def onHandshake(data): obj.handshakeOp = None if data is None: onError() return obj.sslConn, obj.peerKey, obj.peerName = data obj.stream = SSLMessageStream(obj.sslConn, reactor) obj.stream.setCloseCallback(onClose) obj.stream.setErrorCallback(onClose) obj.stream.setInvalidMessageCallback(onClose) obj.stream.setInputCallback(onInput) obj.stream.enableRead(True)
def acceptIncoming(acceptFlag, sslConn, reactor, callback=None): def doCancel(): stream.close() def onError(*args): doCancel() op.notify(None) def onWriteComplete(): stream.shutdown() op.notify(sslConn) stream = SSLMessageStream(sslConn, reactor) stream.setCloseCallback(onError) stream.setErrorCallback(onError) stream.setInvalidMessageCallback(onError) stream.setInputCallback(onError) stream.setWriteCompleteCallback(onWriteComplete) if acceptFlag: data = 0 else: data = -1 stream.sendMessage(encode(data)) op = AsyncOp(callback, doCancel) return op
def acceptIncoming( acceptFlag, sslConn, reactor, callback=None ) : def doCancel() : stream.close() def onError( *args ) : doCancel() op.notify( None ) def onWriteComplete() : stream.shutdown() op.notify( sslConn ) stream = SSLMessageStream( sslConn, reactor ) stream.setCloseCallback( onError ) stream.setErrorCallback( onError ) stream.setInvalidMessageCallback( onError ) stream.setInputCallback( onError ) stream.setWriteCompleteCallback( onWriteComplete ) if acceptFlag : data = 0 else : data = -1 stream.sendMessage( encode(data) ) op = AsyncOp( callback, doCancel ) return op
def _serviceConnect( sslConn, serviceName, reactor, callback=None ) : def doCancel() : ms.shutdown() sslAbort( sslConn ) def onClose( *args ) : doCancel() op.notify( None ) def onInput( data ) : try : result = decode( data ) assert type(result) is int assert result == 0 except : doCancel() op.notify( None ) return ms.shutdown() op.notify( sslConn ) ms = SSLMessageStream( sslConn, reactor ) ms.setCloseCallback( onClose ) ms.setErrorCallback( onClose ) ms.setInvalidMessageCallback( onClose ) ms.setInputCallback( onInput ) ms.sendMessage( encode(serviceName) ) ms.enableRead( True ) op = AsyncOp( callback, doCancel ) return op