Skip to content

Commit

Permalink
Updated native code with a ten-second timeout on read and write opera…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
jetpaccomputer committed Dec 30, 2013
1 parent 83cb2c0 commit d53a74b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions com/etsy/net/UnixDomainSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Java_com_etsy_net_UnixDomainSocket_nativeOpen(JNIEnv * jEnv,
{
int s; /* socket file handle */
struct sockaddr_un sa;
struct timeval timeout;
const char *socketFile =
(*jEnv)->GetStringUTFChars(jEnv, jSocketFile, NULL);
socklen_t salen = sockaddr_init(socketFile, &sa);
Expand All @@ -144,6 +145,16 @@ Java_com_etsy_net_UnixDomainSocket_nativeOpen(JNIEnv * jEnv,
return -1;
}

timeout.tv_sec = 10;
timeout.tv_usec = 0;
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
perror("nativeOpen: setsockopt SO_RCVTIMEO failed");
}

if (setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
perror("nativeOpen: setsockopt SO_SNDTIMEO failed");
}

(*jEnv)->ReleaseStringUTFChars(jEnv, jSocketFile, socketFile);

/* return the socket file handle */
Expand Down

0 comments on commit d53a74b

Please sign in to comment.