Skip to content

Commit

Permalink
passing the wrong address to recvfrom (!)
Browse files Browse the repository at this point in the history
KQUEUE: new compile-time constant
only resize to result from wait_for_read() if using kqueue
  • Loading branch information
samrushing committed Mar 12, 2013
1 parent 7ee30ce commit 554c243
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions coro/socket.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ __socket_version__ = "$Id: //prod/main/ap/shrapnel/coro/socket.pyx#57 $"

# Note: this file is included by <coro.pyx>

DEF KQUEUE = (UNAME_SYSNAME == "FreeBSD" or UNAME_SYSNAME == "Darwin")

# ================================================================================
# socket
# ================================================================================
Expand Down Expand Up @@ -385,22 +387,25 @@ cdef public class sock [ object sock_object, type sock_type ]:
"""
cdef bytes buffer
cdef int r, new_buffer_size
cdef char * p

buffer = PyBytes_FromStringAndSize (NULL, buffer_size)
p = buffer
while 1:
if self._try_selfish() == 1:
#r = recv (self.fd, buffer, buffer_size, 0)
r = read (self.fd, buffer, buffer_size)
r = read (self.fd, p, buffer_size)
else:
r = -1
libc.errno = libc.EWOULDBLOCK
if r == -1:
if libc.errno == libc.EWOULDBLOCK:
# kqueue will tell us exactly how many bytes are waiting for us.
new_buffer_size = min (self._wait_for_read(), buffer_size)
if new_buffer_size != buffer_size:
buffer = PyBytes_FromStringAndSize (NULL, new_buffer_size)
buffer_size = new_buffer_size
IF KQUEUE:
# kqueue will tell us exactly how many bytes are waiting for us.
if new_buffer_size != buffer_size:
buffer = PyBytes_FromStringAndSize (NULL, new_buffer_size)
buffer_size = new_buffer_size
p = buffer
else:
raise_oserror()
elif r == 0:
Expand Down Expand Up @@ -439,23 +444,27 @@ cdef public class sock [ object sock_object, type sock_type ]:
cdef sockaddr_storage sa
cdef int r, new_buffer_size
cdef socklen_t addr_len
cdef char * p

buffer = PyBytes_FromStringAndSize (NULL, buffer_size)
p = buffer
while 1:
if self._try_selfish() == 1:
addr_len = sizeof (sockaddr_storage)
memset (&sa, 0, sizeof (sockaddr_storage))
r = recvfrom (self.fd, <void*>buffer, buffer_size, flags, <sockaddr*>&sa, &addr_len)
r = recvfrom (self.fd, <void*>p, buffer_size, flags, <sockaddr*>&sa, &addr_len)
else:
r = -1
libc.errno = libc.EWOULDBLOCK
if r == -1:
if libc.errno == libc.EWOULDBLOCK:
# kqueue will tell us exactly how many bytes are waiting for us.
new_buffer_size = min (self._wait_for_read(), buffer_size)
if new_buffer_size != buffer_size:
buffer = PyBytes_FromStringAndSize (NULL, new_buffer_size)
buffer_size = new_buffer_size
IF KQUEUE:
# kqueue will tell us exactly how many bytes are waiting for us.
if new_buffer_size != buffer_size:
buffer = PyBytes_FromStringAndSize (NULL, new_buffer_size)
buffer_size = new_buffer_size
p = buffer
else:
raise_oserror()
else:
Expand Down

0 comments on commit 554c243

Please sign in to comment.