diff Modules/_multiprocessing/socket_connection.c @ 61467:f197407bdba2 3.1

Recorded merge of revisions 81032 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r81032 | antoine.pitrou | 2010-05-09 17:52:27 +0200 (dim., 09 mai 2010) | 9 lines Recorded merge of revisions 81029 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines Untabify C files. Will watch buildbots. ........ ................
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 09 May 2010 16:14:21 +0000
parents 9a932f92f394
children 60a7b704de5c
line wrap: on
line diff
--- a/Modules/_multiprocessing/socket_connection.c	Sun May 09 12:17:58 2010 +0000
+++ b/Modules/_multiprocessing/socket_connection.c	Sun May 09 16:14:21 2010 +0000
@@ -25,45 +25,45 @@
 static Py_ssize_t
 _conn_sendall(HANDLE h, char *string, size_t length)
 {
-	char *p = string;
-	Py_ssize_t res;
+    char *p = string;
+    Py_ssize_t res;
 
-	while (length > 0) {
-		res = WRITE(h, p, length);
-		if (res < 0)
-			return MP_SOCKET_ERROR;
-		length -= res;
-		p += res;
-	}
+    while (length > 0) {
+        res = WRITE(h, p, length);
+        if (res < 0)
+            return MP_SOCKET_ERROR;
+        length -= res;
+        p += res;
+    }
 
-	return MP_SUCCESS;
+    return MP_SUCCESS;
 }
 
 /*
- * Receive string of exact length from file descriptor 
+ * Receive string of exact length from file descriptor
  */
 
 static Py_ssize_t
 _conn_recvall(HANDLE h, char *buffer, size_t length)
 {
-	size_t remaining = length;
-	Py_ssize_t temp;
-	char *p = buffer;
+    size_t remaining = length;
+    Py_ssize_t temp;
+    char *p = buffer;
 
-	while (remaining > 0) {
-		temp = READ(h, p, remaining);
-		if (temp <= 0) {
-			if (temp == 0)
-				return remaining == length ? 
-					MP_END_OF_FILE : MP_EARLY_END_OF_FILE;
-			else
-				return temp;
-		}
-		remaining -= temp;
-		p += temp;
-	}
+    while (remaining > 0) {
+        temp = READ(h, p, remaining);
+        if (temp <= 0) {
+            if (temp == 0)
+                return remaining == length ?
+                    MP_END_OF_FILE : MP_EARLY_END_OF_FILE;
+            else
+                return temp;
+        }
+        remaining -= temp;
+        p += temp;
+    }
 
-	return MP_SUCCESS;
+    return MP_SUCCESS;
 }
 
 /*
@@ -73,38 +73,38 @@
 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
-	   combine the "header" and the "body" of the message and send
-	   them at once. */
-	if (length < (16*1024)) {
-		char *message;
+    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
+       combine the "header" and the "body" of the message and send
+       them at once. */
+    if (length < (16*1024)) {
+        char *message;
 
-		message = PyMem_Malloc(length+4);
-		if (message == NULL)
-			return MP_MEMORY_ERROR;
+        message = PyMem_Malloc(length+4);
+        if (message == NULL)
+            return MP_MEMORY_ERROR;
 
-		*(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);
-	} else {
-		UINT32 lenbuff;
+        *(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);
+    } else {
+        UINT32 lenbuff;
 
-		if (length > MAX_MESSAGE_LENGTH)
-			return MP_BAD_MESSAGE_LENGTH;
+        if (length > MAX_MESSAGE_LENGTH)
+            return MP_BAD_MESSAGE_LENGTH;
 
-		lenbuff = htonl((UINT32)length);
-		Py_BEGIN_ALLOW_THREADS
-		res = _conn_sendall(conn->handle, (char*)&lenbuff, 4) || 
-			_conn_sendall(conn->handle, string, length);
-		Py_END_ALLOW_THREADS
-	}
-	return res;
+        lenbuff = htonl((UINT32)length);
+        Py_BEGIN_ALLOW_THREADS
+        res = _conn_sendall(conn->handle, (char*)&lenbuff, 4) ||
+            _conn_sendall(conn->handle, string, length);
+        Py_END_ALLOW_THREADS
+    }
+    return res;
 }
 
 /*
@@ -114,38 +114,38 @@
  */
 
 static Py_ssize_t
