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 network.c pool.c
Date Sat, 28 May 2005 07:48:29 GMT
mturk       2005/05/28 00:48:29

  Modified:    jni/java/org/apache/tomcat/jni Pool.java
               jni/native/src network.c pool.c
  Log:
  Add missing userdata functions for Pool.
  Those will be used for SSL socket abstraction.
  
  Revision  Changes    Path
  1.5       +32 -1     jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Pool.java
  
  Index: Pool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/Pool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Pool.java	5 Feb 2005 12:31:35 -0000	1.4
  +++ Pool.java	28 May 2005 07:48:28 -0000	1.5
  @@ -129,4 +129,35 @@
        */
       public static native ByteBuffer calloc(long p, int size);
   
  +    /*
  +     * User data management
  +     */
  +
  +    /**
  +     * Set the data associated with the current pool
  +     * @param data The user data associated with the pool.
  +     * @param key The key to use for association
  +     * @param pool The current pool
  +     * @warning The data to be attached to the pool should have a life span
  +     *          at least as long as the pool it is being attached to.
  +     *          Object attached to the pool will be globaly referenced
  +     *          untill the pool is cleared or dataSet is called with the
  +     *          null data.
  +     * @return APR Status code.
  +     */
  +     public static native int dataSet(long pool, String key, Object data);
  +
  +    /**
  +     * Return the data associated with the current pool.
  +     * @param key The key for the data to retrieve
  +     * @param pool The current pool.
  +     */
  +     public static native Object dataGet(long pool, String key);
  +
  +    /**
  +     * Run all of the child_cleanups, so that any unnecessary files are
  +     * closed because we are about to exec a new program
  +     */
  +    public static native void cleanupForExec();
  +
   }
  
  
  
  1.22      +9 -2      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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- network.c	27 May 2005 16:39:13 -0000	1.21
  +++ network.c	28 May 2005 07:48:29 -0000	1.22
  @@ -30,6 +30,13 @@
   static int sp_closed   = 0;
   static int sp_cleared  = 0;
   static int sp_accepted = 0;
  +/* Fake private pool struct to deal with APR private's socket
  + * struct not exposing function to access the pool.
  + */
  +typedef struct
  +{
  +    apr_pool_t *pool;
  +} fake_apr_socket_t;
   #endif
   
   #if  !APR_HAVE_IPV6
  @@ -195,7 +202,7 @@
   
   #ifdef TCN_DO_STATISTICS
       sp_closed++;
  -    apr_pool_cleanup_kill((apr_pool_t *)s, s, sp_socket_cleanup);
  +    apr_pool_cleanup_kill(((fake_apr_socket_t *)s)->pool, s, sp_socket_cleanup);
   #endif
   
       return (jint)apr_socket_close(s);
  
  
  
  1.6       +78 -1     jakarta-tomcat-connectors/jni/native/src/pool.c
  
  Index: pool.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/pool.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- pool.c	27 May 2005 16:38:09 -0000	1.5
  +++ pool.c	28 May 2005 07:48:29 -0000	1.6
  @@ -133,6 +133,7 @@
       tcn_callback_t *cb = J2P(data, tcn_callback_t *);
   
       UNREFERENCED(o);
  +    TCN_ASSERT(pool != 0);
       apr_pool_cleanup_kill(p, cb, generic_pool_cleanup);
       (*e)->DeleteGlobalRef(e, cb->obj);
       free(cb);
  @@ -146,6 +147,7 @@
       void *mem;
   
       UNREFERENCED(o);
  +    TCN_ASSERT(pool != 0);
   
       if ((mem = apr_palloc(p, sz)) != NULL)
           return (*e)->NewDirectByteBuffer(e, mem, (jlong)sz);
  @@ -161,9 +163,84 @@
       void *mem;
   
       UNREFERENCED(o);
  +    TCN_ASSERT(pool != 0);
   
       if ((mem = apr_pcalloc(p, sz)) != NULL)
           return (*e)->NewDirectByteBuffer(e, mem, (jlong)sz);
       else
           return NULL;
   }
  +
  +static apr_status_t generic_pool_data_cleanup(void *data)
  +{
  +    apr_status_t rv = APR_SUCCESS;
  +    tcn_callback_t *cb = (tcn_callback_t *)data;
  +
  +    if (data) {
  +        if (!TCN_IS_NULL(cb->env, cb->obj)) {
  +            TCN_UNLOAD_CLASS(cb->env, cb->obj);
  +        }
  +        free(cb);
  +    }
  +    return rv;
  +}
  +
  +TCN_IMPLEMENT_CALL(jint, Pool, dataSet)(TCN_STDARGS, jlong pool,
  +                                        jstring key, jobject data)
  +{
  +    apr_pool_t *p = J2P(pool, apr_pool_t *);
  +    apr_status_t rv = APR_SUCCESS;
  +    void *old = NULL;
  +    TCN_ALLOC_CSTRING(key);
  +
  +    UNREFERENCED(o);
  +    TCN_ASSERT(pool != 0);
  +
  +    if (apr_pool_userdata_get(&old, J2S(key), p) == APR_SUCCESS) {
  +        if (old)
  +            apr_pool_cleanup_run(p, old, generic_pool_data_cleanup);
  +    }
  +    if (data) {
  +        tcn_callback_t *cb = (tcn_callback_t *)malloc(sizeof(tcn_callback_t));
  +        cb->env = e;
  +        cb->obj = (*e)->NewGlobalRef(e, data);
  +        if ((rv = apr_pool_userdata_set(cb, J2S(key), generic_pool_data_cleanup,
  +                                        p)) != APR_SUCCESS) {
  +            (*e)->DeleteGlobalRef(e, cb->obj);
  +            free(cb);
  +        }
  +    }
  +    else {
  +        /* Clear the exiting user data */
  +        rv = apr_pool_userdata_set(NULL, J2S(key), NULL, p);
  +    }
  +    TCN_FREE_CSTRING(key);
  +    return rv;
  +}
  +
  +TCN_IMPLEMENT_CALL(jobject, Pool, dataGet)(TCN_STDARGS, jlong pool,
  +                                           jstring key)
  +{
  +    apr_pool_t *p = J2P(pool, apr_pool_t *);
  +    void *old = NULL;
  +    TCN_ALLOC_CSTRING(key);
  +    jobject rv = NULL;
  +
  +    UNREFERENCED(o);
  +    TCN_ASSERT(pool != 0);
  +
  +    if (apr_pool_userdata_get(&old, J2S(key), p) == APR_SUCCESS) {
  +        if (old) {
  +            tcn_callback_t *cb = (tcn_callback_t *)old;
  +            rv = cb->obj;
  +        }
  +    }
  +    TCN_FREE_CSTRING(key);
  +    return rv;
  +}
  +
  +TCN_IMPLEMENT_CALL(void, Pool, cleanupForExec)(TCN_STDARGS)
  +{
  +    UNREFERENCED_STDARGS;
  +    apr_pool_cleanup_for_exec();;
  +}
  
  
  

---------------------------------------------------------------------
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