commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1154855 [2/2] - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/ native/include/acr/ native/os/win32/ native/shared/
Date Mon, 08 Aug 2011 06:57:16 GMT
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsstream.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsstream.c?rev=1154855&r1=1154854&r2=1154855&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsstream.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsstream.c Mon Aug  8 06:57:15
2011
@@ -55,10 +55,10 @@ ACR_INLINE(int) sdrelease(acr_ss_t *ss)
         return 1;
 }
 
-ACR_NET_EXPORT(jlong, IpcStream, alloc0)(JNI_STDARGS, jlong fp)
+ACR_NET_EXPORT(jlong, IpcStream, alloc0)(JNI_STDARGS, jlong sp)
 {
     acr_ss_t *ss;
-    acr_sd_t *sd = J2P(fp, acr_sd_t *);
+    acr_sd_t *sd = J2P(sp, acr_sd_t *);
 
     if (sd == 0 || sd->p == 0) {
         ACR_THROW_NET_ERROR(ACR_EBADF);
@@ -79,6 +79,26 @@ ACR_NET_EXPORT(jint, IpcStream, close0)(
     return 0;
 }
 
+ACR_NET_EXPORT(jboolean, IpcStream, eof0)(JNI_STDARGS, jlong sp)
+{
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if (ACR_HASFLAG(ss->sd, ACR_SO_RDEOF))
+        return JNI_TRUE;
+    else
+        return JNI_FALSE;
+}
+
+ACR_NET_EXPORT(jint, IpcStream, avail0)(JNI_STDARGS, jlong sp)
+{
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if (ss->sd != 0)
+        return AcrIpcAvail(ss->sd->p, TRUE);
+    else
+        return -1;
+}
+
 ACR_NET_EXPORT(jint, IpcStream, read0)(JNI_STDARGS, jlong sp)
 {
     int  rc = 0;
@@ -94,7 +114,10 @@ ACR_NET_EXPORT(jint, IpcStream, read0)(J
     }
     if (ACR_HASFLAG(ss->sd, ACR_SO_RDEOF))
         goto finally;
-    rd = AcrIpcRead(cp, &ch, 1);
+    if (cp->dwPageSize == 0)
+        rd = AcrIpcRecv(cp, &ch, 1);
+    else
+        rd = AcrIpcRead(cp, &ch, 1);
     if (rd == -1)
         rc = ACR_GET_OS_ERROR();
     else if (rd == 1)
@@ -110,3 +133,442 @@ finally:
     return rv;
 }
 
+ACR_NET_EXPORT(jint, IpcStream, read1)(JNI_STDARGS, jlong sp,
+                                       jbyteArray buf,
+                                       jint off,
+                                       jint len)
+{
+    int rc = 0;
+    int rd = 0;
+    jbyte  *bb = 0;
+    jbyte  *bc = 0;
+    jbyte   onstack[ACR_PBUFF_SIZ];
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+    LPIPCSOCK cp;
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    if (ACR_HASFLAG(ss->sd, ACR_SO_RDEOF))
+        goto finally;
+    if (len > ACR_PBUFF_SIZ) {
+        if (len > ACR_MEGABYTE) {
+            if ((bc = (*env)->GetByteArrayElements(env, buf, 0)) != 0)
+                bb = bc + off;
+        }
+        else {
+            /* Allocate buffer */
+            bb = ACR_MALLOC(jbyte, len);
+        }
+    }
+    if (bb == 0) {
+        rc = ACR_ENOMEM;
+        goto finally;
+    }
+    if (cp->dwPageSize == 0)
+        rd = AcrIpcRecv(cp, bb, len);
+    else
+        rd = AcrIpcRead(cp, bb, len);
+    if (rd == -1) {
+        rc = GetLastError();
+        goto finally;
+    }
+    else if (rd == 0)
+        ss->sd->flags |= ACR_SO_RDEOF;
+
+finally:
+    sdrelease(ss);
+    if (rc == 0) {
+        if (rd > 0) {
+            if (bc != 0) {
+                (*env)->ReleaseByteArrayElements(env, buf, bc, 0);
+                return (jint)rd;
+            }
+            else
+                (*env)->SetByteArrayRegion(env, buf, (jsize)off, (jsize)rd, bb);
+        }
+    }
+    if (bb != 0 && bb != onstack) {
+        if (bc != 0)
+            (*env)->ReleaseByteArrayElements(env, buf, bc, JNI_ABORT);
+        else
+            AcrFree(bb);
+    }
+    if (rc != 0) {
+        rd = 0;
+        /* Throw exception */
+        ACR_THROW_NET_ERROR(rc);
+    }
+    return rd;
+}
+
+ACR_NET_EXPORT(jint, IpcStream, read2)(JNI_STDARGS, jlong sp,
+                                       jlong pa,
+                                       jlong off,
+                                       jint len)
+{
+    int rc = 0;
+    int rd = 0;
+    LPIPCSOCK cp;
+    ptrdiff_t po = (ptrdiff_t)off;
+    char     *bb = J2P(pa, char *);
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    if (ACR_HASFLAG(ss->sd, ACR_SO_RDEOF))
+        goto finally;
+    if (bb == 0) {
+        rc = ACR_EINVAL;
+        goto finally;
+    }
+    if (cp->dwPageSize == 0)
+        rd = AcrIpcRecv(cp, bb + po, len);
+    else
+        rd = AcrIpcRead(cp, bb + po, len);
+    if (rd == -1) {
+        rc = GetLastError();
+        goto finally;
+    }
+    else if (rd == 0)
+        ss->sd->flags |= ACR_SO_RDEOF;
+
+finally:
+    sdrelease(ss);
+    if (rc != 0) {
+        rd = 0;
+        /* Throw exception */
+        ACR_THROW_NET_ERROR(rc);
+    }
+    return rd;
+}
+
+
+ACR_NET_EXPORT(jint, IpcStream, read3)(JNI_STDARGS, jlong sp,
+                                       jobject buf,
+                                       jint off,
+                                       jint len)
+{
+    int rc = 0;
+    int rd = 0;
+    LPIPCSOCK cp;
+    char     *bb = 0;
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    if (ACR_HASFLAG(ss->sd, ACR_SO_RDEOF))
+        goto finally;
+    bb = (char *)(*env)->GetDirectBufferAddress(env, buf);
+    if (bb == 0) {
+        rc = ACR_EINVAL;
+        goto finally;
+    }
+
+    if (cp->dwPageSize == 0)
+        rd = AcrIpcRecv(cp, bb + off, len);
+    else
+        rd = AcrIpcRead(cp, bb + off, len);
+    if (rd == -1) {
+        rc = GetLastError();
+        goto finally;
+    }
+    else if (rd == 0)
+        ss->sd->flags |= ACR_SO_RDEOF;
+
+finally:
+    sdrelease(ss);
+    if (rc != 0) {
+        rd = 0;
+        /* Throw exception */
+        ACR_THROW_NET_ERROR(rc);
+    }
+    return rd;
+}
+
+ACR_NET_EXPORT(jint, IpcStream, write0)(JNI_STDARGS, jlong sp, jint b)
+{
+    int rc = 0;
+    int wr = 0;
+    unsigned char ch = (unsigned char)(b & 0xFF);
+    LPIPCSOCK cp;
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    if (cp->dwPageSize == 0)
+        wr = AcrIpcSend(cp,  &ch, 1, ss->sd->flags);
+    else
+        wr = AcrIpcWrite(cp, &ch, 1, ss->sd->flags);
+    if (wr == -1)
+        rc = GetLastError();
+finally:
+    sdrelease(ss);
+    if (rc != 0) {
+        wr = -1;
+        ACR_THROW_NET_ERROR(rc);
+    }
+    return wr;
+}
+
+ACR_NET_EXPORT(jint, IpcStream, write1)(JNI_STDARGS, jlong sp,
+                                        jbyteArray buf,
+                                        jint off,
+                                        jint len)
+{
+    int rc = 0;
+    int wr = 0;
+    jbyte    *bb = 0;
+    LPIPCSOCK cp;
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    bb = (*env)->GetByteArrayElements(env, buf, 0);
+    if (bb == 0) {
+        rc = ACR_EINVAL;
+        goto finally;
+    }
+    if (cp->dwPageSize == 0)
+        wr = AcrIpcSend(cp,  bb + off, len, ss->sd->flags);
+    else
+        wr = AcrIpcWrite(cp, bb + off, len, ss->sd->flags);
+    if (wr == -1)
+        rc = GetLastError();
+finally:
+    sdrelease(ss);
+    if (bb != 0)
+        (*env)->ReleaseByteArrayElements(env, buf, bb, JNI_ABORT);
+    if (rc != 0) {
+        wr = -1;
+        ACR_THROW_NET_ERROR(rc);
+    }
+    return wr;
+}
+
+ACR_NET_EXPORT(jint, IpcStream, write2)(JNI_STDARGS, jlong sp,
+                                        jlong pa,
+                                        jlong off,
+                                        jint len)
+{
+    int rc = 0;
+    int wr = 0;
+    ptrdiff_t po = (ptrdiff_t)off;
+    LPIPCSOCK cp;
+    char     *bb = J2P(pa, char *);
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    if (bb == 0) {
+        rc = ACR_EINVAL;
+        goto finally;
+    }
+    if (cp->dwPageSize == 0)
+        wr = AcrIpcSend(cp,  bb + po, len, ss->sd->flags);
+    else
+        wr = AcrIpcWrite(cp, bb + po, len, ss->sd->flags);
+    if (wr == -1)
+        rc = GetLastError();
+finally:
+    sdrelease(ss);
+    if (rc != 0) {
+        wr = -1;
+        ACR_THROW_NET_ERROR(rc);
+    }
+    return wr;
+}
+
+ACR_NET_EXPORT(jint, IpcStream, write3)(JNI_STDARGS, jlong sp,
+                                        jobject buf,
+                                        jint off,
+                                        jint len)
+{
+    int rc = 0;
+    int wr = 0;
+    char     *bb = 0;
+    LPIPCSOCK cp;
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    bb = (char *)(*env)->GetDirectBufferAddress(env, buf);
+    if (bb == 0) {
+        rc = ACR_EINVAL;
+        goto finally;
+    }
+    if (cp->dwPageSize == 0)
+        wr = AcrIpcSend(cp,  bb + off, len, ss->sd->flags);
+    else
+        wr = AcrIpcWrite(cp, bb + off, len, ss->sd->flags);
+    if (wr == -1)
+        rc = GetLastError();
+finally:
+    sdrelease(ss);
+    if (rc != 0) {
+        wr = -1;
+        ACR_THROW_NET_ERROR(rc);
+    }
+    return wr;
+}
+
+#define ACR_IOVEC_ON_STACK 32
+ACR_NET_EXPORT(jlong, IpcStream, write4)(JNI_STDARGS, jlong sp,
+                                         jobjectArray vec,
+                                         jint off,
+                                         jint len)
+{
+    int  i;
+    DWORD   wr = 0;
+    int     rc = 0;
+    LPIPCSOCK   cp;
+    jbyteArray *boa = 0;
+    LPWSABUF    iov = 0;
+    u_long      siz = 0;
+    WSABUF      onstack[ACR_IOVEC_ON_STACK];
+    jbyteArray  bastack[ACR_IOVEC_ON_STACK];
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    if ((*env)->EnsureLocalCapacity(env, len * 2)) {
+        rc = ACR_ENOMEM;
+        goto finally;
+    }
+    if (len > ACR_IOVEC_ON_STACK) {
+        iov = ACR_CALLOC(WSABUF, len);
+        if (iov == 0) {
+            rc = ACR_ENOMEM;
+            goto finally;
+        }
+        boa = ACR_CALLOC(jbyteArray, len);
+        if (boa == 0) {
+            rc = ACR_ENOMEM;
+            goto finally;
+        }
+    }
+    else {
+        iov = onstack;
+        boa = bastack;
+    }
+
+    for (i = 0; i < len; i++) {
+        boa[i] = (*env)->GetObjectArrayElement(env, vec, (jsize)(i + off));
+        if (boa[i] == 0) {
+            /* XXX: What's the correct error ?
+             */
+            rc = ACR_EINVAL;
+            goto finally;
+        }
+        iov[i].len = (u_long)(*env)->GetArrayLength(env, boa[i]);
+        iov[i].buf = (char *)(*env)->GetByteArrayElements(env, boa[i], 0);
+        siz += iov[i].len;
+    }
+
+    if (cp->dwPageSize == 0) {
+        wr = siz;
+        rc = AcrIpcSendv(cp,  iov, len, ss->sd->flags);
+    }
+    else {
+        wr = AcrIpcWritev(cp, iov, len, ss->sd->flags);
+        if (wr == -1)
+            rc = GetLastError();
+    }
+
+finally:
+    sdrelease(ss);
+    if (boa != 0) {
+        for (i = 0; i < len; i++) {
+            if (boa[i] == 0)
+                break;
+            (*env)->ReleaseByteArrayElements(env, boa[i],
+                                             (jbyte *)iov[i].buf,
+                                             JNI_ABORT);
+        }
+        if (boa != bastack)
+            AcrFree(boa);
+    }
+    if (iov != onstack)
+        AcrFree(iov);
+    if (rc != 0) {
+        ACR_THROW_NET_ERROR(rc);
+        return ACR_I64_C(-1);
+    }
+    return (jlong)wr;
+}
+
+ACR_NET_EXPORT(jlong, IpcStream, write5)(JNI_STDARGS, jlong sp,
+                                         jobjectArray vec,
+                                         jint off,
+                                         jint len)
+{
+    int  i;
+    DWORD     wr = 0;
+    int       rc = 0;
+    LPIPCSOCK cp;
+    LPWSABUF  iov = 0;
+    u_long    siz = 0;
+    WSABUF    onstack[ACR_IOVEC_ON_STACK];
+    acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+    if ((cp = sdretain(ss)) == 0) {
+        rc = ACR_EBADF;
+        goto finally;
+    }
+    if (len > ACR_IOVEC_ON_STACK) {
+        iov = ACR_CALLOC(WSABUF, len);
+        if (iov == 0) {
+            rc = ACR_ENOMEM;
+            goto finally;
+        }
+    }
+    else {
+        iov = onstack;
+    }
+    for (i = 0; i < len; i++) {
+        jobject bb = (*env)->GetObjectArrayElement(env, vec, (jsize)(i + off));
+        if (bb == 0) {
+            /* XXX: What's the correct error ?
+             */
+            rc = ACR_EINVAL;
+            goto finally;
+        }
+        iov[i].len = (u_long)(*env)->GetDirectBufferCapacity(env, bb);
+        iov[i].buf = (char *)(*env)->GetDirectBufferAddress(env, bb);
+        siz += iov[i].len;
+        (*env)->DeleteLocalRef(env, bb);
+    }
+    if (cp->dwPageSize == 0) {
+        wr = siz;
+        rc = AcrIpcSendv(cp,  iov, len, ss->sd->flags);
+    }
+    else {
+        wr = AcrIpcWritev(cp, iov, len, ss->sd->flags);
+        if (wr == -1)
+            rc = GetLastError();
+    }
+finally:
+    sdrelease(ss);
+    if (iov != onstack)
+        AcrFree(iov);
+    if (rc != 0) {
+        ACR_THROW_NET_ERROR(rc);
+        return ACR_I64_C(-1);
+    }
+    return (jlong)wr;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c?rev=1154855&r1=1154854&r2=1154855&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Mon Aug  8 06:57:15 2011
@@ -886,6 +886,44 @@ ACR_NET_EXPORT(jbyteArray, LocalEndpoint
     return ba;
 }
 
+ACR_NET_EXPORT(jbyteArray, IpcEndpointAddress, sockaddr0)(JNI_STDARGS, jstring hostname)
+{
+    int   rc = ACR_ENOTIMPL;
+    jbyteArray ba = 0;
+#if defined(WINDOWS)
+    acr_sockaddr_t sa;
+
+    memset(&sa, 0, sizeof(acr_sockaddr_t));
+    WITH_WSTR(hostname)
+    {
+        if (WideCharToMultiByte(CP_UTF8, 0, J2S(hostname), -1, sa.hostname,
+                                NI_MAXHOST, 0, 0) == 0) {
+            /* Conversion failed. */
+            rc = GetLastError();
+        }
+        else {
+            sa.family  = AF_LOCAL;
+            sa.addrlen = ISIZEOF(sa.hostname);
+            sa.iplen   = sa.addrlen;
+            rc = 0;
+        }
+    } DONE_WITH_STR(hostname);
+
+    if (rc == 0) {
+        sa.addrcnt = 1;
+        ba = (*env)->NewByteArray(env, ISIZEOF(acr_sockaddr_t));
+        if (ba != 0)
+            (*env)->SetByteArrayRegion(env, ba, 0, ISIZEOF(acr_sockaddr_t), (jbyte *)&sa);
+    }
+
+#endif
+    if (rc != 0) {
+        ACR_THROW_NET_ERROR(rc);
+        return 0;
+    }
+    return ba;
+}
+
 ACR_NET_EXPORT(jint, Address, size0)(JNI_STDARGS)
 {
     return ISIZEOF(acr_sockaddr_t);



Mime
View raw message