Author: mturk
Date: Tue Jul 19 06:22:37 2011
New Revision: 1148190
URL: http://svn.apache.org/viewvc?rev=1148190&view=rev
Log:
Fix setting SO_LINGER sockopt
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h?rev=1148190&r1=1148189&r2=1148190&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h Tue Jul
19 06:22:37 2011
@@ -299,17 +299,17 @@
#define ACR_BEGIN_MACRO if (1) {
#define ACR_END_MACRO } else (void)(0)
-#define ACR_SET(o, f) do { (o) |= (f); } while (0)
-#define ACR_CLR(o, f) do { (o) &= ~(f); } while (0)
-#define ACR_HAS(o, f) (((o) & (f)) != 0)
-#define ACR_NOT(o, f) (((o) & (f)) == 0)
+#define ACR_SET(o, f) (o) |= (f)
+#define ACR_CLR(o, f) (o) &= ~(f)
+#define ACR_HAS(o, f) (((o) & (f)) == (f))
+#define ACR_NOT(o, f) (((o) & (f)) != (f))
#define ACR_ISSET(o, f) (((o) & (f)) == (f))
-#define ACR_SETFLAG(s, f) do { (s)->flags |= (f); } while (0)
-#define ACR_CLRFLAG(s, f) do { (s)->flags &= ~(f); } while (0)
-#define ACR_HASFLAG(s, f) (((s)->flags & (f)) != 0)
-#define ACR_PUTFLAG(s, f, on) do { if (on) (s)->flags |= (f); \
- else (s)->flags &= ~(f); } while (0)
+#define ACR_SETFLAG(s, f) (s)->flags |= (f)
+#define ACR_CLRFLAG(s, f) (s)->flags &= ~(f)
+#define ACR_HASFLAG(s, f) (((s)->flags & (f)) == (f))
+#define ACR_PUTFLAG(s, f, v) if ((v) != 0) (s)->flags |= (f); \
+ else (s)->flags &= ~(f)
#define UNUSED_SOURCE_FILE(F) \
const char __provided_##F [] = "Using system provided " #F "()"
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=1148190&r1=1148189&r2=1148190&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 Tue Jul 19
06:22:37 2011
@@ -85,12 +85,17 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
case ACR_OPT_SO_LINGER:
#ifdef SO_LINGER
{
- struct linger li;
- li.l_onoff = opt == 0 ? 0 : 1;
- li.l_linger = opt;
+ struct linger li = { 0, 0 };
+ if (val >= 0 ) {
+ li.l_onoff = 1;
+ li.l_linger = val;
+ val = 1;
+ }
+ else
+ val = 0;
if (setsockopt(fd->s, SOL_SOCKET, SO_LINGER, (char *)&li,
SSIZEOF(struct linger)) != 0)
return ACR_GET_NETOS_ERROR();
- ACR_PUTFLAG(fd, ACR_SO_LINGER, opt);
+ ACR_PUTFLAG(fd, ACR_SO_LINGER, val);
}
#else
rc = ACR_ENOTIMPL;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h?rev=1148190&r1=1148189&r2=1148190&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h Tue Jul
19 06:22:37 2011
@@ -43,6 +43,7 @@
#define I2H(I) (HANDLE)IntToPtr((I))
#define I2SOCK(I) (SOCKET)IntToPtr((I))
#define SOCK2I(S) PtrToInt((S))
+#define SOCK2H(S) (HANDLE)(uintptr_t)(S)
#define ACR_CRLF "\r\n"
#define ACR__THREAD(pg) _cr__thread(pg)
#define RESOURCE_NAME_LEN 64
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c?rev=1148190&r1=1148189&r2=1148190&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c Tue Jul
19 06:22:37 2011
@@ -51,6 +51,14 @@ ACR_NET_EXPORT(jint, SocketDescriptor, c
AcrFree(fd->socketfname);
fd->socketfname = 0;
}
+ if (!ACR_HASFLAG(fd, ACR_SO_LINGER)) {
+ /* Windows closesock doesn't properly
+ * handle sending FIN when called.
+ * Send diconnect messages if the lingering
+ * was disabled so that this call doesn't block.
+ */
+ WSASendDisconnect(sd, 0);
+ }
if (closesocket(sd) == SOCKET_ERROR)
rc = ACR_GET_NETOS_ERROR();
fd->s = INVALID_SOCKET;
@@ -170,6 +178,8 @@ ACR_NET_EXPORT(jlong, SocketDescriptor,
sd = socket(af, type, 0);
if (sd == INVALID_SOCKET)
rc = ACR_GET_NETOS_ERROR();
+ else
+ SetHandleInformation(SOCK2H(sd), HANDLE_FLAG_INHERIT, FALSE);
if (block == JNI_FALSE && rc == 0) {
u_long one = 1;
if (ioctlsocket(sd, FIONBIO, &one) == SOCKET_ERROR) {
@@ -221,6 +231,8 @@ ACR_NET_EXPORT(jlong, SocketDescriptor,
sd = socket(AF_INET, type, 0);
if (sd == INVALID_SOCKET)
rc = ACR_GET_NETOS_ERROR();
+ else
+ SetHandleInformation(SOCK2H(sd), HANDLE_FLAG_INHERIT, FALSE);
if (block == JNI_FALSE && rc == 0) {
u_long one = 1;
if (ioctlsocket(sd, FIONBIO, &one) == SOCKET_ERROR) {
@@ -317,6 +329,7 @@ ACR_NET_EXPORT(jlong, SocketServerEndpoi
ACR_THROW_NET_ERRNO();
return 0;
}
+ SetHandleInformation(SOCK2H(sd), HANDLE_FLAG_INHERIT, FALSE);
if (ACR_HASFLAG(fd, ACR_TCP_NODELAY)) {
int on = 1;
if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (char *)&on,
SSIZEOF(int)) != 0) {
@@ -423,18 +436,8 @@ ACR_NET_EXPORT(jint, SocketEndpoint, con
if (rc != 0) {
if (timeout > 0) {
if (rc == WSAEINPROGRESS || rc == WSAEALREADY || rc ==
WSAEWOULDBLOCK) {
+ /* Wait for the async connect */
rc = AcrWaitIO(sd, timeout, FD_CONNECT);
-#if 0
- /* We have already check the error in AcrWaitIo call. */
- if (rc == 0) {
- int err = 0;
- int len = ISIZEOF(err);
- if (getsockopt(sd, SOL_SOCKET, SO_ERROR, (char *)&err,
&len) == -1)
- rc = ACR_GET_NETOS_ERROR();
- else if (err != 0)
- rc = err;
- }
-#endif
}
if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK))
AcrNonblock(sd, 0);
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c?rev=1148190&r1=1148189&r2=1148190&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c Tue Jul
19 06:22:37 2011
@@ -59,14 +59,19 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
break;
case ACR_OPT_SO_LINGER:
{
- struct linger li;
- if (opt > USHRT_MAX)
- opt = USHRT_MAX;
- li.l_onoff = opt == 0 ? 0 : 1;
- li.l_linger = (u_short)opt;
+ struct linger li = { 0, 0 };
+ if (val > USHRT_MAX)
+ val = USHRT_MAX;
+ if (val >= 0 ) {
+ li.l_onoff = 1;
+ li.l_linger = (u_short)val;
+ val = 1;
+ }
+ else
+ val = 0;
if (setsockopt(fd->s, SOL_SOCKET, SO_LINGER, (char *)&li,
SSIZEOF(struct linger)) != 0)
return ACR_GET_NETOS_ERROR();
- ACR_PUTFLAG(fd, ACR_SO_LINGER, opt);
+ ACR_PUTFLAG(fd, ACR_SO_LINGER, val);
}
break;
case ACR_OPT_SO_TIMEOUT: