Commit e5a399f2 authored by Denis Bilenko's avatar Denis Bilenko

Merge pull request #393 from snaury/vfd-win64

Port gevent vfd to win64
parents 3d5c99c1 b8bb5eed
......@@ -453,8 +453,13 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
CHECK_LOOP3(self)
return libev.ev_pending_count(self._ptr)
#ifdef _WIN32
def io(self, libev.vfd_socket_t fd, int events, ref=True, priority=None):
return io(self, fd, events, ref, priority)
#else
def io(self, int fd, int events, ref=True, priority=None):
return io(self, fd, events, ref, priority)
#endif
def timer(self, double after, double repeat=0.0, ref=True, priority=None):
return timer(self, after, repeat, ref, priority)
......@@ -785,7 +790,7 @@ cdef public class io(watcher) [object PyGeventIOObject, type PyGeventIO_Type]:
#ifdef _WIN32
def __init__(self, loop loop, long fd, int events, ref=True, priority=None):
def __init__(self, loop loop, libev.vfd_socket_t fd, int events, ref=True, priority=None):
if events & ~(libev.EV__IOFDSET | libev.EV_READ | libev.EV_WRITE):
raise ValueError('illegal event mask: %r' % events)
cdef int vfd = libev.vfd_open(fd)
......
cdef extern from "libev_vfd.h":
#ifdef _WIN32
#ifdef _WIN64
ctypedef long long vfd_socket_t
#else
ctypedef long vfd_socket_t
#endif
#else
ctypedef int vfd_socket_t
#endif
long vfd_get(int)
int vfd_open(long) except -1
void vfd_free(int)
......
#ifdef _WIN32
#ifdef _WIN64
typedef PY_LONG_LONG vfd_socket_t;
#define vfd_socket_object PyLong_FromLongLong
#else
typedef long vfd_socket_t;
#define vfd_socket_object PyInt_FromLong
#endif
#ifdef LIBEV_EMBED
/*
* If libev on win32 is embedded, then we can use an
......@@ -13,7 +20,7 @@
typedef struct vfd_entry_t
{
long handle; /* OS handle, i.e. SOCKET */
vfd_socket_t handle; /* OS handle, i.e. SOCKET */
int count; /* Reference count, 0 if free */
int next; /* Next free fd, -1 if last */
} vfd_entry;
......@@ -58,7 +65,7 @@ static CRITICAL_SECTION* vfd_make_lock()
* Given a virtual fd returns an OS handle or -1
* This function is speed critical, so it cannot use GIL
*/
static long vfd_get(int fd)
static vfd_socket_t vfd_get(int fd)
{
int handle = -1;
VFD_LOCK_ENTER;
......@@ -74,7 +81,7 @@ static long vfd_get(int fd)
* Given an OS handle finds or allocates a virtual fd
* Returns -1 on failure and sets Python exception if pyexc is non-zero
*/
static int vfd_open_(long handle, int pyexc)
static int vfd_open_(vfd_socket_t handle, int pyexc)
{
VFD_GIL_DECLARE;
int fd = -1;
......@@ -87,7 +94,13 @@ static int vfd_open_(long handle, int pyexc)
}
if (ioctlsocket(handle, FIONREAD, &arg) != 0) {
if (pyexc)
PyErr_Format(PyExc_IOError, "%ld is not a socket (files are not supported)", handle);
PyErr_Format(PyExc_IOError,
#ifdef _WIN64
"%lld is not a socket (files are not supported)",
#else
"%ld is not a socket (files are not supported)",
#endif
handle);
goto done;
}
if (vfd_map == NULL) {
......@@ -95,7 +108,7 @@ static int vfd_open_(long handle, int pyexc)
if (vfd_map == NULL)
goto done;
}
key = PyLong_FromLong(handle);
key = vfd_socket_object(handle);
/* check if it's already in the dict */
value = PyDict_GetItem(vfd_map, key);
if (value != NULL) {
......@@ -168,14 +181,14 @@ static void vfd_free_(int fd, int needclose)
goto done; /* free entry, ignore */
if (!--vfd_entries[fd].count) {
/* fd has just been freed */
long handle = vfd_entries[fd].handle;
vfd_socket_t handle = vfd_entries[fd].handle;
vfd_entries[fd].handle = -1;
vfd_entries[fd].next = vfd_next;
vfd_next = fd;
if (needclose)
closesocket(handle);
/* vfd_map is assumed to be != NULL */
key = PyLong_FromLong(handle);
key = vfd_socket_object(handle);
PyDict_DelItem(vfd_map, key);
Py_DECREF(key);
}
......@@ -203,6 +216,7 @@ done:
/*
* On non-win32 platforms vfd_* are noop macros
*/
typedef int vfd_socket_t;
#define vfd_get(fd) (fd)
#define vfd_open(fd) ((int)(fd))
#define vfd_free(fd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment