def connect(self, dest):
with self.lock:
if not self.state.CLOSED:
self.err("connect() in socket state {0}".format(self.state))
if self.state.ESTABLISHED:
raise Error(errno.EISCONN)
if self.state.CONNECT:
raise Error(errno.EALREADY)
raise Error(errno.EPIPE)
if type(dest) is StringType:
pdu = Connect(1, self.addr, self.recv_miu, self.recv_win, dest)
elif type(dest) is IntType:
pdu = Connect(dest, self.addr, self.recv_miu, self.recv_win)
else: raise TypeError("connect() arg *dest* must be int or string")
self.state.CONNECT = True
self.send_queue.append(pdu)
try: pdu = super(DataLinkConnection, self).recv()
except IndexError: raise Error(errno.EPIPE)
if isinstance(pdu, DisconnectedMode):
self.log("connect rejected with reason {0}".format(pdu.reason))
self.state.CLOSED = True
raise ConnectRefused(pdu.reason)
if isinstance(pdu, ConnectionComplete):
self.peer = pdu.ssap
self.recv_buf = self.recv_win
self.send_miu = pdu.miu
self.send_win = pdu.rw
self.state.ESTABLISHED = True
return
raise RuntimeError("only CC or DM expected, not " + pdu.name)
评论列表
文章目录