'forward socket'

def forward_socket(self, local, remote, timeout, bufsize):

    tick = 1
    count = timeout
    while 1:
        count -= tick
        if (count <= 0):
            break
        (ins, _, errors) = select.select([local, remote], [], [local, remote], tick)
        if (remote in errors):
            local.close()
            remote.close()
            return
        if (local in errors):
            local.close()
            remote.close()
            return
        if (remote in ins):
            data = remote.recv(bufsize)
            if (not data):
                remote.close()
                local.close()
                return
            local.sendall(data)
        if (local in ins):
            data = local.recv(bufsize)
            if (not data):
                remote.close()
                local.close()
                return
            remote.sendall(data)
        if ins:
            count = timeout
