예제 #1
0
 def iothread():
     initial = io.read(1)
     assert initial == '1'.encode('ascii')
     channel.gateway._trace('initializing transfer io for', spec.id)
     io_target.write(initial)
     while True:
         message = Message.from_io(io)
         message.to_io(io_target)
예제 #2
0
 def iothread():
     initial = io.read(1)
     assert initial == '1'.encode('ascii')
     channel.gateway._trace('initializing transfer io for', spec.id)
     io_target.write(initial)
     while True:
         message = Message.from_io(io)
         message.to_io(io_target)
예제 #3
0
 def test_wire_protocol(self):
     for i, handler in enumerate(Message._types):
         one = py.io.BytesIO()
         data = '23'.encode('ascii')
         Message(i, 42, data).to_io(one)
         two = py.io.BytesIO(one.getvalue())
         msg = Message.from_io(two)
         assert msg.msgcode == i
         assert isinstance(msg, Message)
         assert msg.channelid == 42
         assert msg.data == data
         assert isinstance(repr(msg), str)
예제 #4
0
 def test_wire_protocol(self):
     for i, handler in enumerate(Message._types):
         one = py.io.BytesIO()
         data = '23'.encode('ascii')
         Message(i, 42, data).to_io(one)
         two = py.io.BytesIO(one.getvalue())
         msg = Message.from_io(two)
         assert msg.msgcode == i
         assert isinstance(msg, Message)
         assert msg.channelid == 42
         assert msg.data == data
         assert isinstance(repr(msg), str)
예제 #5
0
def serve_proxy_io(proxy_channelX):
    execmodel = proxy_channelX.gateway.execmodel
    _trace = proxy_channelX.gateway._trace
    tag = "serve_proxy_io:%s " % proxy_channelX.id

    def log(*msg):
        _trace(tag + msg[0], *msg[1:])

    spec = PseudoSpec(proxy_channelX.receive())
    # create sub IO object which we will proxy back to our proxy initiator
    sub_io = create_io(spec, execmodel)
    control_chan = proxy_channelX.receive()
    log("got control chan", control_chan)

    # read data from master, forward it to the sub
    # XXX writing might block, thus blocking the receiver thread
    def forward_to_sub(data):
        log("forward data to sub, size %s" % len(data))
        sub_io.write(data)

    proxy_channelX.setcallback(forward_to_sub)

    def controll(data):
        if data == RIO_WAIT:
            control_chan.send(sub_io.wait())
        elif data == RIO_KILL:
            control_chan.send(sub_io.kill())
        elif data == RIO_REMOTEADDRESS:
            control_chan.send(sub_io.remoteaddress)
        elif data == RIO_CLOSE_WRITE:
            control_chan.send(sub_io.close_write())

    control_chan.setcallback(controll)

    # write data to the master coming from the sub
    forward_to_master_file = proxy_channelX.makefile("w")

    # read bootstrap byte from sub, send it on to master
    log('reading bootstrap byte from sub', spec.id)
    initial = sub_io.read(1)
    assert initial == '1'.encode('ascii'), initial
    log('forwarding bootstrap byte from sub', spec.id)
    forward_to_master_file.write(initial)

    # enter message forwarding loop
    while True:
        try:
            message = Message.from_io(sub_io)
        except EOFError:
            log('EOF from sub, terminating proxying loop', spec.id)
            break
        message.to_io(forward_to_master_file)
예제 #6
0
def serve_proxy_io(proxy_channelX):
    execmodel = proxy_channelX.gateway.execmodel
    _trace = proxy_channelX.gateway._trace
    tag = "serve_proxy_io:%s " % proxy_channelX.id

    def log(*msg):
        _trace(tag + msg[0], *msg[1:])
    spec = PseudoSpec(proxy_channelX.receive())
    # create sub IO object which we will proxy back to our proxy initiator
    sub_io = create_io(spec, execmodel)
    control_chan = proxy_channelX.receive()
    log("got control chan", control_chan)

    # read data from master, forward it to the sub
    # XXX writing might block, thus blocking the receiver thread
    def forward_to_sub(data):
        log("forward data to sub, size %s" % len(data))
        sub_io.write(data)
    proxy_channelX.setcallback(forward_to_sub)

    def controll(data):
        if data == RIO_WAIT:
            control_chan.send(sub_io.wait())
        elif data == RIO_KILL:
            control_chan.send(sub_io.kill())
        elif data == RIO_REMOTEADDRESS:
            control_chan.send(sub_io.remoteaddress)
        elif data == RIO_CLOSE_WRITE:
            control_chan.send(sub_io.close_write())
    control_chan.setcallback(controll)

    # write data to the master coming from the sub
    forward_to_master_file = proxy_channelX.makefile("w")

    # read bootstrap byte from sub, send it on to master
    log('reading bootstrap byte from sub', spec.id)
    initial = sub_io.read(1)
    assert initial == '1'.encode('ascii'), initial
    log('forwarding bootstrap byte from sub', spec.id)
    forward_to_master_file.write(initial)

    # enter message forwarding loop
    while True:
        try:
            message = Message.from_io(sub_io)
        except EOFError:
            log('EOF from sub, terminating proxying loop', spec.id)
            break
        message.to_io(forward_to_master_file)