def main ( ip='127.0.0.2', port=80, precision=1.0, inactive=3.0, local=256, private=16, public=2 ): from allegra import async_server, tcp_server, http_server listen = tcp_server.decorate(async_server.Listen ( http_server.Dispatcher, (ip, port), precision, tcp_server.LISTEN_MAX ), inactive, local, private, public) def http_404_not_found (reactor): reactor.http_response (404) # Not Found listen.http_continue = http_404_not_found async_loop.catch (listen.server_shutdown)
def serve(obj, ip, port): ''' start a server ''' return async_server.Listen(lambda: Dispatcher(obj), (ip, port), 6.0, 5)
def Listen(Dispatcher, name, precision, max=5): return async_server.Listen(Dispatcher, name, precision, max, socket.AF_INET)
import socket from allegra import (async_loop, finalization, async_net, async_chat, async_server) loglines = async_server.Listen(async_chat.Dispatcher, ('127.0.0.1', 1234), 6.0, 5, socket.AF_INET) async_loop.catch(loglines.server_shutdown) del loglines lognet = async_server.Listen(async_net.Dispatcher, ('127.0.0.1', 2345), 6.0, 5, socket.AF_INET) async_server.accept_named(lognet, 512) async_server.inactive(lognet, 6) async_loop.catch(lognet.server_shutdown) del lognet loglines = async_server.Listen(async_chat.Dispatcher, ('127.0.0.1', 3456), 3.0, 5, socket.AF_INET) loglines.server_resolved = (lambda addr: addr[0]) async_server.accept_named(loglines, 2) async_server.rationed(loglines, 6.0, 1 << 14, 1 << 16) async_loop.catch(loglines.server_shutdown) del loglines async_loop.dispatch() finalization.collect()
import sys from allegra import async_loop, async_core, async_server try: TCP_WINDOW_SIZE = 1 << int (sys.argv[1]) except: TCP_WINDOW_SIZE = 1 << 14 TCP_OVERFLOW_DATA = 'x' * (TCP_WINDOW_SIZE*2) class Flaking (async_core.Dispatcher): def handle_write (self): self.send (TCP_OVERFLOW_DATA) def handle_read (self): self.recv (TCP_WINDOW_SIZE/2) def close_when_done (self): self.close () flaking = async_server.Listen ( Flaking, ('127.0.0.1', 1234), 6.0, 5 ) async_loop.catch (flaking.server_shutdown) async_loop.dispatch ()