Ejemplo n.º 1
0
def client(addr):
    sock = socket.socket()
    sock.connect(addr)
    stream = raw.Stream(sock.makefile('rb', -1), sock.makefile('wb', 0))
    requester = Requester(lambda chunk: stream.write_chunk(json.dumps(chunk)))
    dispatcher = Dispatcher(None, requester.handle_response)
    conn = PyConnector(requester)
    gevent.spawn(util.dispatch_loop, stream, dispatcher, json)
    return conn
Ejemplo n.º 2
0
def client(addr):
    sock = socket.socket()
    sock.connect(addr)
    stream = raw.Stream(sock.makefile('rb+'))
    requester = Requester(lambda chunk: stream.write_chunk(json.dumps(chunk)))
    dispatcher = Dispatcher(None, requester.handle_response)
    conn = PyConnector(requester)
    t = threading.Thread(target=util.dispatch_loop,
                         args=(stream, dispatcher, json))
    t.daemon = True
    t.start()
    return conn
Ejemplo n.º 3
0
 def __init__(self, config):
     address = config['control']['socket']
     if address[:1] == '@':
         address = '\x00' + address[1:]
     self._sock = sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     sock.connect(address)
     stream = framing.Stream(sock.makefile('rb', -1), sock.makefile('rw', 0))
     self._requester = requester = jsonrpc.Requester(
             lambda chunk: stream.write_chunk(json.dumps(chunk)))
     super(ControlConnector, self).__init__(requester)
     self._dispatcher = dispatcher = jsonrpc.Dispatcher(
             None, requester.handle_response)
     self._task = gevent.spawn(dispatch_loop, stream, dispatcher)
Ejemplo n.º 4
0
def _handle_request(sock, handler):
    rfile = sock.makefile('rb', -1)
    wfile = sock.makefile('wb', 0)
    stream = framing.Stream(rfile, wfile)
    dispatcher = jsonrpc.Dispatcher(handler)
    dispatch_loop(stream, dispatcher)