diff options
author | Jesse Noller <jnoller@gmail.com> | 2008-08-02 02:03:58 (GMT) |
---|---|---|
committer | Jesse Noller <jnoller@gmail.com> | 2008-08-02 02:03:58 (GMT) |
commit | 91639e0973369d072baf5936f7ab235b2b3cbbec (patch) | |
tree | cccb12994774af3253b75af2b7935d733d31c23a /Modules/_multiprocessing/socket_connection.c | |
parent | ebd9af44c53dd17dd8f6f2a60697ed6ee885e1d5 (diff) | |
download | cpython-91639e0973369d072baf5936f7ab235b2b3cbbec.zip cpython-91639e0973369d072baf5936f7ab235b2b3cbbec.tar.gz cpython-91639e0973369d072baf5936f7ab235b2b3cbbec.tar.bz2 |
Merge 65376 into 3k, fix for issue 3399
Diffstat (limited to 'Modules/_multiprocessing/socket_connection.c')
-rw-r--r-- | Modules/_multiprocessing/socket_connection.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Modules/_multiprocessing/socket_connection.c b/Modules/_multiprocessing/socket_connection.c index a6ff9dd..e5d2d15 100644 --- a/Modules/_multiprocessing/socket_connection.c +++ b/Modules/_multiprocessing/socket_connection.c @@ -73,6 +73,7 @@ _conn_recvall(HANDLE h, char *buffer, size_t length) static Py_ssize_t conn_send_string(ConnectionObject *conn, char *string, size_t length) { + Py_ssize_t res; /* The "header" of the message is a 32 bit unsigned number (in network order) which specifies the length of the "body". If the message is shorter than about 16kb then it is quicker to @@ -80,7 +81,6 @@ conn_send_string(ConnectionObject *conn, char *string, size_t length) them at once. */ if (length < (16*1024)) { char *message; - int res; message = PyMem_Malloc(length+4); if (message == NULL) @@ -88,9 +88,10 @@ conn_send_string(ConnectionObject *conn, char *string, size_t length) *(UINT32*)message = htonl((UINT32)length); memcpy(message+4, string, length); + Py_BEGIN_ALLOW_THREADS res = _conn_sendall(conn->handle, message, length+4); + Py_END_ALLOW_THREADS PyMem_Free(message); - return res; } else { UINT32 lenbuff; @@ -98,9 +99,12 @@ conn_send_string(ConnectionObject *conn, char *string, size_t length) return MP_BAD_MESSAGE_LENGTH; lenbuff = htonl((UINT32)length); - return _conn_sendall(conn->handle, (char*)&lenbuff, 4) || + Py_BEGIN_ALLOW_THREADS + res = _conn_sendall(conn->handle, (char*)&lenbuff, 4) || _conn_sendall(conn->handle, string, length); + Py_END_ALLOW_THREADS } + return res; } /* @@ -118,7 +122,9 @@ conn_recv_string(ConnectionObject *conn, char *buffer, *newbuffer = NULL; + Py_BEGIN_ALLOW_THREADS res = _conn_recvall(conn->handle, (char*)&ulength, 4); + Py_END_ALLOW_THREADS if (res < 0) return res; @@ -127,13 +133,17 @@ conn_recv_string(ConnectionObject *conn, char *buffer, return MP_BAD_MESSAGE_LENGTH; if (ulength <= buflength) { + Py_BEGIN_ALLOW_THREADS res = _conn_recvall(conn->handle, buffer, (size_t)ulength); + Py_END_ALLOW_THREADS return res < 0 ? res : ulength; } else { *newbuffer = PyMem_Malloc((size_t)ulength); if (*newbuffer == NULL) return MP_MEMORY_ERROR; + Py_BEGIN_ALLOW_THREADS res = _conn_recvall(conn->handle, *newbuffer, (size_t)ulength); + Py_END_ALLOW_THREADS return res < 0 ? (Py_ssize_t)res : (Py_ssize_t)ulength; } } |