class ClientHandler(rpc.RpcBroker): def __init__(self, server, ep): super().__init__() self._server = server self._ep = ep self._splitter = SplitterBuf() self._send_buf = pipe.SimpleBuf() ep.cb = self._ep_cb ep.want_pull(True) ep.want_push(False) auth_client = rpcdef.AuthenticationClient.build_client_proxy() self.add_export(ConnectService()) self.add_export(AuthenticationServer(self.add_import(auth_client))) self.add_export(FriendsServiceServer()) self.add_export(ChannelInvitationServiceServer()) self.add_export(ResourcesServiceServer()) self.add_export(AccountServiceServer()) self.add_export(PresenceServiceServer()) self.add_export(GameUtilitiesServer()) def send_data(self, buf): self._send_buf.append(buf) self._ep.want_push(True) def _ep_cb(self, ep, ev_type, ev_data): if ev_type == 'may_pull': self._ep.pull(self._splitter) while True: segment = self._splitter.pull_segment() if segment is None: break self.handle_packet(segment[0], segment[1]) elif ev_type == 'may_push': if self._send_buf.used > 0: self._ep.push(self._send_buf) self._ep.want_push(self._send_buf.used) elif ev_type == 'closed': self.logger.info('Connection closed')
def __init__(self, server, ep): super().__init__() self._server = server self._ep = ep self._splitter = SplitterBuf() self._send_buf = pipe.SimpleBuf() ep.cb = self._ep_cb ep.want_pull(True) ep.want_push(False) auth_client = rpcdef.AuthenticationClient.build_client_proxy() self.add_export(ConnectService()) self.add_export(AuthenticationServer(self.add_import(auth_client))) self.add_export(FriendsServiceServer()) self.add_export(ChannelInvitationServiceServer()) self.add_export(ResourcesServiceServer()) self.add_export(AccountServiceServer()) self.add_export(PresenceServiceServer()) self.add_export(GameUtilitiesServer())