Author: mturk
Date: Fri Jul 15 14:57:09 2011
New Revision: 1147174
URL: http://svn.apache.org/viewvc?rev=1147174&view=rev
Log:
Add common inlines for retain/release. They are used in multiple files so skip
duplicate code
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h?rev=1147174&r1=1147173&r2=1147174&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h Fri Jul
15 14:57:09 2011
@@ -130,6 +130,27 @@ ACR_INLINE(int) AcrAtomic32Equ(volatile
# endif
#endif
+ACR_INLINE(int) AcrSdRetain(acr_sd_t *sd)
+{
+ AcrAtomic32Inc(&sd->refs);
+ return sd->s;
+}
+
+ACR_INLINE(int) AcrSdRelease(acr_sd_t *sd)
+{
+ if (AcrAtomic32Dec(&sd->refs) == 0) {
+ /* Socket was closed while we were
+ * executing the native method.
+ * Since Socket didn't free the fd
+ * we have to do it here.
+ */
+ AcrFree(sd);
+ return 0;
+ }
+ else
+ return 1;
+}
+
#ifdef __cplusplus
}
#endif
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c?rev=1147174&r1=1147173&r2=1147174&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c Fri Jul 15
14:57:09 2011
@@ -25,27 +25,6 @@
#include <poll.h>
#include <sys/un.h>
-ACR_INLINE(int) retain_sd(acr_sd_t *sd)
-{
- AcrAtomic32Inc(&sd->refs);
- return sd->s;
-}
-
-ACR_INLINE(int) release_sd(acr_sd_t *sd)
-{
- if (AcrAtomic32Dec(&sd->refs) == 0) {
- /* Socket was closed while we were
- * executing the native method.
- * Since Socket didn't free the fd
- * we have to do it here.
- */
- AcrFree(sd);
- return 0;
- }
- else
- return 1;
-}
-
ACR_NET_EXPORT(jlong, SocketDescriptor, socket0)(JNI_STDARGS, jint saf,
jint stype, jboolean block)
{
@@ -228,13 +207,13 @@ ACR_NET_EXPORT(jint, SocketDescriptor, s
how = SHUT_WR;
else
how = SHUT_RDWR;
- sd = retain_sd(fd);
+ sd = AcrSdRetain(fd);
if (shutdown(fd->s, how) == -1)
rc = ACR_GET_NETOS_ERROR();
if (how != 1) {
ACR_SETFLAG(fd, ACR_DT_HITEOF);
}
- release_sd(fd);
+ AcrSdRelease(fd);
return rc;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c?rev=1147174&r1=1147173&r2=1147174&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c Fri Jul
15 14:57:09 2011
@@ -34,27 +34,6 @@
#define SOCKADDR_RELEASE(BA, SA) \
AcrReleaseArrayCritical(env, (BA), (SA))
-ACR_INLINE(int) retain_sd(acr_sd_t *sd)
-{
- AcrAtomic32Inc(&sd->refs);
- return sd->s;
-}
-
-ACR_INLINE(int) release_sd(acr_sd_t *sd)
-{
- if (AcrAtomic32Dec(&sd->refs) == 0) {
- /* Socket was closed while we were
- * executing the native method.
- * Since Socket didn't free the fd
- * we have to do it here.
- */
- AcrFree(sd);
- return 0;
- }
- else
- return 1;
-}
-
ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jlong fp,
jbyteArray cb, jint timeout)
{
@@ -63,7 +42,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
acr_sockaddr_t *ca = SOCKADDR_CAST(cb);
acr_sd_t *fd = J2P(fp, acr_sd_t *);
- sd = retain_sd(fd);
+ sd = AcrSdRetain(fd);
if (timeout == 0)
timeout = fd->timeout;
if (timeout > 0 && !ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
@@ -100,7 +79,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
}
}
finally:
- release_sd(fd);
+ AcrSdRelease(fd);
return rc;
}
@@ -149,7 +128,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
flags |= SOCK_NONBLOCK;
# endif
#endif
- ad = retain_sd(fd);
+ ad = AcrSdRetain(fd);
memset(&aa, 0, sizeof(aa));
aalen = ISIZEOF(struct sockaddr_un);
do {
@@ -159,7 +138,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
sd = accept(ad, (struct sockaddr *)&aa.sa, &aalen);
#endif
} while (sd == -1 && errno == EINTR);
- if (release_sd(fd) == 0 && sd != -1) {
+ if (AcrSdRelease(fd) == 0 && sd != -1) {
sd = -1;
errno = ENOTSOCK;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c?rev=1147174&r1=1147173&r2=1147174&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c Fri Jul
15 14:57:09 2011
@@ -42,23 +42,17 @@ typedef struct acr_ss_t {
ACR_INLINE(int) retain_sd(acr_ss_t *ss)
{
- if (ss->fd != 0) {
- AcrAtomic32Inc(&ss->fd->refs);
- return ss->fd->s;
- }
+ if (ss->fd != 0)
+ return AcrSdRetain(ss->fd);
else
return -1;
}
ACR_INLINE(int) release_sd(acr_ss_t *ss)
{
- if (AcrAtomic32Dec(&ss->fd->refs) == 0) {
- /* Socket was closed while we were
- * executing the native method.
- * Since Socket didn't free the fd
- * we have to do it here.
- */
- AcrFree(ss->fd);
+ if (ss->fd == 0)
+ return 0;
+ if (AcrSdRelease(ss->fd) == 0) {
ss->fd = 0;
return 0;
}
@@ -84,11 +78,10 @@ ACR_NET_EXPORT(jlong, SocketStream, allo
ACR_NET_EXPORT(jint, SocketStream, close0)(JNI_STDARGS, jlong sp)
{
- int rc = 0;
acr_ss_t *ss = J2P(sp, acr_ss_t *);
AcrFree(ss);
- return rc;
+ return 0;
}
ACR_NET_EXPORT(jboolean, SocketStream, eof0)(JNI_STDARGS, jlong sp)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h?rev=1147174&r1=1147173&r2=1147174&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h Fri Jul
15 14:57:09 2011
@@ -77,4 +77,25 @@ ACR_INLINE(int) AcrAtomic32Equ(volatile
return InterlockedCompareExchange(val, cmp, cmp) == cmp;
}
+ACR_INLINE(SOCKET) AcrSdRetain(acr_sd_t *sd)
+{
+ AcrAtomic32Inc(&sd->refs);
+ return sd->s;
+}
+
+ACR_INLINE(int) AcrSdRelease(acr_sd_t *sd)
+{
+ if (AcrAtomic32Dec(&sd->refs) == 0) {
+ /* Socket was closed while we were
+ * executing the native method.
+ * Since Socket didn't free the fd
+ * we have to do it here.
+ */
+ AcrFree(sd);
+ return 0;
+ }
+ else
+ return 1;
+}
+
#endif /* _ACR_ARCH_SYNC_H_ */
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=1147174&r1=1147173&r2=1147174&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 Fri Jul
15 14:57:09 2011
@@ -28,27 +28,6 @@
#define SOCKADDR_RELEASE(BA, SA) \
AcrReleaseArrayCritical(env, (BA), (SA))
-ACR_INLINE(SOCKET) retain_sd(acr_sd_t *sd)
-{
- AcrAtomic32Inc(&sd->refs);
- return sd->s;
-}
-
-ACR_INLINE(int) release_sd(acr_sd_t *sd)
-{
- if (AcrAtomic32Dec(&sd->refs) == 0) {
- /* Socket was closed while we were
- * executing the native method.
- * Since Socket didn't free the fd
- * we have to do it here.
- */
- AcrFree(sd);
- return 0;
- }
- else
- return 1;
-}
-
ACR_NET_EXPORT(jboolean, SocketAddress, haveipv6)(JNI_STDARGS)
{
SOCKET sock;
@@ -108,13 +87,13 @@ ACR_NET_EXPORT(jint, SocketDescriptor, s
how = SD_SEND;
else
how = SD_BOTH;
- sd = retain_sd(fd);
- if (shutdown(fd->s, how) == SOCKET_ERROR)
+ sd = AcrSdRetain(fd);
+ if (shutdown(sd, how) == SOCKET_ERROR)
rc = ACR_GET_NETOS_ERROR();
if (how != 1) {
ACR_SETFLAG(fd, ACR_DT_HITEOF);
}
- release_sd(fd);
+ AcrSdRelease(fd);
return rc;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c?rev=1147174&r1=1147173&r2=1147174&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c Fri Jul
15 14:57:09 2011
@@ -41,27 +41,6 @@
#define SOCKADDR_RELEASE(BA, SA) \
AcrReleaseArrayCritical(env, (BA), (SA))
-ACR_INLINE(SOCKET) retain_sd(acr_sd_t *sd)
-{
- AcrAtomic32Inc(&sd->refs);
- return sd->s;
-}
-
-ACR_INLINE(int) release_sd(acr_sd_t *sd)
-{
- if (AcrAtomic32Dec(&sd->refs) == 0) {
- /* Socket was closed while we were
- * executing the native method.
- * Since Socket didn't free the fd
- * we have to do it here.
- */
- AcrFree(sd);
- return 0;
- }
- else
- return 1;
-}
-
ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jlong fp,
jbyteArray cb, jint timeout)
{
@@ -104,7 +83,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
if (timeout == 0)
timeout = fd->timeout;
- sd = retain_sd(fd);
+ sd = AcrSdRetain(fd);
if (timeout > 0 && !ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
/* Turn the socket to non-blocking mode
* for the duration of the connect call.
@@ -133,7 +112,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
}
}
finally:
- release_sd(fd);
+ AcrSdRelease(fd);
return rc;
}
@@ -227,9 +206,9 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
acr_sd_t *fd = J2P(fp, acr_sd_t *);
memset(&sa, 0, sizeof(sa));
- ad = retain_sd(fd);
+ ad = AcrSdRetain(fd);
sd = accept(ad, 0, 0);
- if (release_sd(fd) == 0 && sd != INVALID_SOCKET) {
+ if (AcrSdRelease(fd) == 0 && sd != INVALID_SOCKET) {
/* XXX: Can this happen ? */
sd = INVALID_SOCKET;
WSASetLastError(WSAENOTSOCK);