Example #1
0
def fromfd(space, fd, family, type, proto=0):
    """fromfd(fd, family, type[, proto]) -> socket object

    Create a socket object from the given file descriptor.
    The remaining arguments are the same as for socket().
    """
    try:
        sock = rsocket.fromfd(fd, family, type, proto, W_RSocket)
    except SocketError, e:
        raise converted_error(space, e)
Example #2
0
def fromfd(space, fd, family, type, proto=0):
    """fromfd(fd, family, type[, proto]) -> socket object

    Create a socket object from the given file descriptor.
    The remaining arguments are the same as for socket().
    """
    try:
        sock = rsocket.fromfd(fd, family, type, proto)
    except SocketError, e:
        raise converted_error(space, e)
Example #3
0
def run(directives):

    hostip = rsocket.gethostbyname('localhost')
    if use_pypy:
        host = rsocket.INETAddress(hostip.get_host(), 2222)
        socket = rsocket.RSocket(rsocket.AF_INET, rsocket.SOCK_STREAM)
    else:
        host = (hostip, 2222)
        socket = rsocket.socket(rsocket.AF_INET, rsocket.SOCK_STREAM)

    socket.bind(host)
    socket.listen(1)

    bufsize = 1048576
    while True:
        if use_pypy:
            (client_sock_fd, client_addr) = socket.accept()
            client_sock = rsocket.fromfd(client_sock_fd, rsocket.AF_INET,
                                         rsocket.SOCK_STREAM)
        else:
            (client_sock, client_addr) = socket.accept()
        client_sock.send("Server ready!\n")
        print 'Client contacted'
        while True:
            msg = client_sock.recv(bufsize)

            if use_jit:
                jitdriver.jit_merge_point( \
                                     # INTs
                                     ## REFs


                                           msg = msg,
                                           client_sock = client_sock
                                           # FLOATs
                                           )

            if not msg:
                client_sock.close()
                break
            msg = msg.rstrip("\n")
            print "\nRECEIVED:\n%s" % msg
            if msg == "exit":
                client_sock.close()
                break
            try:
                ret_msg = directives.parse_and_run_command(msg)
            except RException as e:
                ret_msg = "ERROR: " + e.message
            client_sock.send(ret_msg)
            print "\nSENT:\n%s" % ret_msg
        return 1  # could be unindented, if not for rpython
def run(directives):

    hostip = rsocket.gethostbyname('localhost')
    if use_pypy:
      host = rsocket.INETAddress(hostip.get_host(), 2222)
      socket = rsocket.RSocket(rsocket.AF_INET, rsocket.SOCK_STREAM)
    else:
      host = (hostip, 2222)
      socket = rsocket.socket(rsocket.AF_INET, rsocket.SOCK_STREAM)
    
    socket.bind(host)
    socket.listen(1)
   
    bufsize = 1048576
    while True:
      if use_pypy:
        (client_sock_fd, client_addr) = socket.accept()
        client_sock = rsocket.fromfd(client_sock_fd, rsocket.AF_INET, rsocket.SOCK_STREAM)
      else:
        (client_sock, client_addr) = socket.accept()
      client_sock.send("Server ready!\n")
      print 'Client contacted'
      while True:
        msg = client_sock.recv(bufsize)

        if use_jit:
          jitdriver.jit_merge_point( \
                                     # INTs
                                     ## REFs
                                     msg = msg,
                                     client_sock = client_sock
                                     # FLOATs
                                     )

        if not msg:
          client_sock.close()
          break;
        msg = msg.rstrip("\n")
        print "\nRECEIVED:\n%s" % msg
        if msg == "exit":
          client_sock.close()
          break;
        try:
          ret_msg = directives.parse_and_run_command(msg)
        except RException as e:
          ret_msg = "ERROR: " + e.message
        client_sock.send(ret_msg)
        print "\nSENT:\n%s" % ret_msg
      return 1 # could be unindented, if not for rpython
Example #5
0
    def wait_for_connection(self):
        (fd, client_addr) = self.socket.accept()

        client_sock = rsocket.fromfd(fd, rsocket.AF_INET, rsocket.SOCK_STREAM)

        return client_sock, client_addr