Author: mturk
Date: Wed Aug 10 04:50:12 2011
New Revision: 1156025
URL: http://svn.apache.org/viewvc?rev=1156025&view=rev
Log:
Infinite timeout is zero for SO_RCVTIMEO. Make sure we don't pass invalid values
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c?rev=1156025&r1=1156024&r2=1156025&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c Wed Aug 10
04:50:12 2011
@@ -65,7 +65,12 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
acr_sd_t *fd = J2P(fp, acr_sd_t *);
#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO
struct timeval zt = { 0, 0 };
- struct timeval tv = { val / 1000, (val % 1000) * 1000 };
+ struct timeval tv = { 0, 0 };
+
+ if (val > 0) {
+ tv.tv_sec = (long)(val / 1000);
+ tv.tv_usec = (long)(val % 1000) / 1000;
+ }
#endif
/* Set numeric values */
@@ -177,7 +182,7 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
int on = val == JNI_TRUE ? 1 : 0;
acr_sd_t *fd = J2P(fp, acr_sd_t *);
#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO
- struct timeval zt = { 0, 0 };
+ struct timeval zero = { 0, 0 };
#endif
/* Set numeric values */
@@ -214,9 +219,9 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
ACR_CLRFLAG(fd, ACR_SO_WPART);
#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO
setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
- (char *)&zt, SSIZEOF(struct timeval));
+ (char *)&zero, SSIZEOF(zero));
setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
- (char *)&zt, SSIZEOF(struct timeval));
+ (char *)&zero, SSIZEOF(zero));
#endif
}
}