Permalink
Browse files

Finish the non-blocking connect during init

Because the connect was non-blocking, a new connection would often throw an IOException
when used immediately after init(). Now, force the connect to block so that it is
immediately usable.
  • Loading branch information...
1 parent dba8b22 commit fc09b5affc3fe6e04d1a955eaa66b0012da601b3 @rocketraman rocketraman committed Apr 13, 2011
Showing with 1 addition and 4 deletions.
  1. +1 −4 src/com/trendrr/beanstalk/BeanstalkConnection.java
@@ -6,11 +6,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
-import java.net.SocketException;
import java.nio.ByteBuffer;
-import java.nio.channels.AsynchronousCloseException;
-import java.nio.channels.ClosedByInterruptException;
-import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.SocketChannel;
@@ -36,6 +32,7 @@ public void connect(String addr, int port) throws BeanstalkException {
try {
this.channel = SocketChannel.open();
this.channel.connect(new InetSocketAddress(addr, port));
+ this.channel.finishConnect();
} catch (Exception x) {
throw new BeanstalkException(x);
}

0 comments on commit fc09b5a

Please sign in to comment.