Пример #1
0
class EchoSSLServerHandler(BaseTcpServerHandler[TcpClientConnection]):
    """Wraps client socket during initialization."""
    @staticmethod
    def create(**kwargs: Any) -> TcpClientConnection:  # pragma: no cover
        return TcpClientConnection(**kwargs)

    def initialize(self) -> None:
        # Acceptors don't perform TLS handshake.  Perform the same
        # here using wrap_socket() utility.
        assert self.flags.keyfile is not None and self.flags.certfile is not None
        conn = wrap_socket(
            self.work.connection,
            self.flags.keyfile,
            self.flags.certfile,
        )
        conn.setblocking(False)
        # Upgrade plain TcpClientConnection to SSL connection object
        self.work = TcpClientConnection(
            conn=conn,
            addr=self.work.addr,
        )

    def handle_data(self, data: memoryview) -> Optional[bool]:
        # echo back to client
        self.work.queue(data)
        return None
Пример #2
0
class EchoSSLServerHandler(BaseTcpServerHandler):
    """Wraps client socket during initialization."""
    def initialize(self) -> None:
        # Acceptors don't perform TLS handshake.  Perform the same
        # here using wrap_socket() utility.
        assert self.flags.keyfile is not None and self.flags.certfile is not None
        conn = wrap_socket(self.client.connection, self.flags.keyfile,
                           self.flags.certfile)
        conn.setblocking(False)
        # Upgrade plain TcpClientConnection to SSL connection object
        self.client = TcpClientConnection(conn=conn, addr=self.client.addr)

    def handle_data(self, data: memoryview) -> Optional[bool]:
        # echo back to client
        self.client.queue(data)
        return None