Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Unlike TSocket which takes a timeout in its constructor and uses it as both the connect timeout and the so timeout, TNonblockingSocket only supports a setTimeout method which sets the so timeout but doesn't apply the timeout to the connect operation. Instead, it calls the convenience method SocketChannel.open in its constructor, which calls a blocking, connection-free connect before we set the socket into non-blocking mode or set an so timeout on it.
A solution would be to do something like the following:
SocketChannel socketChannel = SocketChannel.open();
this.socket_ = socketChannel.socket();
socket_.setSoTimeout(timeout_);
socket_.connect(new InetSocketAddress(host, port), timeout_);
socketChannel.configureBlocking(false);
That's a bit weird since in TSocket we do the blocking connect in the open() method instead of the constructor, but it seems like a better fix than to refactor all the non-blocking stuff to also call open().
Also, the initSocket() method in TNonblockingSocket is invalid entirely (although unreachable) as it would overwrite the Socket from the channel with a new, unconnected blocking one.