Exemple #1
0
                self._send_bytes += self._sock.send(self._buffer[self._send_bytes:])
                if self._send_bytes == len(self._buffer):
                    break
            except socket.error as e:
                if e[0] == errno.EWOULDBLOCK:
                    return True
                print(e)
                break
        self._buffer = None
        self._send_bytes = 0
        return False

    def handle_close(self, handle, mask):
        print("handle close")
        super(Echo, self).handle_close(handle, mask)

if __name__ == '__main__':
    g_reactor = Reactor()
    if not g_reactor.open():
        print("reactor open failed")
    
    if sys.argv[1] == 'server':
        g_acceptor = Acceptor(Echo)
        g_acceptor.open(("127.0.0.1", 8008), g_reactor)
    elif sys.argv[1] == 'client':
        g_connector = Connector()
        g_connector.open(g_reactor)
        g_connector.connect(Echo('client'), ("127.0.0.1", 8008), 5)

    g_reactor.reactor_event_loop()
Exemple #2
0
        #url = php_interface + "?url=" + fileid
        url = php_interface + "?" + fileid
        addr = parse_addr(php_interface)
        con = PHPInterface(fileid, addr, url)
        g_connector.connect(con, addr, 4)
        g_active_task_num += 1

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print("check_push.py phpinterface filelist recvbytes(default is filesize)")
        sys.exit(1)
    
    php_interface = sys.argv[1]
    g_reactor = Reactor("any", False)
    if not g_reactor.open():
        print("reactor open failed")

    for line in open(sys.argv[2], "rt"):
        s = line.strip()
        if len(s) > 0: g_filelist.append(s);
    if len(sys.argv) == 4:
        g_recv_bytes = int(sys.argv[3])
    g_task_num = len(g_filelist)
    g_connector = Connector()
    g_connector.open(g_reactor)
    dispatch_task()
    while True:
        if not g_reactor.handle_events():
            print("reactor error")
            sys.exit(0)