Skip to content

Commit 0c92f44

Browse files
committed
Merge pull request #71 from vmarunov/master
fix work with socket on windows
2 parents e0a28cb + d28acc7 commit 0c92f44

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tarantool/connection.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import ctypes.util
1212
import socket
1313
import msgpack
14+
import os
1415

1516
try:
1617
from ctypes import c_ssize_t
@@ -89,7 +90,10 @@ def __init__(self, host, port,
8990
creates network connection.
9091
if False than you have to call connect() manualy.
9192
'''
92-
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
93+
if os.name == 'nt':
94+
libc = ctypes.windll.LoadLibrary(ctypes.util.find_library('Ws2_32'))
95+
else:
96+
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
9397
recv = self._sys_recv = libc.recv
9498
recv.argtypes = [
9599
ctypes.c_int, ctypes.c_void_p, c_ssize_t, ctypes.c_int]
@@ -229,8 +233,13 @@ def check(): # Check that connection is alive
229233
if e.errno == errno.EBADF:
230234
return errno.ECONNRESET
231235
else:
232-
self._sys_recv(sock_fd, buf, 1,
233-
socket.MSG_DONTWAIT | socket.MSG_PEEK)
236+
if os.name == 'nt':
237+
flag = socket.MSG_PEEK
238+
self._socket.setblocking(False)
239+
else:
240+
flag = socket.MSG_DONTWAIT | socket.MSG_PEEK
241+
self._sys_recv(sock_fd, buf, 1, flag)
242+
234243
if ctypes.get_errno() == errno.EAGAIN:
235244
ctypes.set_errno(0)
236245
return errno.EAGAIN

0 commit comments

Comments
 (0)