def ntohl(space, w_x): """ntohl(integer) -> integer Convert a 32-bit integer from network to host byte order. """ if space.is_true(space.isinstance(w_x, space.w_int)): x = space.int_w(w_x) elif space.is_true(space.isinstance(w_x, space.w_long)): x = space.uint_w(w_x) else: raise operationerrfmt(space.w_TypeError, "expected int/long, %s found", space.type(w_x).getname(space, "?")) return space.wrap(rsocket.ntohl(x))
def ntohl(space, w_x): """ntohl(integer) -> integer Convert a 32-bit integer from network to host byte order. """ if space.is_true(space.isinstance(w_x, space.w_int)): x = space.int_w(w_x) elif space.is_true(space.isinstance(w_x, space.w_long)): x = space.uint_w(w_x) else: raise OperationError(space.w_TypeError, space.wrap("expected int/long, %s found" % (space.type(w_x).getname(space, "?")))) return space.wrap(rsocket.ntohl(x))
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(rsocket.ntohl( rffi.cast(lltype.Unsigned, length_ptr[0]))) if length > maxlength: # bad message, close connection self.flags &= ~READABLE if self.flags == 0: self.close() raise OperationError(space.w_IOError, space.wrap( "bad message length")) if length <= buflength: self._recvall(space, self.buffer, length) return length, lltype.nullptr(rffi.CCHARP.TO) else: newbuf = lltype.malloc(rffi.CCHARP.TO, length, flavor='raw') self._recvall(space, newbuf, length) return length, newbuf
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( rsocket.ntohl(rffi.cast(lltype.Unsigned, length_ptr[0]))) if length > maxlength: # bad message, close connection self.flags &= ~READABLE if self.flags == 0: self.close() raise OperationError(space.w_IOError, space.wrap("bad message length")) if length <= buflength: self._recvall(space, self.buffer, length) return length, lltype.nullptr(rffi.CCHARP.TO) else: newbuf = lltype.malloc(rffi.CCHARP.TO, length, flavor='raw') self._recvall(space, newbuf, length) return length, newbuf
def ntohl(space, x): """ntohl(integer) -> integer Convert a 32-bit integer from network to host byte order. """ return space.wrap(rsocket.ntohl(x))