tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native2/jni jk_jni_aprImpl.c org_apache_jk_apr_AprImpl.h
Date Sun, 26 May 2002 07:38:17 GMT
costin      02/05/26 00:38:17

  Modified:    jk/native2/jni jk_jni_aprImpl.c org_apache_jk_apr_AprImpl.h
  Log:
  - removed code we don't need. ( creating and using directly the apr pools
  is overkill and dangerous, things are better handled by keeping them
  in the execution context - jk_endpoint ).
  
  - started to add the signal callbacks ( using the code in the jni channel ).
  The jni channel is not used only for in-process apache-tomcat communication,
  but for any callbacks from C to java ( i.e. you can have tomcat standalone
  using libjkjni.so to receive SIGHUP or any other callbacks we want ).
  
  - add jkInit/jkDestroy ( for component initialization )
  
  Revision  Changes    Path
  1.24      +114 -65   jakarta-tomcat-connectors/jk/native2/jni/jk_jni_aprImpl.c
  
  Index: jk_jni_aprImpl.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/jni/jk_jni_aprImpl.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- jk_jni_aprImpl.c	24 May 2002 04:30:07 -0000	1.23
  +++ jk_jni_aprImpl.c	26 May 2002 07:38:17 -0000	1.24
  @@ -91,7 +91,9 @@
   #include "apr_shm.h"
   #endif
   
  +#ifdef HAVE_SIGNAL
   #include "signal.h"
  +#endif
   
   static apr_pool_t *jniAprPool;
   static jk_workerEnv_t *workerEnv;
  @@ -152,55 +154,86 @@
       return 0;
   }
   
  -JNIEXPORT jlong JNICALL 
  -Java_org_apache_jk_apr_AprImpl_poolCreate(JNIEnv *jniEnv, jobject _jthis, jlong parentP)
  -{
  -    apr_pool_t *parent;
  -    apr_pool_t *child;
  -
  -    parent=(apr_pool_t *)(void *)(long)parentP;
  -    apr_pool_create( &child, parent );
  -    return (jlong)(long)child;
  -}
  -
  -JNIEXPORT jlong JNICALL 
  -Java_org_apache_jk_apr_AprImpl_poolClear(JNIEnv *jniEnv, jobject _jthis,
  -                                         jlong poolP)
  -{
  -    apr_pool_t *pool;
  -
  -    pool=(apr_pool_t *)(void *)(long)poolP;
  -    apr_pool_clear( pool );
  -    return 0;
  -}
  -
   /* -------------------- Signals -------------------- */
  +
   #ifdef HAVE_SIGNALS
   static struct sigaction jkAction;
   
  +/* We use a jni channel to send the notification to java
  + */
  +static jk_channel_t *jniChannel;
  +
  +/* XXX we should sync or use multiple endpoints if multiple signals
  +   can be concurent
  +*/
  +static jk_endpoint_t *signalEndpoint;
  +
   static void jk2_SigAction(int sig) {
  -    fprintf(stderr, "Signal %d\n", sig );
  +    jk_env_t *env;
       
       /* Make a callback using the jni channel */
  +    fprintf(stderr, "Signal %d\n", sig );
  +
  +    if( jk_env_globalEnv == NULL ) {
  +        return;
  +    }
  +
  +    env=jk_env_globalEnv->getEnv( jk_env_globalEnv );
  +
  +    if( jniChannel==NULL ) {
  +        jniChannel=env->getByName( env, "channel.jni:jni" );
  +        fprintf(stderr, "Got jniChannel %p\n", jniChannel );
  +    }
  +    if( jniChannel==NULL ) {
  +        return;
  +    }
  +    if( signalEndpoint == NULL ) {
  +        jk_bean_t *component=env->createBean2( env, NULL, "endpoint", NULL );
  +        if( component == NULL ) {
  +            fprintf(stderr, "Can't create endpoint\n" );
  +            return;
  +        }
  +        component->init( env, component );
  +        fprintf(stderr, "Create endpoint %p\n", component->object );
  +        signalEndpoint=component->object;
  +    }
  +
  +    /* Channel:jni should be initialized by the caller */
  +
  +    /* XXX make the callback */
       
  -    signal( sig, jk2_SigAction );
  +    jk_env_globalEnv->releaseEnv( jk_env_globalEnv, env );
  +
   }
  -#endif
  +
   
   /* XXX We need to: - preserve the old signal ( or get them ) - either
        implement "waitSignal" or use invocation in jk2_SigAction
   
        Probably waitSignal() is better ( we can have a thread that waits )
  -*/
  + */
   
   JNIEXPORT jint JNICALL 
   Java_org_apache_jk_apr_AprImpl_signal(JNIEnv *jniEnv, jobject _jthis, jint signalNr )
   {
  -#ifdef HAVE_SIGNALS
       memset(& jkAction, 0, sizeof(jkAction));
       jkAction.sa_handler=jk2_SigAction;
       sigaction((int)signalNr, &jkAction, (void *) NULL);
  -#endif
  +    return 0;
  +}
  +
  +JNIEXPORT jint JNICALL 
  +Java_org_apache_jk_apr_AprImpl_sendSignal(JNIEnv *jniEnv, jobject _jthis, jint target ,
  +                                          jint signo)
  +{
  +    return kill( (pid_t)target, (int)signo );
  +}
  +
  +#else /* ! HAVE_SIGNALS */
  +
  +JNIEXPORT jint JNICALL 
  +Java_org_apache_jk_apr_AprImpl_signal(JNIEnv *jniEnv, jobject _jthis, jint signalNr )
  +{
       return 0;
   }
   
  @@ -208,10 +241,12 @@
   Java_org_apache_jk_apr_AprImpl_sendSignal(JNIEnv *jniEnv, jobject _jthis, jint signo,
                                             jlong target)
   {
  -    
       return 0;
   }
   
  +#endif
  +
  +
   /* -------------------- User related functions -------------------- */
   
   JNIEXPORT jint JNICALL 
  @@ -262,10 +297,13 @@
      'native' calls. For 'tcp' sockets we just use what java provides.
   */
   
  +/* XXX @deprecated !!! All this will move to jk_channel_un, and we'll
  +   use the same dispatch that we use for the jni channel !!!
  +*/
      
   JNIEXPORT jlong JNICALL 
   Java_org_apache_jk_apr_AprImpl_unSocketClose(JNIEnv *jniEnv, jobject _jthis, 
  -                                             jlong poolJ, jlong socketJ, jint typeJ )
  +                                             jlong socketJ, jint typeJ )
   {
       int socket=(int)socketJ;
       int type=(int)typeJ;
  @@ -276,9 +314,8 @@
   
   JNIEXPORT jlong JNICALL 
   Java_org_apache_jk_apr_AprImpl_unSocketListen(JNIEnv *jniEnv, jobject _jthis, 
  -                                              jlong poolJ, jstring hostJ, jint backlog
)
  +                                              jstring hostJ, jint backlog )
   {
  -    apr_pool_t *pool=(apr_pool_t *)(void *)(long)poolJ;
       const char *host;
       int status;
       int unixSocket=-1L;
  @@ -325,9 +362,8 @@
   
   JNIEXPORT jlong JNICALL 
   Java_org_apache_jk_apr_AprImpl_unSocketConnect(JNIEnv *jniEnv, jobject _jthis, 
  -                                               jlong poolJ, jstring hostJ )
  +                                               jstring hostJ )
   {
  -    apr_pool_t *pool=(apr_pool_t *)(void *)(long)poolJ;
       const char *host;
       int status;
       int unixSocket=-1L;
  @@ -366,7 +402,7 @@
   
   JNIEXPORT jlong JNICALL 
   Java_org_apache_jk_apr_AprImpl_unAccept(JNIEnv *jniEnv, jobject _jthis, 
  -                                      jlong poolJ, jlong unSocketJ)
  +                                      jlong unSocketJ)
   {
   #ifdef HAVE_UNIXSOCKETS
       int listenUnSocket=(int)unSocketJ;
  @@ -381,10 +417,6 @@
   
           fprintf(stderr, "unAccept %d\n", listenUnSocket );
   
  -#ifdef HAVE_SIGNALS
  -/*         signal( SIGCHLD, SIG_IGN ); */
  -/*         signal( SIGIO, jk2_SigAction ); */
  -#endif        
           clientlen=sizeof( client );
           
           connfd=accept( listenUnSocket, (struct sockaddr *)&client, &clientlen );
  @@ -410,11 +442,10 @@
   
   JNIEXPORT jint JNICALL 
   Java_org_apache_jk_apr_AprImpl_unRead(JNIEnv *jniEnv, jobject _jthis, 
  -                                      jlong poolJ, jlong unSocketJ,
  +                                      jlong unSocketJ,
                                         jbyteArray jbuf, jint from, jint cnt)
   {
   #ifdef HAVE_UNIXSOCKETS
  -    apr_pool_t *pool=(apr_pool_t *)(void *)(long)poolJ;
       jbyte *nbuf;
       int rd;
       jboolean iscopy;
  @@ -455,10 +486,9 @@
   
   JNIEXPORT jint JNICALL 
   Java_org_apache_jk_apr_AprImpl_unWrite(JNIEnv *jniEnv, jobject _jthis, 
  -                                     jlong poolJ, jlong unSocketJ, jbyteArray jbuf, jint
from, jint cnt)
  +                                     jlong unSocketJ, jbyteArray jbuf, jint from, jint
cnt)
   {
       apr_status_t status;
  -    apr_pool_t *pool=(apr_pool_t *)(void *)(long)poolJ;
       jbyte *nbuf;
       int rd=0;
   #ifdef HAVE_UNIXSOCKETS
  @@ -549,7 +579,7 @@
   }
   
   /*
  -  Recycle the jk env 
  +  Recycle the jk endpoint
   */
   JNIEXPORT void JNICALL 
   Java_org_apache_jk_apr_AprImpl_jkRecycle
  @@ -596,7 +626,7 @@
   }
   
   /*
  -  Create a jk handler
  +  Create a jk handler XXX It should be createJkBean
   */
   JNIEXPORT jlong JNICALL 
   Java_org_apache_jk_apr_AprImpl_createJkHandler
  @@ -638,6 +668,44 @@
   
   /*
   */
  +JNIEXPORT jint JNICALL 
  +Java_org_apache_jk_apr_AprImpl_jkInit
  +  (JNIEnv *jniEnv, jobject o, jlong xEnv, jlong componentP )
  +{
  +    jk_env_t *env=(jk_env_t *)(void *)(long)xEnv;
  +    jk_bean_t *component=(jk_bean_t *)(void *)(long)componentP;
  +    int rc;
  +    
  +    if( component->init ==NULL )
  +        return JK_OK;
  +    
  +    rc=component->init( env, component );
  +
  +    return rc;
  +}
  +
  +/*
  +*/
  +JNIEXPORT jint JNICALL 
  +Java_org_apache_jk_apr_AprImpl_jkDestroy
  +  (JNIEnv *jniEnv, jobject o, jlong xEnv, jlong componentP )
  +{
  +    jk_env_t *env=(jk_env_t *)(void *)(long)xEnv;
  +    jk_bean_t *component=(jk_bean_t *)(void *)(long)componentP;
  +    int rc;
  +    
  +    if( component->destroy ==NULL )
  +        return JK_OK;
  +    
  +    rc=component->destroy( env, component );
  +
  +    /* XXX component->pool->reset( env, component->pool ); */
  +    
  +    return rc;
  +}
  +
  +/*
  +*/
   JNIEXPORT jstring JNICALL 
   Java_org_apache_jk_apr_AprImpl_jkGetAttribute
     (JNIEnv *jniEnv, jobject o, jlong xEnv, jlong componentP, jstring nameJ)
  @@ -661,26 +729,6 @@
       return valueJ;
   }
   
  -/*
  -*/
  -JNIEXPORT jint JNICALL 
  -Java_org_apache_jk_apr_AprImpl_jkGetId
  -  (JNIEnv *jniEnv, jobject o, jlong xEnv, jstring nsJ, jstring nameJ)
  -{
  -    jk_env_t *env=(jk_env_t *)(void *)(long)xEnv;
  -    char *name=(char *)(*jniEnv)->GetStringUTFChars(jniEnv, nameJ, 0);
  -    char *value;
  -    int rc=-1;
  -    int i=0;
  -
  -    env->l->jkLog(env, env->l, JK_LOG_INFO, 
  -                  "aprImpl.getId()  %d %s\n", rc, name );
  -        
  -    (*jniEnv)->ReleaseStringUTFChars(jniEnv, nameJ, name);
  -    
  -    return rc;
  -}
  -
   
   /*
   */
  @@ -749,4 +797,5 @@
   
       return rc;
   }
  +
   
  
  
  
  1.3       +6 -61     jakarta-tomcat-connectors/jk/native2/jni/org_apache_jk_apr_AprImpl.h
  
  Index: org_apache_jk_apr_AprImpl.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/jni/org_apache_jk_apr_AprImpl.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- org_apache_jk_apr_AprImpl.h	12 May 2002 01:10:56 -0000	1.2
  +++ org_apache_jk_apr_AprImpl.h	26 May 2002 07:38:17 -0000	1.3
  @@ -36,21 +36,6 @@
   JNIEXPORT jint JNICALL Java_org_apache_jk_apr_AprImpl_terminate
     (JNIEnv *, jobject);
   
  -/*
  - * Class:     org_apache_jk_apr_AprImpl
  - * Method:    poolCreate
  - * Signature: (J)J
  - */
  -JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_poolCreate
  -  (JNIEnv *, jobject, jlong);
  -
  -/*
  - * Class:     org_apache_jk_apr_AprImpl
  - * Method:    poolClear
  - * Signature: (J)J
  - */
  -JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_poolClear
  -  (JNIEnv *, jobject, jlong);
   
   /*
    * Class:     org_apache_jk_apr_AprImpl
  @@ -58,7 +43,7 @@
    * Signature: (JJI)J
    */
   JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_unSocketClose
  -  (JNIEnv *, jobject, jlong, jlong, jint);
  +  (JNIEnv *, jobject, jlong, jint);
   
   /*
    * Class:     org_apache_jk_apr_AprImpl
  @@ -66,7 +51,7 @@
    * Signature: (JLjava/lang/String;I)J
    */
   JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_unSocketListen
  -  (JNIEnv *, jobject, jlong, jstring, jint);
  +  (JNIEnv *, jobject, jstring, jint);
   
   /*
    * Class:     org_apache_jk_apr_AprImpl
  @@ -74,7 +59,7 @@
    * Signature: (JLjava/lang/String;)J
    */
   JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_unSocketConnect
  -  (JNIEnv *, jobject, jlong, jstring);
  +  (JNIEnv *, jobject, jstring);
   
   /*
    * Class:     org_apache_jk_apr_AprImpl
  @@ -82,7 +67,7 @@
    * Signature: (JJ)J
    */
   JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_unAccept
  -  (JNIEnv *, jobject, jlong, jlong);
  +  (JNIEnv *, jobject, jlong);
   
   /*
    * Class:     org_apache_jk_apr_AprImpl
  @@ -90,7 +75,7 @@
    * Signature: (JJ[BII)I
    */
   JNIEXPORT jint JNICALL Java_org_apache_jk_apr_AprImpl_unRead
  -  (JNIEnv *, jobject, jlong, jlong, jbyteArray, jint, jint);
  +  (JNIEnv *, jobject, jlong, jbyteArray, jint, jint);
   
   /*
    * Class:     org_apache_jk_apr_AprImpl
  @@ -98,47 +83,7 @@
    * Signature: (JJ[BII)I
    */
   JNIEXPORT jint JNICALL Java_org_apache_jk_apr_AprImpl_unWrite
  -  (JNIEnv *, jobject, jlong, jlong, jbyteArray, jint, jint);
  -
  -/*
  - * Class:     org_apache_jk_apr_AprImpl
  - * Method:    mutexCreate
  - * Signature: (JLjava/lang/String;I)J
  - */
  -JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_mutexCreate
  -  (JNIEnv *, jobject, jlong, jstring, jint);
  -
  -/*
  - * Class:     org_apache_jk_apr_AprImpl
  - * Method:    mutexLock
  - * Signature: (JJ)J
  - */
  -JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_mutexLock
  -  (JNIEnv *, jobject, jlong, jlong);
  -
  -/*
  - * Class:     org_apache_jk_apr_AprImpl
  - * Method:    mutexUnLock
  - * Signature: (JJ)J
  - */
  -JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_mutexUnLock
  -  (JNIEnv *, jobject, jlong, jlong);
  -
  -/*
  - * Class:     org_apache_jk_apr_AprImpl
  - * Method:    mutexTryLock
  - * Signature: (JJ)J
  - */
  -JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_mutexTryLock
  -  (JNIEnv *, jobject, jlong, jlong);
  -
  -/*
  - * Class:     org_apache_jk_apr_AprImpl
  - * Method:    mutexDestroy
  - * Signature: (JJ)J
  - */
  -JNIEXPORT jlong JNICALL Java_org_apache_jk_apr_AprImpl_mutexDestroy
  -  (JNIEnv *, jobject, jlong, jlong);
  +  (JNIEnv *, jobject, jlong, jbyteArray, jint, jint);
   
   /*
    * Class:     org_apache_jk_apr_AprImpl
  
  
  

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


Mime
View raw message