recv_pack = struct.unpack('ii64s',datalist[fileno]) if recv_pack[1] == 10: check = hash.get_info(recv_pack[2].replace('\0','').strip())#把空字符转换成空格,再去掉空格 if check != None: check_rel = check.split('\\') tem = [] for val in check_rel: tem.append(struct.pack('32s',val))#把每个返回结果都打包成32个字节 send_val = ''.join(tem)#把列表整合成字符串 backmsg[fileno] = struct.pack('ii224s',232,11,send_val) epoll.modify(fileno, select.EPOLLOUT | select.EPOLLET) else: backmsg[fileno] = struct.pack('ii224s',8,11,'\0') epoll.modify(fileno, select.EPOLLOUT | select.EPOLLET) elif recv_pack[1]==9: hash.update_hashtable('Telephone', 'root', 'IceFlow2012') epoll.unregister(fileno) hash.init_hashtable('Telephone','root','IceFlow2012') try: connections = {};addresses = {};datalist = {};backmsg = {} while True: events = epoll.poll(1)#查询epoll对象 是否有事件被触发 参数表示1秒 等待一秒看是否有事件发生 for fileno,event in events: if fileno == serversocket.fileno(): try: #while True: connection,address = serversocket.accept() print "accept connection from %s, %d, fd = %d" % (address[0], address[1], connection.fileno()) connection.setblocking(0) epoll.register(connection.fileno(),select.EPOLLIN|select.EPOLLET)
def reload_sql(self): hash.update_hashtable(self.db, self.user, self.passwd)
'\0', '').strip()) #把空字符转换成空格,再去掉空格 if check != None: check_rel = check.split('\\') tem = [] for val in check_rel: tem.append(struct.pack('32s', val)) #把每个返回结果都打包成32个字节 send_val = ''.join(tem) #把列表整合成字符串 backmsg[fileno] = struct.pack('ii224s', 232, 11, send_val) epoll.modify(fileno, select.EPOLLOUT | select.EPOLLET) else: backmsg[fileno] = struct.pack('ii224s', 8, 11, '\0') epoll.modify(fileno, select.EPOLLOUT | select.EPOLLET) elif recv_pack[1] == 9: hash.update_hashtable('Telephone', 'root', 'IceFlow2012') epoll.unregister(fileno) elif event & select.EPOLLHUP: epoll.unregister(fileno) connections[fileno].close() del connections[fileno] elif event & select.EPOLLOUT: try: while len(backmsg[fileno]) > 0: sendlen = connections[fileno].send(backmsg[fileno]) backmsg[fileno] = backmsg[fileno][sendlen:] except socket.error: pass if len(backmsg[fileno]) == 0: epoll.modify(fileno,
def reload_sql(self): hash.update_hashtable(self.db,self.user,self.passwd)