mturk 2005/06/13 00:31:11 Modified: jni/java/org/apache/tomcat/jni SSLSocket.java jni/native/src sslnetwork.c Log: Copy/paste the rest of the recv*/send* methods from APR sockets. Revision Changes Path 1.7 +134 -1 jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/SSLSocket.java Index: SSLSocket.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/SSLSocket.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SSLSocket.java 12 Jun 2005 10:31:16 -0000 1.6 +++ SSLSocket.java 13 Jun 2005 07:31:11 -0000 1.7 @@ -89,6 +89,68 @@ public static native int send(long sock, byte[] buf, int offset, int len); /** + * Send data over a network. + * <PRE> + * This functions acts like a blocking write by default. To change + * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK + * socket option. + * + * It is possible for both bytes to be sent and an error to be returned. + * + * APR_EINTR is never returned. + * </PRE> + * @param sock The socket to send the data over. + * @param buf The buffer which contains the data to be sent. + * @param offset Offset in the byte buffer. + * @param len The number of bytes to write; (-1) for full array. + * @return The number of bytes send. + * + */ + public static native int send(long sock, byte[] buf, int offset, int len); + + /** + * Send data over a network. + * <PRE> + * This functions acts like a blocking write by default. To change + * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK + * socket option. + * + * It is possible for both bytes to be sent and an error to be returned. + * + * APR_EINTR is never returned. + * </PRE> + * @param sock The socket to send the data over. + * @param buf The Byte buffer which contains the data to be sent. + * @param offset The offset within the buffer array of the first buffer from + * which bytes are to be retrieved; must be non-negative + * and no larger than buf.length + * @param len The maximum number of buffers to be accessed; must be non-negative + * and no larger than buf.length - offset + * @return The number of bytes send. + * + */ + public static native int sendb(long sock, ByteBuffer buf, + int offset, int len); + + /** + * Send multiple packets of data over a network. + * <PRE> + * This functions acts like a blocking write by default. To change + * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK + * socket option. + * The number of bytes actually sent is stored in argument 3. + * + * It is possible for both bytes to be sent and an error to be returned. + * + * APR_EINTR is never returned. + * </PRE> + * @param sock The socket to send the data over. + * @param vec The array from which to get the data to send. + * + */ + public static native int sendv(long sock, byte[][] vec); + + /** * Read data from a network. * * <PRE> @@ -110,4 +172,75 @@ */ public static native int recv(long sock, byte[] buf, int offset, int nbytes); + /** + * Read data from a network with timeout. + * + * <PRE> + * This functions acts like a blocking read by default. To change + * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK + * socket option. + * The number of bytes actually received is stored in argument 3. + * + * It is possible for both bytes to be received and an APR_EOF or + * other error to be returned. + * + * APR_EINTR is never returned. + * </PRE> + * @param sock The socket to read the data from. + * @param buf The buffer to store the data in. + * @param offset Offset in the byte buffer. + * @param nbytes The number of bytes to read (-1) for full array. + * @param timeout The socket timeout in microseconds. + * @return the number of bytes received. + */ + public static native int recvt(long sock, byte[] buf, int offset, + int nbytes, long timeout); + + /** + * Read data from a network. + * + * <PRE> + * This functions acts like a blocking read by default. To change + * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK + * socket option. + * The number of bytes actually received is stored in argument 3. + * + * It is possible for both bytes to be received and an APR_EOF or + * other error to be returned. + * + * APR_EINTR is never returned. + * </PRE> + * @param sock The socket to read the data from. + * @param buf The buffer to store the data in. + * @param offset Offset in the byte buffer. + * @param nbytes The number of bytes to read (-1) for full array. + * @return the number of bytes received. + */ + public static native int recvb(long sock, ByteBuffer buf, + int offset, int nbytes); + + /** + * Read data from a network with timeout. + * + * <PRE> + * This functions acts like a blocking read by default. To change + * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK + * socket option. + * The number of bytes actually received is stored in argument 3. + * + * It is possible for both bytes to be received and an APR_EOF or + * other error to be returned. + * + * APR_EINTR is never returned. + * </PRE> + * @param sock The socket to read the data from. + * @param buf The buffer to store the data in. + * @param offset Offset in the byte buffer. + * @param nbytes The number of bytes to read (-1) for full array. + * @param timeout The socket timeout in microseconds. + * @return the number of bytes received. + */ + public static native int recvbt(long sock, ByteBuffer buf, + int offset, int nbytes, long timeout); + } 1.10 +149 -1 jakarta-tomcat-connectors/jni/native/src/sslnetwork.c Index: sslnetwork.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/sslnetwork.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- sslnetwork.c 12 Jun 2005 10:31:17 -0000 1.9 +++ sslnetwork.c 13 Jun 2005 07:31:11 -0000 1.10 @@ -600,6 +600,66 @@ } } +TCN_IMPLEMENT_CALL(jint, SSLSocket, sendv)(TCN_STDARGS, jlong sock, + jobjectArray bufs) +{ + tcn_ssl_conn_t *s = J2P(sock, tcn_ssl_conn_t *); + jsize nvec = (*e)->GetArrayLength(e, bufs); + jsize i; + jobject ba; + apr_size_t written = 0; + apr_status_t ss; + + UNREFERENCED(o); + TCN_ASSERT(sock != 0); + + if (nvec >= APR_MAX_IOVEC_SIZE) + return (jint)(-APR_ENOMEM); + for (i = 0; i < nvec; i++) { + apr_size_t len; + jbyte *buf; + ba = (*e)->GetObjectArrayElement(e, bufs, i); + len = (*e)->GetArrayLength(e, ba); + buf = (*e)->GetByteArrayElements(e, ba, NULL); + ss = ssl_socket_send(s, buf, &len); + (*e)->ReleaseByteArrayElements(e, ba, buf, JNI_ABORT); + if (ss == APR_SUCCESS) + written += len; + else + break; + } + + if (ss == APR_SUCCESS) + return (jint)written; + else { + TCN_ERROR_WRAP(ss); + return -(jint)ss; + } +} + +TCN_IMPLEMENT_CALL(jint, SSLSocket, sendb)(TCN_STDARGS, jlong sock, + jobject buf, jint offset, jint len) +{ + tcn_ssl_conn_t *s = J2P(sock, tcn_ssl_conn_t *); + apr_size_t nbytes = (apr_size_t)len; + char *bytes; + apr_status_t ss; + + UNREFERENCED(o); + TCN_ASSERT(sock != 0); + TCN_ASSERT(buf != NULL); + bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); + ss = ssl_socket_send(s, bytes + offset, &nbytes); + + if (ss == APR_SUCCESS) + return (jint)nbytes; + else { + TCN_ERROR_WRAP(ss); + return -(jint)ss; + } +} + + TCN_IMPLEMENT_CALL(jint, SSLSocket, recv)(TCN_STDARGS, jlong sock, jbyteArray buf, jint offset, jint toread) @@ -624,6 +684,94 @@ } } +TCN_IMPLEMENT_CALL(jint, SSLSocket, recvt)(TCN_STDARGS, jlong sock, + jbyteArray buf, jint offset, + jint toread, jlong timeout) +{ + tcn_ssl_conn_t *s = J2P(sock, tcn_ssl_conn_t *); + apr_size_t nbytes = (apr_size_t)toread; + jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL); + apr_status_t ss; + apr_interval_time_t t; + + UNREFERENCED(o); + TCN_ASSERT(sock != 0); + TCN_ASSERT(buf != NULL); + TCN_ASSERT(bytes != NULL); + + if ((ss = apr_socket_timeout_get(s->sock, &t)) != APR_SUCCESS) + goto cleanup; + if ((ss = apr_socket_timeout_set(s->sock, J2T(timeout))) != APR_SUCCESS) + goto cleanup; + ss = ssl_socket_recv(s, bytes + offset, &nbytes); + /* Resore the original timeout */ + apr_socket_timeout_set(s->sock, t); +cleanup: + (*e)->ReleaseByteArrayElements(e, buf, bytes, + nbytes ? 0 : JNI_ABORT); + if (ss == APR_SUCCESS) + return (jint)nbytes; + else { + TCN_ERROR_WRAP(ss); + return -(jint)ss; + } +} + +TCN_IMPLEMENT_CALL(jint, SSLSocket, recvb)(TCN_STDARGS, jlong sock, + jobject buf, jint offset, jint len) +{ + tcn_ssl_conn_t *s = J2P(sock, tcn_ssl_conn_t *); + apr_status_t ss; + apr_size_t nbytes = (apr_size_t)len; + char *bytes; + + UNREFERENCED(o); + TCN_ASSERT(sock != 0); + TCN_ASSERT(buf != NULL); + bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); + TCN_ASSERT(bytes != NULL); + ss = ssl_socket_recv(s, bytes + offset, &nbytes); + + if (ss == APR_SUCCESS) + return (jint)nbytes; + else { + TCN_ERROR_WRAP(ss); + return -(jint)ss; + } +} + +TCN_IMPLEMENT_CALL(jint, SSLSocket, recvbt)(TCN_STDARGS, jlong sock, + jobject buf, jint offset, + jint len, jlong timeout) +{ + tcn_ssl_conn_t *s = J2P(sock, tcn_ssl_conn_t *); + apr_status_t ss; + apr_size_t nbytes = (apr_size_t)len; + char *bytes; + apr_interval_time_t t; + + UNREFERENCED(o); + TCN_ASSERT(sock != 0); + TCN_ASSERT(buf != NULL); + bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); + TCN_ASSERT(bytes != NULL); + + if ((ss = apr_socket_timeout_get(s->sock, &t)) != APR_SUCCESS) + return -(jint)ss; + if ((ss = apr_socket_timeout_set(s->sock, J2T(timeout))) != APR_SUCCESS) + return -(jint)ss; + ss = ssl_socket_recv(s, bytes + offset, &nbytes); + /* Resore the original timeout */ + apr_socket_timeout_set(s->sock, t); + + if (ss == APR_SUCCESS) + return (jint)nbytes; + else { + TCN_ERROR_WRAP(ss); + return -(jint)ss; + } +} + #else /* OpenSSL is not supported * If someday we make OpenSSL optional
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]