我编写了一个最简单的抽象“套接字代理”,它只是从传入连接读取并将所有数据传输到另一台服务器并返回。没有任何传输数据的分析。
我启动代理,然后git remote show origin
。然后通过代理将517个字节传输到“bitbucket.org”,然后所有内容挂起 - 不再有来自git
的字节而没有“bitbucket.org”的回答。 (Bitbucket和SSL仅用于调查目的。)
如何让数据流动?
Java / Groovy中的完整代码:
void main() {
ServerSocket reader = new ServerSocket(443)
Socket clientSocket = reader.accept()
Socket remote = new Socket("bitbucket.org", 443)
Thread t1 = Util.createThread("request-transfer") {
Util.copy(clientSocket.inputStream, remote.outputStream)
}
Thread t2 = Util.createThread("response-transfer") {
Util.copy(remote.inputStream, clientSocket.outputStream)
}
t1.join(); t2.join();
}
static void copy(InputStream src, OutputStream dest) {
log.debug("transferring bytes from IN to OUT")
while (true) {
byte[] buf = new byte[10*1024]
int copied = src.read(buf) // I know about -1
log.debug("read $copied bytes")
dest.write(buf, 0, copied)
dest.flush() // added later
log.debug("copied $copied bytes")
}
}
输出:
transferring bytes from IN to OUT
transferring bytes from IN to OUT
read 517 bytes
copied 517 bytes
< it hangs here >