Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ctypes.util
import socket
import msgpack
import os

try:
from ctypes import c_ssize_t
Expand Down Expand Up @@ -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.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
recv.argtypes = [
ctypes.c_int, ctypes.c_void_p, c_ssize_t, ctypes.c_int]
Expand Down Expand Up @@ -229,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
Expand Down