def ntohl(space, x): """ntohl(integer) -> integer Convert a 32-bit integer from network to host byte order. """ if x < r_longlong(0): raise oefmt(space.w_OverflowError, "can't convert negative number to unsigned long") if x > LONGLONG_UINT32_MAX: raise oefmt(space.w_OverflowError, "long int larger than 32 bits") return space.newint(rsocket.ntohl(r_uint32(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 oefmt(space.w_IOError, "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 oefmt(space.w_IOError, "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))