Пример #1
0
def htonl(space, w_x):
    """htonl(integer) -> integer

    Convert a 32-bit integer from host to network 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.htonl(x))
Пример #2
0
 def do_send_string(self, space, buffer, offset, size):
     # Since str2charp copies the buffer anyway, always combine the
     # "header" and the "body" of the message and send them at once.
     message = lltype.malloc(rffi.CCHARP.TO, size + 4, flavor='raw')
     try:
         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]
             i -= 1
         self._sendall(space, message, size + 4)
     finally:
         lltype.free(message, flavor='raw')
Пример #3
0
def htonl(space, w_x):
    """htonl(integer) -> integer

    Convert a 32-bit integer from host to network 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.htonl(x))
Пример #4
0
 def do_send_string(self, space, buffer, offset, size):
     # Since str2charp copies the buffer anyway, always combine the
     # "header" and the "body" of the message and send them at once.
     message = lltype.malloc(rffi.CCHARP.TO, size + 4, flavor='raw')
     try:
         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]
             i -= 1
         self._sendall(space, message, size + 4)
     finally:
         lltype.free(message, flavor='raw')
Пример #5
0
def htonl(space, x):
    """htonl(integer) -> integer

    Convert a 32-bit integer from host to network byte order.
    """
    return space.wrap(rsocket.htonl(x))
Пример #6
0
def htonl(space, x):
    """htonl(integer) -> integer

    Convert a 32-bit integer from host to network byte order.
    """
    return space.wrap(rsocket.htonl(x))