Ejemplo n.º 1
0
def t1(qname, qtype):
    p = t0(qname, getattr(dns.TYPE, qtype))
    s = coro.udp_sock()
    s.connect(('192.168.200.1', 53))
    s.send(p)
    r = s.recv(8192)
    coro.write_stderr('reply=%r\n' % (r, ))
    u = dns.Unpacker(r)
    return u.unpack()
Ejemplo n.º 2
0
def t1 (qname, qtype):
    p = t0 (qname, getattr (dns.TYPE, qtype))
    s = coro.udp_sock()
    s.connect (('192.168.200.1', 53))
    s.send (p)
    r = s.recv (8192)
    coro.write_stderr ('reply=%r\n' % (r,))
    u = dns.Unpacker (r)
    return u.unpack()
Ejemplo n.º 3
0
def serve():
    s = coro.tcp_sock()
    s.bind (('', 9001))
    s.listen (5)
    coro.write_stderr ('Try "telnet localhost 9001" to watch the worms!\n')
    while 1:
        c, a = s.accept()
        t = terminal (c)
        the_arena.listeners.append (t)
Ejemplo n.º 4
0
 def crack (self, h):
     "Crack one header line."
     # deliberately ignoring 822 crap like continuation lines.
     try:
         i = h.index (': ')
         name, value = h[:i], h[i + 2:]
         self[name] = value
     except ValueError:
         coro.write_stderr ('dropping bogus header %r\n' % (h,))
         pass
Ejemplo n.º 5
0
 def crack(self, h):
     "Crack one header line."
     # deliberately ignoring 822 crap like continuation lines.
     try:
         i = h.index(': ')
         name, value = h[:i], h[i + 2:]
         self[name] = value
     except ValueError:
         coro.write_stderr('dropping bogus header %r\n' % (h, ))
         pass
Ejemplo n.º 6
0
 def serve (self, family, address):
     self.s = coro.make_socket (family, socket.SOCK_STREAM)
     self.s.bind ((address, 0))
     self.port = self.s.getsockname()[1]
     self.s.set_reuse_addr()
     self.s.listen (5)
     while True:
         try:
             coro.write_stderr ('accepting...\n')
             conns = self.s.accept_many (5)
             coro.write_stderr ('...after: conns=%r\n' % (conns,))
         except coro.Shutdown:
             break
         for s, addr in conns:
             session = TestSession (s, addr)
             coro.spawn (session.run)
Ejemplo n.º 7
0
def client (ip='127.0.0.1', port=9000):
    global alive
    alive += 1
    try:
        s = coro.tcp_sock()
        s.connect ((ip, port))
        for i in range (10):
            s.send ('howdy there\r\n')
            assert (s.recv_exact (13) == 'howdy there\r\n')
        coro.write_stderr ('.')
        s.close()
    finally:
        alive -= 1
        if alive == 0:
            coro.write_stderr ('\ndone.\n')
            coro.set_exit()
Ejemplo n.º 8
0
def status():
    while 1:
        coro.sleep_relative (2)
        coro.write_stderr ('%5d worms %5d threads\n' % (len(the_arena.worms), len(coro.all_threads)))
Ejemplo n.º 9
0
# -*- Mode: Python -*-

import coro
import echo_server

port = 9000
coro.write_stderr ('starting echo server on port %d\n' % (port,))
server = echo_server.echo_server (port)
coro.spawn (server.go)
coro.write_stderr ('starting event loop\n')
coro.event_loop()
coro.write_stderr ('exited event loop\n')
Ejemplo n.º 10
0
def status():
    while 1:
        coro.sleep_relative (2)
        coro.write_stderr ('%5d worms %5d threads\n' % (len(the_arena.worms), len(coro.all_threads)))