Skip to content

Commit

Permalink
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/src/main/java/org/jruby/ext/socket/RubyTCPSocket.java
Original file line number Diff line number Diff line change
@@ -107,8 +107,16 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
// Do this nonblocking so we can be interrupted
channel.configureBlocking(false);
channel.connect( new InetSocketAddress(InetAddress.getByName(remoteHost), remotePort) );
context.getThread().select(channel, this, SelectionKey.OP_CONNECT);
channel.finishConnect();

// wait for connection
while (!context.getThread().select(channel, this, SelectionKey.OP_CONNECT)) {
context.pollThreadEvents();
}

// complete connection
while (!channel.finishConnect()) {
context.pollThreadEvents();
}

// only try to set blocking back if we succeeded to finish connecting
channel.configureBlocking(true);

0 comments on commit af1d26d

Please sign in to comment.