Beispiel #1
0
 def __init__(self, logic):
     self.conn_state = {}
     self.epoll_sock = select.epoll()
     self.logic = logic
     remote_cmd = sys.argv[1] + '||' + sys.argv[2]  # 'date|||root'
     for host in sys.argv[3:]:  #start with the host1 ,host2,host3
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
         sock.connect((host, remote_port))
         sock.setblocking(0)
         tmp_state = STATE()
         tmp_state.state = 'write'
         tmp_str = '%0' + str(maxheader) + "d%s"
         tmp_state.buff_write = tmp_str % (len(remote_cmd), remote_cmd
                                           )  #00010date||root
         tmp_state.need_write = len(tmp_state.buff_write)
         tmp_state.sock_obj = sock
         self.conn_state[sock.fileno()] = tmp_state
         self.epoll_sock.register(sock.fileno(), select.EPOLLOUT)
     self.sm = {
         "accept": self.accept2read,
         "read": self.read2process,
         "write": self.write2read,
         "process": self.process,
         "closing": self.close,
     }
Beispiel #2
0
 def __init__(self,logic):
         self.conn_state = {}
         self.epoll_sock = select.epoll()
         self.logic = logic
         remote_cmd = sys.argv[1]+'||'+ sys.argv[2]    # 'date|||root'
         for host in sys.argv[3:] :        #start with the host1 ,host2,host3
             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
             sock.connect((host,remote_port))
             sock.setblocking(0)
             tmp_state = STATE()
             tmp_state.state = 'write'
             tmp_str = '%0'+str(maxheader)+"d%s"
             tmp_state.buff_write = tmp_str % (len(remote_cmd), remote_cmd)   #00010date||root
             tmp_state.need_write = len(tmp_state.buff_write)
             tmp_state.sock_obj = sock
             self.conn_state[sock.fileno()] = tmp_state
             self.epoll_sock.register(sock.fileno(), select.EPOLLOUT)
         self.sm = {
             "accept" : self.accept2read,
             "read"   : self.read2process,
             "write"  : self.write2read,
             "process": self.process,
             "closing": self.close,
         }
Beispiel #3
0
 def setFd(self, sock):
     tmp_state = STATE()
     tmp_state.sock_obj = sock
     self.conn_state[sock.fileno()] = tmp_state
Beispiel #4
0
 def setFd(self,sock):
     tmp_state = STATE()
     tmp_state.sock_obj = sock
     self.conn_state[sock.fileno()] = tmp_state