From 0f683b2d024bd8b4eec0baeeb1ddfcfab6e162b8 Mon Sep 17 00:00:00 2001 From: vmarunov Date: Thu, 7 Apr 2016 21:50:42 +0300 Subject: [PATCH 1/2] Fix connect error on windows (https://github.com/tarantool/tarantool-python/issues/70): >>> import tarantool >>> tarantool.connect('48.12.22.123',3311) ``` Traceback (most recent call last): File "", line 1, in tarantool.connect('48.12.22.123',3311) File "C:\Python27\lib\site-packages\tarantool\__init__.py", line 47, in connect encoding=encoding) File "C:\Python27\lib\site-packages\tarantool\connection.py", line 93, in __init__ recv = self._sys_recv = libc.recv File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__ func = self.__getitem__(name) File "C:\Python27\lib\ctypes\__init__.py", line 383, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'recv' not found ``` --- tarantool/connection.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tarantool/connection.py b/tarantool/connection.py index cc517522..b8676ee8 100644 --- a/tarantool/connection.py +++ b/tarantool/connection.py @@ -11,6 +11,7 @@ import ctypes.util import socket import msgpack +import os try: from ctypes import c_ssize_t @@ -89,7 +90,10 @@ def __init__(self, host, port, creates network connection. if False than you have to call connect() manualy. ''' - libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) + if os.name == 'nt': + libc = ctypes.CDLL(ctypes.util.find_library('Ws2_32'), use_errno=True) + else: + libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) recv = self._sys_recv = libc.recv recv.argtypes = [ ctypes.c_int, ctypes.c_void_p, c_ssize_t, ctypes.c_int] From d28acc746eda5323690601ce78fc10c71623550f Mon Sep 17 00:00:00 2001 From: vmarunov Date: Fri, 8 Apr 2016 08:16:58 +0300 Subject: [PATCH 2/2] use correct socket library on windows platform --- tarantool/connection.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tarantool/connection.py b/tarantool/connection.py index b8676ee8..a6a48848 100644 --- a/tarantool/connection.py +++ b/tarantool/connection.py @@ -91,7 +91,7 @@ def __init__(self, host, port, if False than you have to call connect() manualy. ''' if os.name == 'nt': - libc = ctypes.CDLL(ctypes.util.find_library('Ws2_32'), use_errno=True) + libc = ctypes.windll.LoadLibrary(ctypes.util.find_library('Ws2_32')) else: libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) recv = self._sys_recv = libc.recv @@ -233,8 +233,13 @@ def check(): # Check that connection is alive if e.errno == errno.EBADF: return errno.ECONNRESET else: - self._sys_recv(sock_fd, buf, 1, - socket.MSG_DONTWAIT | socket.MSG_PEEK) + if os.name == 'nt': + flag = socket.MSG_PEEK + self._socket.setblocking(False) + else: + flag = socket.MSG_DONTWAIT | socket.MSG_PEEK + self._sys_recv(sock_fd, buf, 1, flag) + if ctypes.get_errno() == errno.EAGAIN: ctypes.set_errno(0) return errno.EAGAIN