Ejemplo n.º 1
0
 def write(self, data):
     #log.msg("%s.write(%r)" % (self, data))
     self.sock.setblocking(True)
     try:
         SocketStream.write(self, data)
     finally:
         self.sock.setblocking(False)
Ejemplo n.º 2
0
 def write(self, data):
     #log.msg("%s.write(%r)" % (self, data))
     self.sock.setblocking(True)
     try:
         SocketStream.write(self, data)
     finally:
         self.sock.setblocking(False)
Ejemplo n.º 3
0
    def _authenticate_and_build_connection(self, sock):
        """
        Authenticate a client and if it succees, wraps the socket
        in a connection object.  Note that this code is cut and paste
        from the rpyc internals and may have to be changed if rpyc
        evolves
        """

        # authenticate
        if self.authenticator:
            h, p = sock.getpeername()
            try:
                sock, credentials = self.authenticator(sock)
            except AuthenticationError:
                self.log_message(
                    "%s:%s failed to authenticate, rejecting connection",
                    h, p)
                return None
        else:
            credentials = None

        # build a connection
        h, p = sock.getpeername()
        config = dict(self.protocol_config,
                      credentials = credentials,
                      connid      = "%s:%d" % (h, p))
        return Connection(self.service,
                          Channel(SocketStream(sock)),
                          config = config)
Ejemplo n.º 4
0
 def _wait(self):
     if not self._listener_poll.poll(0.01):
         return
     sock, addrinfo = self.listener.accept()
     self.clients.add(sock)
     config = dict(self.protocol_config, allow_all_attrs = True, allow_setattr = True)
     self._connection = Connection(self.service, Channel(SocketStream(sock)), config)
     self._connection_callback()
     self._log_message('client connected', addrinfo)
Ejemplo n.º 5
0
def connect():
    """rpyc.utils.factory.connect() uses default 3s connection timeout
    too short for some computers running big projects,
    use connect_stream() instead and set timeout"""
    stream = None
    if sys.platform == 'win32':
        stream = SocketStream.connect(rpyc_config.HOSTNAME,
                                      rpyc_config.PORT,
                                      timeout=15)
    else:
        stream = SocketStream.unix_connect(rpyc_config.SOCKET_PATH)
    """default sync_request_timeout is 30.0"""
    global _conn
    stream_config = dict(sync_request_timeout=3.0)
    _conn = factory.connect_stream(stream, config=stream_config)
    global bind
    bind = _conn.root.lom_observer_helper.bind
    return _conn.root.Live
Ejemplo n.º 6
0
 def poll(self, timeout):
     if self._buffer:
         return True
     self.sock.setblocking(True)
     try:
         return SocketStream.poll(self, timeout)
     finally:
         try:
             self.sock.setblocking(False)
         except socket.error:
             pass
Ejemplo n.º 7
0
 def poll(self, timeout):
     if self._buffer:
         return True
     self.sock.setblocking(True)
     try:
         return SocketStream.poll(self, timeout)
     finally:
         try:
             self.sock.setblocking(False)
         except socket.error:
             pass
Ejemplo n.º 8
0
 def _serve_client(self, sock, credentials):
     addrinfo = sock.getpeername()
     if credentials:
         self.logger.info("welcome %s (%r)", addrinfo, credentials)
     else:
         self.logger.info("welcome %s", addrinfo)
     try:
         config = dict(self.protocol_config, credentials = credentials,
             endpoints = (sock.getsockname(), addrinfo), logger = self.logger)
         conn = self.service._connect(Channel(SocketStream(sock)), config)
         self._handle_connection(conn)
     finally:
         self.logger.info("goodbye %s", addrinfo)
Ejemplo n.º 9
0
 def _serve_client(self, sock, credentials):
     h, p = sock.getpeername()
     self.logger.info("welcome %s:%s", h, p)
     try:
         config = dict(self.protocol_config, credentials=credentials)
         conn = Connection(self.service,
                           Channel(SocketStream(sock)),
                           config=config,
                           _lazy=True)
         conn._init_service()
         conn.serve_all()
     finally:
         self.logger.info("goodbye %s:%s", h, p)
Ejemplo n.º 10
0
 def _serve_client(self, sock, credentials):
     addrinfo = sock.getpeername()
     try:
         config = dict(self.protocol_config,
                       credentials=credentials,
                       endpoints=(sock.getsockname(), addrinfo),
                       logger=self.logger)
         conn = Connection(self.service,
                           Channel(SocketStream(sock)),
                           config=config)
         conn.serve_all()
     finally:
         pass
Ejemplo n.º 11
0
 def _authenticate_and_build_connection(self, sock):
     '''Authenticate a client and if it succees, wraps the socket in a connection object.
     Note that this code is cut and paste from the rpyc internals and may have to be
     changed if rpyc evolves'''
     # authenticate
     if self.authenticator:
         sock, credentials = self.authenticator(sock)
     else:
         credentials = None
     # build a connection
     h, p = sock.getpeername()
     config = dict(self.protocol_config, credentials=credentials, connid="%s:%d" % (h, p),
                   endpoints=(sock.getsockname(), (h, p)))
     return sock, self.service._connect(Channel(SocketStream(sock)), config)
Ejemplo n.º 12
0
 def read(self, count):
     if count <= len(self._buffer):
         data = self._buffer[:count]
         self._buffer = self._buffer[count:]
     else:
         self.sock.setblocking(True)
         try:
             data2 = SocketStream.read(self, count - len(self._buffer))
         finally:
             try:
                 self.sock.setblocking(False)
             except socket.error:
                 pass
         data = self._buffer + data2
         self._buffer = ""
     #log.msg("%s.read(%r)" % (self, data))
     return data
Ejemplo n.º 13
0
 def _serve_client(self, sock, credentials):
     addrinfo = sock.getpeername()
     h = addrinfo[0]
     p = addrinfo[1]
     if credentials:
         self.logger.info("welcome [%s]:%s (%r)", h, p, credentials)
     else:
         self.logger.info("welcome [%s]:%s", h, p)
     try:
         config = dict(self.protocol_config, credentials = credentials, 
             endpoints = (sock.getsockname(), addrinfo), logger = self.logger)
         conn = Connection(self.service, Channel(SocketStream(sock)),
             config = config, _lazy = True)
         conn._init_service()
         conn.serve_all()
     finally:
         self.logger.info("goodbye [%s]:%s", h, p)
Ejemplo n.º 14
0
 def read(self, count):
     if count <= len(self._buffer):
         data = self._buffer[:count]
         self._buffer = self._buffer[count:]
     else:
         self.sock.setblocking(True)
         try:
             data2 = SocketStream.read(self, count - len(self._buffer))
         finally:
             try:
                 self.sock.setblocking(False)
             except socket.error:
                 pass
         data = self._buffer + data2
         self._buffer = ""
     #log.msg("%s.read(%r)" % (self, data))
     return data
Ejemplo n.º 15
0
 def __init__(self, transport):
     SocketStream.__init__(self, transport.socket)
     self.transport = transport
     self._buffer = ""
Ejemplo n.º 16
0
 def __init__(self, transport):
     SocketStream.__init__(self, transport.socket)
     self.transport = transport
     self._buffer = ""