def open_session(address): name = 'udp_%s_%s' % (address[0].replace('.','_'), str(address[1])) for a in automat.objects().values(): if a.name == name: return a a = TransportUDPSession(address, name, 'AT_STARTUP', 12) return a
def _state_changed(index, ip, newstate, filename, loop_delay): print '+++++ STATE CHANGED [%s]' % newstate sess = automat.objects().get(index) if newstate == 'CONNECTED': transport_udp_session.SetStateChangedCallbackFunc(None) if loop_delay: reactor.callLater(2, LoopingCall(send, filename, sess.remote_address[0], sess.remote_address[1]).start, loop_delay, True) else: reactor.callLater(2, send, filename, sess.remote_address[0], sess.remote_address[1])
def doDestroyMe(self, arg): # dhnio.Dprint(6, 'transport_udp_session.doDestroyMe %s' % self.name) file_ids_to_remove = self.incommingFiles.keys() for file_id in file_ids_to_remove: try: os.close(self.incommingFiles[file_id].fd) except: dhnio.DprintException() file_received(self.incommingFiles[file_id].filename, 'failed', 'udp', self.remote_address, None, 'session has been closed') self.incommingFiles[file_id].close() del self.incommingFiles[file_id] file_ids_to_remove = self.outgoingFiles.keys() for file_id in file_ids_to_remove: file_sent(self.remote_address, self.outgoingFiles[file_id].filename, 'failed', 'udp', None, 'session has been closed') self.closeOutboxFile(file_id) self.receivedFiles.clear() self.sliding_window.clear() automat.objects().pop(self.index)
def get_session(address): name = 'udp_%s_%s' % (address[0].replace('.','_'), str(address[1])) for a in automat.objects().values(): if a.name == name: return a return None
def sessions(): for a in automat.objects().values(): if a.name.startswith('udp_'): yield a
def is_session_opened(address): name = 'udp_%s_%s' % (address[0].replace('.','_'), str(address[1])) for a in automat.objects().values(): if a.name == name: return True return False
def get_session_by_index(index): return automat.objects().get(index, None)
def doShutdown(self, arg): automat.objects().pop(self.index) d = self.shutdownDefer if d is None: d = arg shutdown_final(d)