| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2008 Twisted Matrix Laboratories. | |
| 2 # See LICENSE for details. | |
| 3 | |
| 4 | |
| 5 def recv(long s, object bufflist, object obj, unsigned long flags = 0): | |
| 6 cdef int rc, buffcount, i, res | |
| 7 cdef myOVERLAPPED *ov | |
| 8 cdef WSABUF *ws_buf | |
| 9 cdef unsigned long bytes | |
| 10 cdef PyObject **buffers | |
| 11 | |
| 12 bufflist = PySequence_Fast(bufflist, 'second argument needs to be a list') | |
| 13 buffcount = PySequence_Fast_GET_SIZE(bufflist) | |
| 14 buffers = PySequence_Fast_ITEMS(bufflist) | |
| 15 | |
| 16 ws_buf = <WSABUF *>PyMem_Malloc(buffcount*sizeof(WSABUF)) | |
| 17 | |
| 18 try: | |
| 19 for i from 0 <= i < buffcount: | |
| 20 PyObject_AsWriteBuffer(<object>buffers[i], <void **>&ws_buf[i].buf,
<int *>&ws_buf[i].len) | |
| 21 | |
| 22 ov = makeOV() | |
| 23 if obj is not None: | |
| 24 ov.obj = <PyObject *>obj | |
| 25 | |
| 26 rc = WSARecv(s, ws_buf, buffcount, &bytes, &flags, <OVERLAPPED *>ov, NUL
L) | |
| 27 | |
| 28 if rc == SOCKET_ERROR: | |
| 29 rc = WSAGetLastError() | |
| 30 if rc != ERROR_IO_PENDING: | |
| 31 return rc, 0 | |
| 32 | |
| 33 Py_XINCREF(obj) | |
| 34 return rc, bytes | |
| 35 finally: | |
| 36 PyMem_Free(ws_buf) | |
| 37 | |
| 38 def recvfrom(long s, object buff, object addr_buff, object obj, unsigned long fl
ags = 0): | |
| 39 cdef int rc, fromlen | |
| 40 cdef myOVERLAPPED *ov | |
| 41 cdef WSABUF ws_buf | |
| 42 cdef unsigned long bytes | |
| 43 cdef sockaddr *fromaddr | |
| 44 | |
| 45 PyObject_AsWriteBuffer(buff, <void **>&ws_buf.buf, <int *>&ws_buf.len) | |
| 46 PyObject_AsWriteBuffer(addr_buff, <void **>&fromaddr, &fromlen) | |
| 47 | |
| 48 ov = makeOV() | |
| 49 if obj is not None: | |
| 50 ov.obj = <PyObject *>obj | |
| 51 | |
| 52 rc = WSARecvFrom(s, &ws_buf, 1, &bytes, &flags, fromaddr, &fromlen, <OVERLAP
PED *>ov, NULL) | |
| 53 | |
| 54 if rc == SOCKET_ERROR: | |
| 55 rc = WSAGetLastError() | |
| 56 if rc != ERROR_IO_PENDING: | |
| 57 return rc, 0 | |
| 58 | |
| 59 Py_XINCREF(obj) | |
| 60 return rc, bytes | |
| 61 | |
| OLD | NEW |