costin 02/01/11 21:25:09 Modified: jk/native2 CHANGES.html build.xml jk/native2/jni jk_jni_aprImpl.c Log: Document some of the changes. Move some of the code did by Jean-Francisc in jk_jni_aprImpl. The whole thing will disapear as soon as apr adds the support. Revision Changes Path 1.4 +26 -0 jakarta-tomcat-connectors/jk/native2/CHANGES.html Index: CHANGES.html =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/CHANGES.html,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CHANGES.html 17 Dec 2001 07:17:08 -0000 1.3 +++ CHANGES.html 12 Jan 2002 05:25:08 -0000 1.4 @@ -18,6 +18,17 @@ efficient.</li> <li> </ul> + +<li>JNI worker. Most options on the jni worker are now optional, jk can detect +and set them automcatically. This reduce the effort needed to configure jni. +It is _required_ that LD_LIBRARY_PATH or equivalent is set coreclty, otherwise +java will not start and apache will crash. ( on windows this may not be needed ). +The user must set either as environment variables or in httpd.conf ( using JkSet ) +or in workers.properties: JAVA_HOME, TOMCAT_HOME ( or CATALINA_HOME ). Jk must +be installed in the standard location ( modules/ or webapps/. The output from +the vm will go in apache's error.log ( like all other jk output ) unless +a special file is requested. + </ul> <h4>Developer specific</h4> @@ -54,6 +65,21 @@ <li>Method signatures. Jk2 uses the same 'patterns' as jni, with a jk_env as first parameter, then 'this' (the pointer to the object ), then regular parameters. The same pattern is used no consistently in all methods. + +<li>JNI has been refactored. On file, jk_vmutil deals with the creation of the +vm and guessing of all properties needed to create a java vm. It could be possible +to create specialized instances of jk_vmutil for different vms ( the default +works for most ). + +<li>JNI now uses the channel abstraction to send/receive messages. In future we +could refine this to use a special 'marshalling' that will map 'messages' into +method invocations. One big benefit is that we can now reuse all objects, no +longer need to use strings ( and thus enable the solving of most i18n problems ). +The code is also more 'uniform' and easier to extend. + +<li>JNI worker is no longer singleton and can be used to start multiple java +programms in the same process. Probably not very usefull for jk in particular, +but the restriction was not needed. <li>(not completed) Error handling. The env parameter will provide a mechanism to pass error information up the stack ( eventually a stack trace ). It'll also 1.11 +7 -30 jakarta-tomcat-connectors/jk/native2/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/build.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- build.xml 6 Jan 2002 09:06:02 -0000 1.10 +++ build.xml 12 Jan 2002 05:25:08 -0000 1.11 @@ -43,7 +43,7 @@ <!-- ==================== Targets ==================== --> - <target name="main" depends="init,apache20,jni,unixsocket"> + <target name="main" depends="init,apache20,jni"> </target> <target name="init" > @@ -77,6 +77,9 @@ info="Use the MD5 implementation that is part of apache2" /> <def name="HAS_APR" info="Allow APR specific extensions" /> + <def name="HAVE_JNI" + info="Jni worker" /> + <def name="HPUX11" if="hpux" /> <src dir="."> <include name="server/apache2/*.c" /> <include name="common/*.c" /> @@ -89,6 +92,7 @@ <include name="${native.dir}/include" /> <include name="${java.home}/../include" /> <include name="${java.home}/../include/linux" if="linux" /> + <include name="${java.home}/../include/hp-ux" if="hpux" /> </includes> <depends> <fileset dir="${native.dir}/common" includes="*.h" /> @@ -128,6 +132,7 @@ <include name="${java.home}/../include/win32" if="win32" /> <include name="${java.home}/../include/linux" if="linux" /> + <include name="${java.home}/../include/linux" if="linux" /> </includes> <depends> <fileset dir="${native.dir}/common" includes="*.h" /> @@ -156,6 +161,7 @@ <linkOpt value="-threadname "JK_JNI Thread"" if="netware" /> <linkOpt value="-stacksize 64000" if="netware" /> + <def name="HPUX11" if="hpux" /> <def name="WIN32" if="win32" /> <def name="NDEBUG" if="win32" /> <def name="_WINDOWS" if="win32" /> @@ -406,33 +412,4 @@ </delete> </target> - <target name="unixsocket" depends="init" if="useunixsocket"> - <mkdir dir="${jk.build}/WEB-INF/jk2/unixsocket" /> - <so sofile="libunixsocket" - buildDir="${jk.build}/WEB-INF/jk2/unixsocket" - optimize="${so.optimize}" - debug="${so.debug}" - profile="${so.profile}"> - - <src dir="."> - <include name="tomcat/UnixSocket.c" /> - <!-- When APR will provide the AF_UNIX socket support --> - <!-- - <include name="common/apr/*.c" if="HAVE_APR" /> - --> - </src> - <includes> - <include name="${java.home}/../include" /> - - <!-- Platform specific includes --> - <include name="${java.home}/../include/netware" if="netware" /> - <include name="${java.home}/../include/win32" if="win32" /> - <include name="${java.home}/../include/linux" if="linux" /> - </includes> - <depends> - <fileset dir="${native.dir}/common" includes="*.h" /> - </depends> - - </so> - </target> </project> 1.4 +52 -11 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- jk_jni_aprImpl.c 6 Jan 2002 09:01:51 -0000 1.3 +++ jk_jni_aprImpl.c 12 Jan 2002 05:25:09 -0000 1.4 @@ -179,7 +179,8 @@ { int socket=(int)socketJ; int type=(int)typeJ; - shutdown( socket, type ); + /* shutdown( socket, type ); */ + close(socket); return 0L; } @@ -188,29 +189,39 @@ jlong poolJ, jstring hostJ, jint backlog ) { apr_pool_t *pool=(apr_pool_t *)(void *)(long)poolJ; - char *host; + const char *host; int status; int unixSocket; struct sockaddr_un unixAddr; + mode_t omask; memset(& unixAddr, 0, sizeof(struct sockaddr_un)); unixAddr.sun_family=AF_UNIX; host=(*jniEnv)->GetStringUTFChars(jniEnv, hostJ, 0); strcpy(unixAddr.sun_path, host); - - unixSocket = socket(AF_UNIX, SOCK_STREAM, 0); - (*jniEnv)->ReleaseStringUTFChars(jniEnv, hostJ, host); + // remove the exist socket. + if (unlink(unixAddr.sun_path) < 0 && errno != ENOENT) { + // The socket cannot be remove... Well I hope that no problems ;-) + } + + unixSocket = socket(AF_UNIX, SOCK_STREAM, 0); if (unixSocket<0) { return 0L; } - bind(unixSocket, - (struct sockaddr *)& unixAddr, - strlen( unixAddr.sun_path ) + - sizeof( unixAddr.sun_family) ); + omask = umask(0117); /* so that only Apache can use socket */ + + status=bind(unixSocket, + (struct sockaddr *)& unixAddr, + strlen( unixAddr.sun_path ) + + sizeof( unixAddr.sun_family) ); + + umask(omask); /* can't fail, so can't clobber errno */ + if (status<0) + return -errno; listen( unixSocket, (int)backlog ); @@ -272,6 +283,8 @@ clientlen=sizeof( client ); connfd=accept( listenUnSocket, (struct sockaddr *)&client, &clientlen ); + /* XXX Should we return EINTR ? This would allow us to stop + */ if( connfd < 0 ) { if( errno==EINTR ) { fprintf(stderr, "EINTR\n"); @@ -279,7 +292,7 @@ } else { fprintf(stderr, "Error accepting %d %d %s\n", listenUnSocket, errno, strerror(errno)); - return -1; + return -errno; } } return (jlong)connfd; @@ -289,7 +302,8 @@ JNIEXPORT jint JNICALL Java_org_apache_jk_apr_AprImpl_unRead(JNIEnv *jniEnv, jobject _jthis, - jlong poolJ, jlong unSocketJ, jbyteArray bufJ, jint from, jint cnt) + jlong poolJ, jlong unSocketJ, + jbyteArray bufJ, jint from, jint cnt) { apr_pool_t *pool=(apr_pool_t *)(void *)(long)poolJ; jbyte *nbuf; @@ -344,5 +358,32 @@ (*jniEnv)->ReleaseByteArrayElements(jniEnv, bufJ, nbuf, 0); return (jint)rd; } + +/** + * setSoLinger + */ +JNIEXPORT jint JNICALL +Java_org_apache_jk_apr_AprImpl_unSetSoLingerNative ( + JNIEnv *env, + jobject ignored, + jint sd, + jint l_onoff, + jint l_linger) +{ + struct linger { + int l_onoff; /* linger active */ + int l_linger; /* how many seconds to linger for */ + } lin; + int rc; + + lin.l_onoff = l_onoff; + lin.l_linger = l_linger; + rc=setsockopt(sd, SOL_SOCKET, SO_LINGER, &lin, sizeof(lin)); + if( rc < 0) { + return -errno; + } + return 0; +} +
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>