cvs commit: jakarta-tomcat-connectors/jni/native/src network.c poll.c
mturk 2005/06/10 00:06:10 Modified:jni/java/org/apache/tomcat/jni Status.java jni/native/include tcn.h jni/native/src network.c poll.c Log: Use macros for portable wrapping of APR_STATUS_IS to user error messages for most common return values Revision ChangesPath 1.8 +4 -1 jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Status.java Index: Status.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Status.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Status.java 9 Jun 2005 11:13:40 - 1.7 +++ Status.java 10 Jun 2005 07:06:10 - 1.8 @@ -177,6 +177,9 @@ public static final int TIMEUP= (APR_OS_START_USERERR + 1); public static final int EAGAIN= (APR_OS_START_USERERR + 2); +public static final int EINTR = (APR_OS_START_USERERR + 3); +public static final int EINPROGRESS = (APR_OS_START_USERERR + 4); +public static final int ETIMEDOUT = (APR_OS_START_USERERR + 5); private static native boolean is(int err, int idx); /** 1.15 +20 -3 jakarta-tomcat-connectors/jni/native/include/tcn.h Index: tcn.h === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/include/tcn.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- tcn.h 9 Jun 2005 11:13:40 - 1.14 +++ tcn.h 10 Jun 2005 07:06:10 - 1.15 @@ -39,8 +39,25 @@ #define APR_MAX_IOVEC_SIZE 1024 #endif -#define TCN_TIMEUP APR_OS_START_USERERR + 1 -#define TCN_EAGAIN APR_OS_START_USERERR + 2 +#define TCN_TIMEUP APR_OS_START_USERERR + 1 +#define TCN_EAGAIN APR_OS_START_USERERR + 2 +#define TCN_EINTR APR_OS_START_USERERR + 3 +#define TCN_EINPROGRESS APR_OS_START_USERERR + 4 +#define TCN_ETIMEDOUT APR_OS_START_USERERR + 5 + +#define TCN_ERROR_WRAP(E) \ +if (APR_STATUS_IS_TIMEUP(E))\ +(E) = TCN_TIMEUP; \ +else if (APR_STATUS_IS_EAGAIN(E)) \ +(E) = TCN_EAGAIN; \ +else if (APR_STATUS_IS_EINTR(E))\ +(E) = TCN_EINTR;\ +else if (APR_STATUS_IS_EINPROGRESS(E)) \ +(E) = TCN_EINPROGRESS; \ +else if (APR_STATUS_IS_ETIMEDOUT(E))\ +(E) = TCN_ETIMEDOUT;\ +else\ +(E) = (E) #define TCN_CLASS_PATH org/apache/tomcat/jni/ #define TCN_FINFO_CLASS TCN_CLASS_PATH FileInfo 1.25 +11 -21jakarta-tomcat-connectors/jni/native/src/network.c Index: network.c === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/network.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- network.c 9 Jun 2005 11:13:40 - 1.24 +++ network.c 10 Jun 2005 07:06:10 - 1.25 @@ -292,8 +292,7 @@ if (ss == APR_SUCCESS) return (jint)nbytes; else { -if (APR_STATUS_IS_EAGAIN(ss)) -ss = TCN_EAGAIN; +TCN_ERROR_WRAP(ss); return -(jint)ss; } } @@ -315,8 +314,7 @@ if (ss == APR_SUCCESS) return (jint)nbytes; else { -if (APR_STATUS_IS_EAGAIN(ss)) -ss = TCN_EAGAIN; +TCN_ERROR_WRAP(ss); return -(jint)ss; } } @@ -351,8 +349,7 @@ if (ss == APR_SUCCESS) return (jint)written; else { -if (APR_STATUS_IS_EAGAIN(ss)) -ss = TCN_EAGAIN; +TCN_ERROR_WRAP(ss); return -(jint)ss; } } @@ -386,8 +383,7 @@ if (ss == APR_SUCCESS) return (jint)nbytes; else { -if (APR_STATUS_IS_EAGAIN(ss)) -ss = TCN_EAGAIN; +TCN_ERROR_WRAP(ss); return -(jint)ss; } } @@ -410,8 +406,7 @@ if (ss == APR_SUCCESS) return (jint)nbytes; else { -if (APR_STATUS_IS_EAGAIN(ss)) -ss = TCN_EAGAIN; +TCN_ERROR_WRAP(ss); return -(jint)ss; } } @@ -444,8 +439,7 @@ if (ss == APR_SUCCESS) return (jint)nbytes; else { -if (APR_STATUS_IS_EAGAIN(ss)) -ss = TCN_EAGAIN; +TCN_ERROR_WRAP(ss); return -(jint)ss; } } @@ -468,8 +462,7 @@ if (ss == APR_SUCCESS) return (jint)nbytes; else { -if (APR_STATUS_IS_EAGAIN(ss)) -ss = TCN_EAGAIN; +TCN_ERROR_WRAP(ss); return
cvs commit: jakarta-tomcat-connectors/jni/native/src network.c poll.c
mturk 2005/04/23 08:51:03 Modified:jni/java/org/apache/tomcat/jni Socket.java jni/native/src network.c poll.c Log: Remove 'senfilet' function, because it's useless. Also return the error from Poll.poll Revision ChangesPath 1.13 +1 -24 jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Socket.java Index: Socket.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Socket.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- Socket.java 18 Apr 2005 16:25:20 - 1.12 +++ Socket.java 23 Apr 2005 15:51:03 - 1.13 @@ -445,27 +445,4 @@ byte[][] trailers, long offset, int len, int flags); -/** - * Send a file from an open file descriptor to a socket, along with - * optional headers and trailers, with a timeout. - * The number of bytes actually sent is stored in the len parameter. - * The offset parameter is passed by reference for no reason; its - * value will never be modified by the apr_socket_sendfile() function. - * @param sock The socket to which we're writing - * @param file The open file from which to read - * @param headers Array containing the headers to send - * @param trailers Array containing the trailers to send - * @param offset Offset into the file where we should begin writing - * @param len Number of bytes to send from the file - * @param flags APR flags that are mapped to OS specific flags - * @param timeout Socket timeout to use with the call. The original - *socket timeout will be preserved. - * @return Number of bytes actually sent, including headers, - * file, and trailers - * - */ -public static native int sendfilet(long sock, long file, byte [][] headers, - byte[][] trailers, long offset, - int len, int flags, long timeout); - } 1.14 +0 -73 jakarta-tomcat-connectors/jni/native/src/network.c Index: network.c === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/network.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- network.c 18 Apr 2005 16:22:23 - 1.13 +++ network.c 23 Apr 2005 15:51:03 - 1.14 @@ -577,76 +577,3 @@ else return -(jint)ss; } - -TCN_IMPLEMENT_CALL(jint, Socket, sendfilet)(TCN_STDARGS, jlong sock, -jlong file, -jobjectArray headers, -jobjectArray trailers, -jlong offset, jint len, -jint flags, jlong timeout) -{ -apr_socket_t *s = J2P(sock, apr_socket_t *); -apr_file_t *f = J2P(file, apr_file_t *); -jsize nh = 0; -jsize nt = 0; -jsize i; -struct iovec hvec[APR_MAX_IOVEC_SIZE]; -struct iovec tvec[APR_MAX_IOVEC_SIZE]; -jobject hba[APR_MAX_IOVEC_SIZE]; -jobject tba[APR_MAX_IOVEC_SIZE]; -apr_off_t off = (apr_off_t)offset; -apr_size_t written = (apr_size_t)len; -apr_hdtr_t hdrs; -apr_status_t ss; -apr_interval_time_t t; - -UNREFERENCED(o); -TCN_ASSERT(sock != 0); -TCN_ASSERT(file != 0); - -if (headers) -nh = (*e)-GetArrayLength(e, headers); -if (trailers) -nt = (*e)-GetArrayLength(e, trailers); -/* Check for overflow */ -if (nh = APR_MAX_IOVEC_SIZE || nt = APR_MAX_IOVEC_SIZE) -return (jint)(-APR_ENOMEM); -if ((ss = apr_socket_timeout_get(s, t)) != APR_SUCCESS) - return -(jint)ss; -if ((ss = apr_socket_timeout_set(s, J2T(timeout))) != APR_SUCCESS) - return -(jint)ss; - -for (i = 0; i nh; i++) { -hba[i] = (*e)-GetObjectArrayElement(e, headers, i); -hvec[i].iov_len = (*e)-GetArrayLength(e, hba[i]); -hvec[i].iov_base = (*e)-GetByteArrayElements(e, hba[i], NULL); -} -for (i = 0; i nt; i++) { -tba[i] = (*e)-GetObjectArrayElement(e, trailers, i); -tvec[i].iov_len = (*e)-GetArrayLength(e, tba[i]); -tvec[i].iov_base = (*e)-GetByteArrayElements(e, tba[i], NULL); -} -hdrs.headers = hvec[0]; -hdrs.numheaders = nh; -hdrs.trailers = tvec[0]; -hdrs.numtrailers = nt; - -ss = apr_socket_sendfile(s, f, hdrs, off, written, (apr_int32_t)flags); -/* Resore the original timeout */ -apr_socket_timeout_set(s, t); - -for (i
cvs commit: jakarta-tomcat-connectors/jni/native/src network.c poll.c
mturk 2005/04/13 23:47:56 Modified:jni/java/org/apache/tomcat/jni Poll.java jni/native/src network.c poll.c Log: Add time to live to socket Poller, so we can maintain resources. The returned descriptor will be returned with APR_POOLIN + APR_POLLHUP in case the recycle is needed. Revision ChangesPath 1.5 +3 -3 jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Poll.java Index: Poll.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Poll.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Poll.java 13 Apr 2005 13:16:55 - 1.4 +++ Poll.java 14 Apr 2005 06:47:56 - 1.5 @@ -60,9 +60,10 @@ * @param size The maximum number of descriptors that this pollset can hold * @param p The pool from which to allocate the pollset * @param flags Optional flags to modify the operation of the pollset. + * @param ttl Maximum time to live for a particular socket. * @return The pointer in which to return the newly created object */ -public static native long create(int size, long p, int flags) +public static native long create(int size, long p, int flags, long ttl) throws Error; /** * Destroy a pollset object @@ -98,8 +99,7 @@ * @return Number of signalled descriptors (output parameter) */ public static native int poll(long pollset, long timeout, - long [] descriptors) -throws Error; + long [] descriptors); /** * Return socket from poll descriptor 1.4 +6 -6 jakarta-tomcat-connectors/jni/native/src/network.c Index: network.c === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/network.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- network.c 13 Apr 2005 13:17:42 - 1.3 +++ network.c 14 Apr 2005 06:47:56 - 1.4 @@ -183,7 +183,7 @@ UNREFERENCED(o); apr_socket_opt_get(s, APR_SO_NONBLOCK, nb); if (tosend 0) -nbytes = min(nbytes, (apr_size_t)tosend); +nbytes = min(nbytes - offset, (apr_size_t)tosend); if (nb) bytes = (*e)-GetPrimitiveArrayCritical(e, buf, NULL); else @@ -213,7 +213,7 @@ goto cleanup; } if (len 0) -nbytes = min(nbytes, (apr_size_t)len); +nbytes = min(nbytes - offset, (apr_size_t)len); TCN_THROW_IF_ERR(apr_socket_send(s, bytes + offset, nbytes), nbytes); cleanup: @@ -264,7 +264,7 @@ UNREFERENCED(o); apr_socket_opt_get(s, APR_SO_NONBLOCK, nb); if (tosend 0) -nbytes = min(nbytes, (apr_size_t)tosend); +nbytes = min(nbytes - offset, (apr_size_t)tosend); if (nb) bytes = (*e)-GetPrimitiveArrayCritical(e, buf, NULL); else @@ -288,7 +288,7 @@ UNREFERENCED(o); if (toread 0) -nbytes = min(nbytes, (apr_size_t)toread); +nbytes = min(nbytes - offset, (apr_size_t)toread); TCN_THROW_IF_ERR(apr_socket_recv(s, bytes + offset, nbytes), nbytes); @@ -314,7 +314,7 @@ goto cleanup; } if (len 0) -nbytes = min(nbytes, (apr_size_t)len); +nbytes = min(nbytes - offset, (apr_size_t)len); TCN_THROW_IF_ERR(apr_socket_recv(s, bytes + offset, nbytes), nbytes); @@ -333,7 +333,7 @@ UNREFERENCED(o); if (toread 0) -nbytes = min(nbytes, (apr_size_t)toread); +nbytes = min(nbytes - offset, (apr_size_t)toread); TCN_THROW_IF_ERR(apr_socket_recvfrom(f, s, (apr_int32_t)flags, bytes + offset, nbytes), nbytes); 1.4 +83 -17jakarta-tomcat-connectors/jni/native/src/poll.c Index: poll.c === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/poll.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- poll.c13 Apr 2005 13:17:42 - 1.3 +++ poll.c14 Apr 2005 06:47:56 - 1.4 @@ -18,55 +18,86 @@ #include apr_poll.h #include tcn.h +/* Internal poll structure for queryset + */ + +typedef struct tcn_pollset { +apr_pool_t*pool; +apr_int32_t nelts; +apr_int32_t nalloc; +apr_pollset_t *pollset; +apr_pollfd_t *query_set; +apr_time_t*query_add; +apr_interval_time_t max_ttl; +} tcn_pollset_t; TCN_IMPLEMENT_CALL(jlong, Poll, create)(TCN_STDARGS, jint size, -jlong pool, jint flags) +jlong pool,
cvs commit: jakarta-tomcat-connectors/jni/native/src network.c poll.c
mturk 2005/04/13 06:17:42 Modified:jni/native/src network.c poll.c Log: Add offset for send and receive oprations to skip the need for array copy. Revision ChangesPath 1.3 +54 -8 jakarta-tomcat-connectors/jni/native/src/network.c Index: network.c === RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/network.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- network.c 5 Feb 2005 12:33:09 - 1.2 +++ network.c 13 Apr 2005 13:17:42 - 1.3 @@ -173,7 +173,7 @@ } TCN_IMPLEMENT_CALL(jint, Socket, send)(TCN_STDARGS, jlong sock, - jbyteArray buf, jint tosend) + jbyteArray buf, jint offset, jint tosend) { apr_socket_t *s = J2P(sock, apr_socket_t *); apr_size_t nbytes = (*e)-GetArrayLength(e, buf); @@ -188,7 +188,7 @@ bytes = (*e)-GetPrimitiveArrayCritical(e, buf, NULL); else bytes = (*e)-GetByteArrayElements(e, buf, NULL); -TCN_THROW_IF_ERR(apr_socket_send(s, bytes, nbytes), nbytes); +TCN_THROW_IF_ERR(apr_socket_send(s, bytes + offset, nbytes), nbytes); cleanup: if (nb) @@ -198,6 +198,28 @@ return (jint)nbytes; } +TCN_IMPLEMENT_CALL(jint, Socket, sendb)(TCN_STDARGS, jlong sock, +jobject buf, jint offset, jint len) +{ +apr_socket_t *s = J2P(sock, apr_socket_t *); +apr_size_t nbytes; +char *bytes; + +UNREFERENCED(o); +bytes = (char *)(*e)-GetDirectBufferAddress(e, buf); +nbytes = (apr_size_t)(*e)-GetDirectBufferCapacity(e, buf); +if (bytes == NULL || nbytes 0) { +tcn_ThrowAPRException(e, APR_EGENERAL); +goto cleanup; +} +if (len 0) +nbytes = min(nbytes, (apr_size_t)len); +TCN_THROW_IF_ERR(apr_socket_send(s, bytes + offset, nbytes), nbytes); + +cleanup: +return (jint)nbytes; +} + TCN_IMPLEMENT_CALL(jint, Socket, sendv)(TCN_STDARGS, jlong sock, jobjectArray bufs) { @@ -231,7 +253,7 @@ TCN_IMPLEMENT_CALL(jint, Socket, sendto)(TCN_STDARGS, jlong sock, jlong where, jint flag, - jbyteArray buf, jint tosend) + jbyteArray buf, jint offset, jint tosend) { apr_socket_t *s = J2P(sock, apr_socket_t *); apr_sockaddr_t *w = J2P(where, apr_sockaddr_t *); @@ -247,7 +269,7 @@ bytes = (*e)-GetPrimitiveArrayCritical(e, buf, NULL); else bytes = (*e)-GetByteArrayElements(e, buf, NULL); -TCN_THROW_IF_ERR(apr_socket_sendto(s, w, flag, bytes, nbytes), nbytes); +TCN_THROW_IF_ERR(apr_socket_sendto(s, w, flag, bytes + offset, nbytes), nbytes); cleanup: if (nb) @@ -258,7 +280,7 @@ } TCN_IMPLEMENT_CALL(jint, Socket, recv)(TCN_STDARGS, jlong sock, - jbyteArray buf, jint toread) + jbyteArray buf, jint offset, jint toread) { apr_socket_t *s = J2P(sock, apr_socket_t *); apr_size_t nbytes = (*e)-GetArrayLength(e, buf); @@ -268,7 +290,7 @@ if (toread 0) nbytes = min(nbytes, (apr_size_t)toread); -TCN_THROW_IF_ERR(apr_socket_recv(s, bytes, nbytes), nbytes); +TCN_THROW_IF_ERR(apr_socket_recv(s, bytes + offset, nbytes), nbytes); cleanup: (*e)-ReleaseByteArrayElements(e, buf, bytes, @@ -276,9 +298,33 @@ return (jint)nbytes; } +TCN_IMPLEMENT_CALL(jint, Socket, recvb)(TCN_STDARGS, jlong sock, +jobject buf, jint offset, jint len) +{ +apr_socket_t *s = J2P(sock, apr_socket_t *); + +apr_size_t nbytes; +char *bytes; + +UNREFERENCED(o); +bytes = (char *)(*e)-GetDirectBufferAddress(e, buf); +nbytes = (apr_size_t)(*e)-GetDirectBufferCapacity(e, buf); +if (bytes == NULL || nbytes 0) { +tcn_ThrowAPRException(e, APR_EGENERAL); +goto cleanup; +} +if (len 0) +nbytes = min(nbytes, (apr_size_t)len); + +TCN_THROW_IF_ERR(apr_socket_recv(s, bytes + offset, nbytes), nbytes); + +cleanup: +return (jint)nbytes; +} + TCN_IMPLEMENT_CALL(jint, Socket, recvfrom)(TCN_STDARGS, jlong from, jlong sock, jint flags, - jbyteArray buf, jint toread) + jbyteArray buf, jint offset, jint toread) { apr_socket_t *s = J2P(sock, apr_socket_t *); apr_sockaddr_t *f = J2P(from, apr_sockaddr_t *); @@ -290,7 +336,7 @@ nbytes = min(nbytes,