Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r50819:bb7e012d070a Date: 2011-12-21 21:18 -0600 http://bitbucket.org/pypy/pypy/changeset/bb7e012d070a/
Log: merged upstream diff --git a/pypy/module/_multiprocessing/interp_connection.py b/pypy/module/_multiprocessing/interp_connection.py --- a/pypy/module/_multiprocessing/interp_connection.py +++ b/pypy/module/_multiprocessing/interp_connection.py @@ -6,7 +6,7 @@ OperationError, wrap_oserror, operationerrfmt) from pypy.rpython.lltypesystem import rffi, lltype from pypy.rlib.rarithmetic import intmask -from pypy.rlib import rpoll +from pypy.rlib import rpoll, rsocket import sys READABLE = 1 @@ -252,7 +252,9 @@ # "header" and the "body" of the message and send them at once. message = lltype.malloc(rffi.CCHARP.TO, size + 4, flavor='raw') try: - rffi.cast(rffi.UINTP, message)[0] = rffi.r_uint(size) # XXX htonl! + length = rffi.r_uint(rsocket.htonl( + rffi.cast(lltype.Unsigned, size))) + rffi.cast(rffi.UINTP, message)[0] = length i = size - 1 while i >= 0: message[4 + i] = buffer[offset + i] @@ -264,7 +266,8 @@ def do_recv_string(self, space, buflength, maxlength): with lltype.scoped_alloc(rffi.CArrayPtr(rffi.UINT).TO, 1) as length_ptr: self._recvall(space, rffi.cast(rffi.CCHARP, length_ptr), 4) - length = intmask(length_ptr[0]) + length = intmask(rsocket.ntohl( + rffi.cast(lltype.Unsigned, length_ptr[0]))) if length > maxlength: # bad message, close connection self.flags &= ~READABLE if self.flags == 0: diff --git a/pypy/module/_multiprocessing/test/test_connection.py b/pypy/module/_multiprocessing/test/test_connection.py --- a/pypy/module/_multiprocessing/test/test_connection.py +++ b/pypy/module/_multiprocessing/test/test_connection.py @@ -37,6 +37,9 @@ def test_connection(self): rhandle, whandle = self.make_pair() + whandle.send_bytes("abc") + assert rhandle.recv_bytes(100) == "abc" + obj = [1, 2.0, "hello"] whandle.send(obj) obj2 = rhandle.recv() @@ -150,4 +153,20 @@ import _multiprocessing raises(IOError, _multiprocessing.Connection, -1) - raises(IOError, _multiprocessing.Connection, -15) \ No newline at end of file + raises(IOError, _multiprocessing.Connection, -15) + + def test_byte_order(self): + # The exact format of net strings (length in network byte + # order) is important for interoperation with others + # implementations. + rhandle, whandle = self.make_pair() + whandle.send_bytes("abc") + whandle.send_bytes("defg") + import socket + sock = socket.fromfd(rhandle.fileno(), + socket.AF_INET, socket.SOCK_STREAM) + data1 = sock.recv(7) + assert data1 == '\x00\x00\x00\x03abc' + data2 = sock.recv(8) + assert data2 == '\x00\x00\x00\x04defg' + _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit