def ConnectedCallback(_socket):
			if _socket is not None:
				self._ConnectingConfirm(socket_id, _socket)
				confirm_message = Protocol.PackMapCtrlMsg('link_confirm', socket_id)
				self._SelfSendData(confirm_message)
				self._Log(logging.DEBUG, 'Sending confirm message to remote, ID: [%d]', socket_id)
			else:
				try:
					refuse_message = Protocol.PackMapCtrlMsg('link_refuse', socket_id)
					self._SelfSendData(refuse_message)
					self._DelConnectingInfo(socket_id)
					self._Log(logging.DEBUG, 'Sending refuse message to remote, ID: [%d]', socket_id)
				except socket.error:
					pass
	def _DoCloseConnectingConn(self, ID, inform_other):
		try:
			t = self.connecting_id_dict[ID]
			if isinstance(t, ThreadingConnectServer):
				# The socket is connecting, stop the thread
				t.Stop()
				if inform_other:
					msg = Protocol.PackMapCtrlMsg('link_refuse', ID)
					self._SelfSendData(msg)
		except KeyError:
			self._Log(logging.DEBUG, 'The key is not existed in conneting_id_dict: %d', ID)
예제 #3
0
    def _HostNewConnectHandler(self, _socket):
        client, address = _socket.accept()
        new_id = self.id_set.Gen()
        self._AddConnecting(client, new_id)

        new_link_msg = Protocol.PackMapCtrlMsg('new_link', new_id)
        self._SelfSendData(new_link_msg)

        self._Log(
            logging.INFO,
            'New connected in map host port. allocated ID [%d], address [%s:%d]',
            new_id, *address)
        # Now waiting for new link confirm message
        # And still listen this socket
        return True