

def _loopbackAsyncBody(server, serverToClient, client, clientToServer, pumpPolicy):
    "\n    Transfer bytes from the output queue of each protocol to the input of the other.\n\n    @param server: The protocol instance representing the server-side of this\n    connection.\n\n    @param serverToClient: The L{_LoopbackQueue} holding the server's output.\n\n    @param client: The protocol instance representing the client-side of this\n    connection.\n\n    @param clientToServer: The L{_LoopbackQueue} holding the client's output.\n\n    @param pumpPolicy: See L{loopbackAsync}.\n\n    @return: A L{Deferred} which fires when the connection has been closed and\n        both sides have received notification of this.\n    "

    def pump(source, q, target):
        sent = False
        if q:
            pumpPolicy(q, target)
            sent = True
        if (sent and (not q)):
            source.transport._pollProducer()
        return sent
    while 1:
        disconnect = clientSent = serverSent = False
        serverSent = pump(server, serverToClient, client)
        clientSent = pump(client, clientToServer, server)
        if ((not clientSent) and (not serverSent)):
            d = defer.Deferred()
            clientToServer._notificationDeferred = d
            d._notificationDeferred = d
            d.addCallback(_loopbackAsyncContinue, server, serverToClient, client, clientToServer, pumpPolicy)
            return d
        if serverToClient.disconnect:
            disconnect = True
            pump(server, serverToClient, client)
        elif clientToServer.disconnect:
            disconnect = True
            pump(client, clientToServer, server)
        if disconnect:
            server.connectionLost(failure.Failure(main.CONNECTION_DONE))
            client.connectionLost(failure.Failure(main.CONNECTION_DONE))
            return defer.succeed(None)

dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/protocols/loopback.py _loopbackAsyncBody/VarMisuse@143/417 `serverToClient`->`d`