-conn_recv_string(ConnectionObject *conn, char *buffer, 
-		 size_t buflength, char **newbuffer, size_t maxlength)
+conn_recv_string(ConnectionObject *conn, char *buffer,
+                 size_t buflength, char **newbuffer, size_t maxlength)
 {
-	int res;
-	UINT32 ulength;
+    int res;
+    UINT32 ulength;
 
-	*newbuffer = NULL;
+    *newbuffer = NULL;
 
-	Py_BEGIN_ALLOW_THREADS
-	res = _conn_recvall(conn->handle, (char*)&ulength, 4);
-	Py_END_ALLOW_THREADS
-	if (res < 0)
-		return res;
+    Py_BEGIN_ALLOW_THREADS
+    res = _conn_recvall(conn->handle, (char*)&ulength, 4);
+    Py_END_ALLOW_THREADS
+    if (res < 0)
+        return res;
 
-	ulength = ntohl(ulength);
-	if (ulength > maxlength)
-		return MP_BAD_MESSAGE_LENGTH;
+    ulength = ntohl(ulength);
+    if (ulength > maxlength)
+        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;
-	}
+    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;
+    }
 }
 
 /*
@@ -155,41 +155,41 @@
 static int
 conn_poll(ConnectionObject *conn, double timeout, PyThreadState *_save)
 {
-	int res;
-	fd_set rfds;
+    int res;
+    fd_set rfds;
 
-	/*
-	 * Verify the handle, issue 3321. Not required for windows.
-	 */ 
-	#ifndef MS_WINDOWS
-		if (((int)conn->handle) < 0 || ((int)conn->handle) >= FD_SETSIZE) {
-			Py_BLOCK_THREADS
-			PyErr_SetString(PyExc_IOError, "handle out of range in select()");
-			Py_UNBLOCK_THREADS
-			return MP_EXCEPTION_HAS_BEEN_SET;
-		}
-	#endif
+    /*
+     * Verify the handle, issue 3321. Not required for windows.
+     */
+    #ifndef MS_WINDOWS
+        if (((int)conn->handle) < 0 || ((int)conn->handle) >= FD_SETSIZE) {
+            Py_BLOCK_THREADS
+            PyErr_SetString(PyExc_IOError, "handle out of range in select()");
+            Py_UNBLOCK_THREADS
+            return MP_EXCEPTION_HAS_BEEN_SET;
+        }
+    #endif
 
-	FD_ZERO(&rfds);
-	FD_SET((SOCKET)conn->handle, &rfds);
+    FD_ZERO(&rfds);
+    FD_SET((SOCKET)conn->handle, &rfds);
 
-	if (timeout < 0.0) {
-		res = select((int)conn->handle+1, &rfds, NULL, NULL, NULL);
-	} else {
-		struct timeval tv;
-		tv.tv_sec = (long)timeout;
-		tv.tv_usec = (long)((timeout - tv.tv_sec) * 1e6 + 0.5);
-		res = select((int)conn->handle+1, &rfds, NULL, NULL, &tv);
-	}
+    if (timeout < 0.0) {
+        res = select((int)conn->handle+1, &rfds, NULL, NULL, NULL);
+    } else {
+        struct timeval tv;
+        tv.tv_sec = (long)timeout;
+        tv.tv_usec = (long)((timeout - tv.tv_sec) * 1e6 + 0.5);
+        res = select((int)conn->handle+1, &rfds, NULL, NULL, &tv);
+    }
 
-	if (res < 0) {
-		return MP_SOCKET_ERROR;
-	} else if (FD_ISSET(conn->handle, &rfds)) {
-		return TRUE;
-	} else {
-		assert(res == 0);
-		return FALSE;
-	}
+    if (res < 0) {
+        return MP_SOCKET_ERROR;
+    } else if (FD_ISSET(conn->handle, &rfds)) {
+        return TRUE;
+    } else {
+        assert(res == 0);
+        return FALSE;
+    }
 }
 
 /*