def __init__(self, theSocket, theProtocol, theProcessor): """ theSocket: socket facade theProtocol: socket event handler theProcessor: thread facade """ self.recvBuffer = BipBuffer(1024*1024) self.recvBuffer.setMaxRead(4096) self.sendBuffer = BipBuffer(1024*1024) self.recvBuffer.setMaxRead(4096) self.sendLock = threading.RLock() self.sock = theSocket self.sock.setBuffer(self.recvBuffer, self.sendBuffer) self.fd = theSocket.getFileNo() self.status = theSocket.status self.addr = ('', 0) self.proto = theProtocol #self.proto.addConnection(self) self.processor = theProcessor self.protoHandleConnected = Bind1(self.proto.handleConnected, self) self.protoHandleInput = Bind1(self.proto.handleInput, self)
class SocketConnection: """ generate socket jobs notify protocol layer with incoming data """ def __init__(self, theSocket, theProtocol, theProcessor): """ theSocket: socket facade theProtocol: socket event handler theProcessor: thread facade """ self.recvBuffer = BipBuffer(1024*1024) self.recvBuffer.setMaxRead(4096) self.sendBuffer = BipBuffer(1024*1024) self.recvBuffer.setMaxRead(4096) self.sendLock = threading.RLock() self.sock = theSocket self.sock.setBuffer(self.recvBuffer, self.sendBuffer) self.fd = theSocket.getFileNo() self.status = theSocket.status self.addr = ('', 0) self.proto = theProtocol #self.proto.addConnection(self) self.processor = theProcessor self.protoHandleConnected = Bind1(self.proto.handleConnected, self) self.protoHandleInput = Bind1(self.proto.handleInput, self) def hasDataToSend(self): return self.sendBuffer.dataLen() > 0 def isConnected(self): return self.status.has(CONST.STATUS_C) def dump(self): return "[sock]%s\n[sendBuffer]%s\n[recvBuffer]%s\n"%\ (str(self.sock.dump()), str(self.sendBuffer.dump()), str(self.recvBuffer.dump())) def reportError(self, strError = ""): self.sock.reportError(strError) self.proto.handleError(self, strError) def connect(self, host, port): try: self.sock.connect(host, port) self.addr = (host, port) #duplicate when genJobs #if self.sock.status.has(CONST.STATUS_C): # self.handleConnected() except socket.error, e: self.reportError("[SocketConnection.connect]connecting error:" + str(e))