Skip to content

Commit

Permalink
Check the file path is created by the server, before running the clie…
Browse files Browse the repository at this point in the history
…nt too much.
  • Loading branch information
Alun Evans committed Mar 9, 2016
1 parent 7369b5f commit f61210a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/test/java/jnr/unixsocket/example/UnixClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@
import java.io.PrintWriter;
import java.nio.CharBuffer;
import java.nio.channels.Channels;
import java.util.concurrent.TimeUnit;
import jnr.unixsocket.UnixSocketAddress;
import jnr.unixsocket.UnixSocketChannel;

public class UnixClient {
public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException, InterruptedException {
java.io.File path = new java.io.File("/tmp/fubar.sock");
int retries = 0;
while (!path.exists()) {
TimeUnit.MILLISECONDS.sleep(500L);
retries++;
if (retries > 10) {
throw new IOException(
String.format(
"File %s does not exist after retry",
path.getAbsolutePath()
)
);
}
}
String data = "blah blah";
UnixSocketAddress address = new UnixSocketAddress(path);
UnixSocketChannel channel = UnixSocketChannel.open(address);
Expand Down

0 comments on commit f61210a

Please sign in to comment.