Author: mturk
Date: Wed Jul 13 04:36:02 2011
New Revision: 1145858
URL: http://svn.apache.org/viewvc?rev=1145858&view=rev
Log:
Add stream and rename usock
Added:
commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c
- copied, changed from r1145784,
commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c (with
props)
Removed:
commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketStream.java
commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketStream.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketStream.java?rev=1145858&r1=1145857&r2=1145858&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketStream.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketStream.java
Wed Jul 13 04:36:02 2011
@@ -71,10 +71,11 @@ class SocketStream extends Stream
public final void close()
throws IOException
{
- if (valid()) {
+ if (nd != 0L) {
try {
close0(nd);
- sd.close();
+ if (sd != null)
+ sd.close();
}
finally {
nd = 0L;
@@ -96,7 +97,7 @@ class SocketStream extends Stream
@Override
public boolean closed()
{
- if (sd == null)
+ if (sd == null || nd == 0L)
return true;
else
return sd.closed();
@@ -105,7 +106,7 @@ class SocketStream extends Stream
@Override
public boolean valid()
{
- if (sd != null)
+ if (sd != null && nd != 0L)
return sd.valid();
else
return false;
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1145858&r1=1145857&r2=1145858&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Wed Jul 13
04:36:02 2011
@@ -65,6 +65,7 @@ UNIX_SOURCES=\
$(TOPDIR)/os/unix/execmem.c \
$(TOPDIR)/os/unix/inetsock.c \
$(TOPDIR)/os/unix/init.c \
+ $(TOPDIR)/os/unix/localsock.c \
$(TOPDIR)/os/unix/platform.c \
$(TOPDIR)/os/unix/poll.c \
$(TOPDIR)/os/unix/pollset.c \
@@ -73,8 +74,8 @@ UNIX_SOURCES=\
$(TOPDIR)/os/unix/shmem.c \
$(TOPDIR)/os/unix/selectset.c \
$(TOPDIR)/os/unix/semaphore.c \
+ $(TOPDIR)/os/unix/sockstream.c \
$(TOPDIR)/os/unix/time.c \
- $(TOPDIR)/os/unix/usock.c \
$(TOPDIR)/os/unix/util.c
BSDX_SOURCES=\
Copied: commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c (from
r1145784, commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c)
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c?p2=commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c&p1=commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c&r1=1145784&r2=1145858&rev=1145858&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c Wed Jul
13 04:36:02 2011
@@ -50,6 +50,25 @@ ACR_NET_EXPORT(jint, LocalDescriptor, cl
return rc;
}
+ACR_NET_EXPORT(jint, LocalDescriptor, shutdown0)(JNI_STDARGS, jlong fp,
+ jint how)
+{
+ int rc = 0;
+ acr_fd_t *fd = J2P(fp, acr_fd_t *);
+
+ if (fd == 0)
+ return ACR_EBADF;
+ if (how == 0)
+ how = SHUT_RD;
+ else if (how == 1)
+ how = SHUT_WR;
+ else
+ how = SHUT_RDWR;
+ if (shutdown(fd->u.s, how) == -1)
+ rc = ACR_GET_NETOS_ERROR();
+ return rc;
+}
+
ACR_NET_EXPORT(jint, LocalDescriptor, sendz0)(JNI_STDARGS, jlong fp)
{
char dummy = 0;
Added: 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=1145858&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c Wed Jul
13 04:36:02 2011
@@ -0,0 +1,109 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/error.h"
+#include "acr/iodefs.h"
+#include "acr/clazz.h"
+#include "acr/string.h"
+#include "acr/memory.h"
+#include "acr/iofd.h"
+#include "acr/netapi.h"
+#include "acr/unsafe.h"
+#include "acr/port.h"
+#include "arch_opts.h"
+#include "arch_sync.h"
+#include <poll.h>
+
+#define SOCKADDR_CAST(BA) \
+ (acr_sockaddr_t *)AcrGetArrayCritical(env, (BA))
+#define SOCKADDR_RELEASE(BA, SA) \
+ AcrReleaseArrayCritical(env, (BA), (SA))
+
+typedef struct acr_ss_t {
+ acr_fd_t *fd;
+} acr_ss_t;
+
+ACR_INLINE(int) _retain_sd(acr_ss_t *ss)
+{
+ if (ss->fd != 0) {
+ AcrAtomic32Inc(&ss->fd->refs);
+ return ss->fd->u.s;
+ }
+ else
+ return -1;
+}
+
+ACR_INLINE(void) _release_sd(acr_ss_t *ss)
+{
+ if (AcrAtomic32Dec(&ss->fd->refs) == 0) {
+ AcrFree(ss->fd);
+ ss->fd = 0;
+ }
+}
+
+ACR_NET_EXPORT(jlong, SocketStream, alloc0)(JNI_STDARGS, jlong fp)
+{
+ acr_ss_t *ss;
+ acr_fd_t *fd = J2P(fp, acr_fd_t *);
+
+ if (fd == 0 || fd->u.s == -1) {
+ ACR_THROW_NET_ERROR(ACR_EBADF);
+ return 0;
+ }
+
+ if ((ss = ACR_TALLOC(acr_ss_t)) == 0)
+ return 0;
+ ss->fd = fd;
+ return P2J(ss);
+}
+
+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;
+}
+
+ACR_NET_EXPORT(jint, SocketStream, read0)(JNI_STDARGS, jlong sp)
+{
+ int sd;
+ int rc = 0;
+ int rv = -1;
+ ssize_t rd;
+ unsigned char ch;
+ acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+ if ((sd = _retain_sd(ss)) == -1) {
+ rc = ACR_EBADF;
+ goto finally;
+ }
+ rd = r_read(sd, &ch, 1);
+ if (rd == -1)
+ rc = ACR_GET_OS_ERROR();
+ else if (rd == 0)
+ rv = -1;
+ else
+ rv = ch;
+finally:
+ _release_sd(ss);
+ if (rc != 0) {
+ ACR_THROW_NET_ERROR(rc);
+ return -1;
+ }
+ return rv;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c
------------------------------------------------------------------------------
svn:eol-style = native
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=1145858&r1=1145857&r2=1145858&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 Wed Jul
13 04:36:02 2011
@@ -59,12 +59,31 @@ ACR_NET_EXPORT(jint, LocalDescriptor, cl
if (closesocket(wd->fd.u.s) == SOCKET_ERROR)
rc = ACR_GET_NETOS_ERROR();
wd->fd.u.s = INVALID_SOCKET;
- }
+ }
if (AcrAtomic32Dec(&wd->fd.refs) == 0)
AcrFree(wd);
return rc;
}
+ACR_NET_EXPORT(jint, LocalDescriptor, shutdown0)(JNI_STDARGS, jlong fp,
+ jint how)
+{
+ int rc = 0;
+ acr_fd_t *fd = J2P(fp, acr_fd_t *);
+
+ if (fd == 0)
+ return ACR_EBADF;
+ if (how == 0)
+ how = SD_RECEIVE;
+ else if (how == 1)
+ how = SD_SEND;
+ else
+ how = SD_BOTH;
+ if (shutdown(fd->u.s, how) == SOCKET_ERROR)
+ rc = ACR_GET_NETOS_ERROR();
+ return rc;
+}
+
ACR_NET_EXPORT(jint, LocalDescriptor, sendz0)(JNI_STDARGS, jlong fp)
{
char dummy = 0;
@@ -98,7 +117,7 @@ ACR_NET_EXPORT(jlong, LocalDescriptor, s
}
sd = socket(AF_INET, type, 0);
- if (sd == -1)
+ if (sd == INVALID_SOCKET)
rc = ACR_GET_NETOS_ERROR();
if (block == JNI_FALSE && rc == 0) {
u_long one = 1;