Ejemplo n.º 1
0
def main():
    conf = {"address": ("127.0.0.1", 5000), "debug": True,
            "num_workers": 3}
    spec = (HttpWorker, 30, "send_file", {}, "worker",)

    arbiter = TcpArbiter(conf, spec)
    arbiter.run()
Ejemplo n.º 2
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     # we return a spec
     return (
         MyTcpWorker,
         30,
         "worker",
         {},
         "http_welcome",
     )
Ejemplo n.º 3
0
def main():
    conf = {"address": ("127.0.0.1", 5000), "debug": True, "num_workers": 3}
    spec = (
        HttpWorker,
        30,
        "send_file",
        {},
        "worker",
    )

    arbiter = TcpArbiter(conf, spec)
    arbiter.run()
Ejemplo n.º 4
0
def run_server():
    parser = argparse.ArgumentParser(
            description='serve a static file folder')

    parser.add_argument('path', type=str, help='Folder to serve',
            default=".", nargs='?')

    parser.add_argument(
        '--bind', 
        type=str, 
        default="127.0.0.1:5000",
        help="""\
            The socket to bind.
            
            A string of the form: 'HOST', 'HOST:PORT', 'unix:PATH'. An IP is a valid
            HOST.
            """)

    parser.add_argument(
            '--workers', 
            type=int, 
            default=1,
            help='number of workers')

    parser.add_argument(
            '--name', 
            type=str, 
            default="fserve",
            help='name of the server')

    parser.add_argument(
            '--debug', 
            action='store_true', 
            default=False,
            help='Debug mode')
    
    args = parser.parse_args()

    
    path = args.path
    if path == ".":
        path = os.getcwd()

    address  = parse_address(util.to_bytestring(args.bind))
    conf = {"address": address, "debug": args.debug,
            "num_workers": args.workers}

    spec = (HttpWorker, 30, "worker", 
            {"path": path}, args.name,)
    
    arbiter = TcpArbiter(conf, spec, name=args.name)
    arbiter.run()
Ejemplo n.º 5
0
def run_main():
    parser = argparse.ArgumentParser(description='FileServer - a gevent based TCP file server.')
    parser.add_argument('--port', dest='port', default=4530, type=int, 
        help='Port to listen for incoming connections (default: %(default)s)')
    parser.add_argument('--workers', dest='workers', default=3, type=int,
        help='Number of workers to fork (default: (%(default)s)')
    parser.add_argument('--host', dest='host', default='0.0.0.0',
        help='Host to listen (default: (%(default)s)')

    args = parser.parse_args()
    conf = {'num_workers': args.workers, 'address' : (args.host, args.port)}
    spec = (FileServerWorker, 30, 'worker', {}, 'worker',)
    arbiter = TcpArbiter(conf, spec)
    arbiter.run()
Ejemplo n.º 6
0
# See the NOTICE for more information.
import os

from pistil.tcp.sync_worker import TcpSyncWorker
from pistil.tcp.arbiter import TcpArbiter

from http_parser.reader import SocketReader


class MyTcpWorker(TcpSyncWorker):

    def handle(self, sock, addr):
        s = SocketReader(sock)
        l = s.readline()
        print l
        sock.send(l)

if __name__ == '__main__':
    try:
        os.remove('/tmp/pistil.sock')
    except Exception:
        pass
    conf = {"num_workers": 3, "address": "unix:/tmp/pistil.sock"}
    spec = (MyTcpWorker, 30, "worker", {}, "worker",)

    arbiter = TcpArbiter(conf, spec)
    print "try to connect with :"
    print "nc -U /tmp/pistil.sock"

    arbiter.run()
Ejemplo n.º 7
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     # we return a spec
     return (conf['fanout.worker'], 30, "worker", {}, "worker",)
Ejemplo n.º 8
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     return RedBarrelSocketIOWorker, 9999, "worker", conf, "socketio"
Ejemplo n.º 9
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     return RedBarrelWSGIWorker, 30, "worker", conf, "rb"
Ejemplo n.º 10
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     # we return a spec
     return (MyTcpWorker, 30, "worker", {}, "http_welcome",)
Ejemplo n.º 11
0
from http_parser.http import HttpStream
from http_parser.reader import SocketReader


class MyTcpWorker(TcpSyncWorker):
    def handle(self, sock, addr):
        p = HttpStream(SocketReader(sock))

        path = p.path()
        data = "hello world"
        sock.send("".join([
            "HTTP/1.1 200 OK\r\n", "Content-Type: text/html\r\n",
            "Content-Length:" + str(len(data)) + "\r\n",
            "Connection: close\r\n\r\n", data
        ]))


if __name__ == '__main__':
    conf = {"num_workers": 3}
    spec = (
        MyTcpWorker,
        30,
        "worker",
        {},
        "worker",
    )

    arbiter = TcpArbiter(conf, spec)

    arbiter.run()
Ejemplo n.º 12
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     return RedBarrelSocketIOWorker, 9999, "worker", conf, "socketio"
Ejemplo n.º 13
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     return RedBarrelWSGIWorker, 30, "worker", conf, "rb"