tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jni/native/src info.c jnilib.c network.c sslnetwork.c
Date Thu, 23 Jun 2005 08:58:05 GMT
mturk       2005/06/23 01:58:05

  Modified:    jni/native/include tcn.h
               jni/native/src info.c jnilib.c network.c sslnetwork.c
  Log:
  Add function wrappers for getting and setting the timeout.
  Also catch the info classes to spped up it's prosessing.
  
  Revision  Changes    Path
  1.26      +5 -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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- tcn.h	18 Jun 2005 16:36:15 -0000	1.25
  +++ tcn.h	23 Jun 2005 08:58:05 -0000	1.26
  @@ -124,6 +124,8 @@
       void         *opaque;
       int          type;
       apr_status_t (*cleanup)(void *);
  +    apr_status_t (APR_THREAD_FUNC *tmset)(apr_socket_t *, apr_interval_time_t);
  +    apr_status_t (APR_THREAD_FUNC *tmget)(apr_socket_t *, apr_interval_time_t *);
       apr_status_t (APR_THREAD_FUNC *send) (apr_socket_t *, const char *, apr_size_t *);
       apr_status_t (APR_THREAD_FUNC *sendv)(apr_socket_t *, const struct iovec *, apr_int32_t,
apr_size_t *);
       apr_status_t (APR_THREAD_FUNC *recv) (apr_socket_t *, char *, apr_size_t *);
  @@ -142,8 +144,8 @@
   char           *tcn_get_string(JNIEnv *, jstring);
   char           *tcn_strdup(JNIEnv *, jstring);
   char           *tcn_pstrdup(JNIEnv *, jstring, apr_pool_t *);
  -apr_status_t    tcn_load_finfo_class(JNIEnv *);
  -apr_status_t    tcn_load_ainfo_class(JNIEnv *);
  +apr_status_t    tcn_load_finfo_class(JNIEnv *, jclass);
  +apr_status_t    tcn_load_ainfo_class(JNIEnv *, jclass);
   
   #define J2S(V)  c##V
   #define J2L(V)  p##V
  
  
  
  1.9       +65 -38    jakarta-tomcat-connectors/jni/native/src/info.c
  
  Index: info.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/info.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- info.c	17 Jun 2005 09:41:30 -0000	1.8
  +++ info.c	23 Jun 2005 08:58:05 -0000	1.9
  @@ -121,17 +121,13 @@
   
   static int finfo_class_initialized = 0;
   static int ainfo_class_initialized = 0;
  +static jmethodID finfo_class_init = NULL;
  +static jmethodID ainfo_class_init = NULL;
  +static jclass finfo_class = NULL;
  +static jclass ainfo_class = NULL;
   
  -apr_status_t tcn_load_finfo_class(JNIEnv *e)
  +apr_status_t tcn_load_finfo_class(JNIEnv *e, jclass finfo)
   {
  -    jclass finfo;
  -
  -    finfo = (*e)->FindClass(e, TCN_FINFO_CLASS);
  -    if (finfo == NULL) {
  -        (*e)->ExceptionClear(e);
  -        return APR_EGENERAL;
  -    }
  -
       GET_FINFO_J(pool);
       GET_FINFO_I(valid);
       GET_FINFO_I(protection);
  @@ -149,33 +145,33 @@
       GET_FINFO_S(fname);
       GET_FINFO_S(name);
       GET_FINFO_J(filehand);
  -
  +    
  +    finfo_class_init = (*e)->GetMethodID(e, finfo,
  +                                      "<init>", "()V");
  +    if (finfo_class_init == NULL)
  +        goto cleanup;
       finfo_class_initialized = 1;
  +    finfo_class = finfo;
   cleanup:
  -    (*e)->DeleteLocalRef(e, finfo);
       return APR_SUCCESS;
   }
   
  -apr_status_t tcn_load_ainfo_class(JNIEnv *e)
  +apr_status_t tcn_load_ainfo_class(JNIEnv *e, jclass ainfo)
   {
  -    jclass ainfo;
  -
  -    ainfo = (*e)->FindClass(e, TCN_AINFO_CLASS);
  -    if (ainfo == NULL) {
  -        (*e)->ExceptionClear(e);
  -        return APR_EGENERAL;
  -    }
  -
       GET_AINFO_J(pool);
       GET_AINFO_S(hostname);
       GET_AINFO_S(servname);
       GET_AINFO_I(port);
       GET_AINFO_I(family);
       GET_AINFO_J(next);
  +    ainfo_class_init = (*e)->GetMethodID(e, ainfo,
  +                                      "<init>", "()V");
   
  +    if (ainfo_class_init == NULL)
  +        goto cleanup;
       ainfo_class_initialized = 1;
  +    ainfo_class = ainfo;
   cleanup:
  -    (*e)->DeleteLocalRef(e, ainfo);
       return APR_SUCCESS;
   }
   
  @@ -233,6 +229,30 @@
       return (jint)rv;
   }
   
  +TCN_IMPLEMENT_CALL(jobject, File, getStat)(TCN_STDARGS, jstring fname,
  +                                           jint wanted, jlong pool)
  +{
  +    apr_pool_t *p = J2P(pool, apr_pool_t *);
  +    TCN_ALLOC_CSTRING(fname);
  +    apr_status_t rv;
  +    apr_finfo_t info;
  +    jobject finfo = NULL;
  +
  +    UNREFERENCED(o);
  +
  +    if ((rv =  apr_stat(&info, J2S(fname), wanted, p)) == APR_SUCCESS) {
  +        finfo = (*e)->NewObject(e, finfo_class, finfo_class_init);
  +        if (finfo == NULL)
  +            goto cleanup;
  +        fill_finfo(e, finfo, &info);
  +    }
  +    else
  +        tcn_ThrowAPRException(e, rv);
  +cleanup:
  +    TCN_FREE_CSTRING(fname);
  +    return finfo;
  +}
  +
   TCN_IMPLEMENT_CALL(jint, File, infoGet)(TCN_STDARGS, jobject finfo,
                                           jint wanted, jlong file)
   {
  @@ -250,6 +270,27 @@
       return (jint)rv;
   }
   
  +TCN_IMPLEMENT_CALL(jobject, File, getInfo)(TCN_STDARGS, jint wanted, jlong file)
  +{
  +    apr_file_t *f = J2P(file, apr_file_t *);
  +    apr_status_t rv;
  +    apr_finfo_t  info;
  +
  +    UNREFERENCED(o);
  +
  +    if ((rv =  apr_file_info_get(&info, wanted, f)) == APR_SUCCESS) {
  +        jobject finfo;
  +        finfo = (*e)->NewObject(e, finfo_class, finfo_class_init);
  +        if (finfo == NULL)
  +            return NULL;
  +        fill_finfo(e, finfo, &info);
  +        return finfo;
  +    }
  +    else
  +        tcn_ThrowAPRException(e, rv);
  +    return NULL;
  +}
  +
   TCN_IMPLEMENT_CALL(jint, Directory, read)(TCN_STDARGS, jobject finfo,
                                             jint wanted, jlong dir)
   {
  @@ -297,28 +338,14 @@
   TCN_IMPLEMENT_CALL(jobject, Address, getInfo)(TCN_STDARGS, jlong info)
   {
       apr_sockaddr_t *i = J2P(info, apr_sockaddr_t *);
  -    jclass aprSockaddrClass;
  -    jmethodID constructorID = 0;
       jobject sockaddrObj = NULL;
   
       UNREFERENCED(o);
   
  -    aprSockaddrClass = (*e)->FindClass(e, TCN_AINFO_CLASS);
  -    if (aprSockaddrClass == NULL)
  -        return NULL;
  -
  -    /* Find the constructor ID */
  -    constructorID = (*e)->GetMethodID(e, aprSockaddrClass,
  -                                      "<init>", "()V");
  -    if (constructorID == NULL)
  -        goto cleanup;
       /* Create the APR Error object */
  -    sockaddrObj = (*e)->NewObject(e, aprSockaddrClass, constructorID);
  +    sockaddrObj = (*e)->NewObject(e, ainfo_class, ainfo_class_init);
       if (sockaddrObj == NULL)
  -        goto cleanup;
  +        return NULL;
       fill_ainfo(e, sockaddrObj, i);
  -cleanup:
  -    (*e)->DeleteLocalRef(e, aprSockaddrClass);
  -
       return sockaddrObj;
   }
  
  
  
  1.12      +9 -3      jakarta-tomcat-connectors/jni/native/src/jnilib.c
  
  Index: jnilib.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/jnilib.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- jnilib.c	17 Jun 2005 09:41:30 -0000	1.11
  +++ jnilib.c	23 Jun 2005 08:58:05 -0000	1.12
  @@ -37,6 +37,8 @@
   static JavaVM     *tcn_global_vm = NULL;
   
   static jclass    jString_class;
  +static jclass    jFinfo_class;
  +static jclass    jAinfo_class;
   static jmethodID jString_init;
   static jmethodID jString_getBytes;
   
  @@ -53,15 +55,17 @@
   
       /* Initialize global java.lang.String class */
       TCN_LOAD_CLASS(env, jString_class, "java/lang/String", JNI_ERR);
  +    TCN_LOAD_CLASS(env, jFinfo_class, TCN_FINFO_CLASS, JNI_ERR);
  +    TCN_LOAD_CLASS(env, jAinfo_class, TCN_AINFO_CLASS, JNI_ERR);
   
       TCN_GET_METHOD(env, jString_class, jString_init,
                      "<init>", "([B)V", JNI_ERR);
       TCN_GET_METHOD(env, jString_class, jString_getBytes,
                      "getBytes", "()[B", JNI_ERR);
   
  -    if(tcn_load_finfo_class(env) != APR_SUCCESS)
  +    if(tcn_load_finfo_class(env, jFinfo_class) != APR_SUCCESS)
           return JNI_ERR;
  -    if(tcn_load_ainfo_class(env) != APR_SUCCESS)
  +    if(tcn_load_ainfo_class(env, jAinfo_class) != APR_SUCCESS)
           return JNI_ERR;
   
       apr_initialize();
  @@ -81,6 +85,8 @@
           return;
       }
       TCN_UNLOAD_CLASS(env, jString_class);
  +    TCN_UNLOAD_CLASS(env, jFinfo_class);
  +    TCN_UNLOAD_CLASS(env, jAinfo_class);
       apr_terminate();
   }
   
  
  
  
  1.38      +66 -33    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.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- network.c	18 Jun 2005 16:36:15 -0000	1.37
  +++ network.c	23 Jun 2005 08:58:05 -0000	1.38
  @@ -209,11 +209,25 @@
       return apr_socket_shutdown(sock, how);
   }
   
  +static APR_INLINE apr_status_t APR_THREAD_FUNC
  +APR_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
  +{
  +    return apr_socket_timeout_set(sock, t);
  +}
  +
  +static APR_INLINE apr_status_t APR_THREAD_FUNC
  +APR_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
  +{
  +    return apr_socket_timeout_get(sock, t);
  +}
  +
   #else
  -#define APR_socket_send      apr_socket_send
  -#define APR_socket_recv      apr_socket_recv
  -#define APR_socket_sendv     apr_socket_sendv
  -#define APR_socket_shutdown  apr_socket_shutdown
  +#define APR_socket_send         apr_socket_send
  +#define APR_socket_recv         apr_socket_recv
  +#define APR_socket_sendv        apr_socket_sendv
  +#define APR_socket_shutdown     apr_socket_shutdown
  +#define APR_socket_timeout_set  apr_socket_timeout_set
  +#define APR_socket_timeout_get  apr_socket_timeout_get
   #endif
   
   TCN_IMPLEMENT_CALL(jlong, Socket, create)(TCN_STDARGS, jint family,
  @@ -246,6 +260,8 @@
           a->send     = APR_socket_send;
           a->sendv    = APR_socket_sendv;
           a->shutdown = APR_socket_shutdown;
  +        a->tmget    = APR_socket_timeout_get;
  +        a->tmset    = APR_socket_timeout_set;
           a->close    = NULL;
       }
       a->opaque   = s;
  @@ -295,7 +311,7 @@
               return P2J(s->sock);
           break;
           case TCN_SOCKET_GET_TYPE:
  -            return P2J(s->type);
  +            return (jlong)(s->type);
           break;
       }
       return 0;
  @@ -363,10 +379,15 @@
   
       UNREFERENCED(o);
       TCN_ASSERT(sock != 0);
  -    TCN_ASSERT(s->sock != NULL);
  -
  -    TCN_THROW_IF_ERR(apr_socket_accept(&n, s->sock, p), n);
   
  +    if (s->type == TCN_SOCKET_APR) {
  +        TCN_ASSERT(s->sock != NULL);
  +        TCN_THROW_IF_ERR(apr_socket_accept(&n, s->sock, p), n);
  +    }
  +    else {
  +        tcn_ThrowAPRException(e, APR_ENOTIMPL);
  +        goto cleanup;
  +    }
       if (n) {
   #ifdef TCN_DO_STATISTICS
           apr_atomic_inc32(&sp_accepted);
  @@ -379,6 +400,8 @@
           a->send     = APR_socket_send;
           a->sendv    = APR_socket_sendv;
           a->shutdown = APR_socket_shutdown;
  +        a->tmget    = APR_socket_timeout_get;
  +        a->tmset    = APR_socket_timeout_set;
           a->close    = NULL;
           a->opaque   = n;
           apr_pool_cleanup_register(p, (const void *)a,
  @@ -399,11 +422,16 @@
   
       UNREFERENCED(o);
       TCN_ASSERT(sock != 0);
  -    TCN_ASSERT(s->sock != NULL);
   
       TCN_THROW_IF_ERR(apr_pool_create(&p, s->pool), p);
  -    TCN_THROW_IF_ERR(apr_socket_accept(&n, s->sock, p), n);
  -
  +    if (s->type == TCN_SOCKET_APR) {
  +        TCN_ASSERT(s->sock != NULL);
  +        TCN_THROW_IF_ERR(apr_socket_accept(&n, s->sock, p), n);
  +    }
  +    else {
  +        tcn_ThrowAPRException(e, APR_ENOTIMPL);
  +        goto cleanup;
  +    }
       if (n) {
   #ifdef TCN_DO_STATISTICS
           apr_atomic_inc32(&sp_accepted);
  @@ -422,11 +450,11 @@
                                     sp_socket_cleanup,
                                     apr_pool_cleanup_null);
       }
  -    else if (p)
  -        apr_pool_destroy(p);
  -
  -cleanup:
       return P2J(a);
  +cleanup:
  +    if (p)
  +        apr_pool_destroy(p);
  +    return 0;
   }
   
   TCN_IMPLEMENT_CALL(jint, Socket, connect)(TCN_STDARGS, jlong sock,
  @@ -649,12 +677,12 @@
   
       UNREFERENCED(o);
       TCN_ASSERT(sock != 0);
  -    TCN_ASSERT(s->sock != NULL);
  +    TCN_ASSERT(s->opaque != NULL);
       TCN_ASSERT(buf != NULL);
   
  -    if ((ss = apr_socket_timeout_get(s->sock, &t)) != APR_SUCCESS)
  +    if ((ss = (*s->tmget)(s->opaque, &t)) != APR_SUCCESS)
           goto cleanup;
  -    if ((ss = apr_socket_timeout_set(s->sock, J2T(timeout))) != APR_SUCCESS)
  +    if ((ss = (*s->tmset)(s->opaque, J2T(timeout))) != APR_SUCCESS)
           goto cleanup;
       if (toread <= TCN_BUFFER_SZ) {
           char sb[TCN_BUFFER_SZ];
  @@ -668,7 +696,7 @@
                                          nbytes ? 0 : JNI_ABORT);
       }
       /* Resore the original timeout */
  -    apr_socket_timeout_set(s->sock, t);
  +    (*s->tmset)(s->opaque, t);
   #ifdef TCN_DO_STATISTICS
       if (ss == APR_SUCCESS) {
           sp_max_recv = TCN_MAX(sp_max_recv, nbytes);
  @@ -761,13 +789,13 @@
       bytes  = (char *)(*e)->GetDirectBufferAddress(e, buf);
       TCN_ASSERT(bytes != NULL);
   
  -    if ((ss = apr_socket_timeout_get(s->sock, &t)) != APR_SUCCESS)
  +    if ((ss = (*s->tmget)(s->opaque, &t)) != APR_SUCCESS)
            return -(jint)ss;
  -    if ((ss = apr_socket_timeout_set(s->sock, J2T(timeout))) != APR_SUCCESS)
  +    if ((ss = (*s->tmset)(s->opaque, J2T(timeout))) != APR_SUCCESS)
            return -(jint)ss;
       ss = (*s->recv)(s->opaque, bytes + offset, &nbytes);
       /* Resore the original timeout */
  -    apr_socket_timeout_set(s->sock, t);
  +    (*s->tmset)(s->opaque, t);
   #ifdef TCN_DO_STATISTICS
       if (ss == APR_SUCCESS) {
           sp_max_recv = TCN_MAX(sp_max_recv, nbytes);
  @@ -830,20 +858,26 @@
   
       UNREFERENCED_STDARGS;
       TCN_ASSERT(sock != 0);
  -    return (jint)apr_socket_opt_set(s->sock, (apr_int32_t)opt, (apr_int32_t)on);
  +    if (!s->sock)
  +        return APR_EINVAL;
  +    else
  +        return (jint)apr_socket_opt_set(s->sock, (apr_int32_t)opt, (apr_int32_t)on);
   }
   
   TCN_IMPLEMENT_CALL(jint, Socket, optGet)(TCN_STDARGS, jlong sock,
                                            jint opt)
   {
       tcn_socket_t *s = J2P(sock, tcn_socket_t *);
  -    apr_int32_t on;
  +    apr_int32_t on = 0;
   
       UNREFERENCED(o);
       TCN_ASSERT(sock != 0);
  -    TCN_ASSERT(s->sock != NULL);
  -    TCN_THROW_IF_ERR(apr_socket_opt_get(s->sock, (apr_int32_t)opt,
  -                                        &on), on);
  +    if (s->sock)
  +        tcn_ThrowAPRException(e, APR_EINVAL);
  +    else {
  +        TCN_THROW_IF_ERR(apr_socket_opt_get(s->sock, (apr_int32_t)opt,
  +                                            &on), on);
  +    }
   cleanup:
       return (jint)on;
   }
  @@ -855,8 +889,8 @@
   
       UNREFERENCED_STDARGS;
       TCN_ASSERT(sock != 0);
  -    TCN_ASSERT(s->sock != NULL);
  -    return (jint)apr_socket_timeout_set(s->sock, J2T(timeout));
  +    TCN_ASSERT(s->opaque != NULL);
  +    return (jint)(*s->tmset)(s->opaque, J2T(timeout));
   }
   
   TCN_IMPLEMENT_CALL(jlong, Socket, timeoutGet)(TCN_STDARGS, jlong sock)
  @@ -866,9 +900,8 @@
   
       UNREFERENCED(o);
       TCN_ASSERT(sock != 0);
  -    TCN_ASSERT(s->sock != NULL);
  -    TCN_THROW_IF_ERR(apr_socket_timeout_get(s->sock, &timeout), timeout);
  -
  +    TCN_ASSERT(s->opaque != NULL);
  +    TCN_THROW_IF_ERR((*s->tmget)(s->sock, &timeout), timeout);
   cleanup:
       return (jlong)timeout;
   }
  
  
  
  1.18      +17 -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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- sslnetwork.c	18 Jun 2005 14:03:09 -0000	1.17
  +++ sslnetwork.c	23 Jun 2005 08:58:05 -0000	1.18
  @@ -206,6 +206,20 @@
   }
   
   static apr_status_t APR_THREAD_FUNC
  +ssl_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
  +{
  +    tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
  +    return apr_socket_timeout_set(con->sock, t);
  +}
  +
  +static apr_status_t APR_THREAD_FUNC
  +ssl_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
  +{
  +    tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
  +    return apr_socket_timeout_get(con->sock, t);
  +}
  +
  +static apr_status_t APR_THREAD_FUNC
   ssl_socket_shutdown(apr_socket_t *sock, apr_shutdown_how_e how)
   {
       apr_status_t rv = APR_SUCCESS;
  @@ -453,6 +467,8 @@
       s->send     = ssl_socket_send;
       s->sendv    = ssl_socket_sendv;
       s->shutdown = ssl_socket_shutdown;
  +    s->tmget    = ssl_socket_timeout_get;
  +    s->tmset    = ssl_socket_timeout_set;
       s->close    = ssl_socket_close;
       s->opaque   = con;
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message