jfclere 2005/06/09 02:33:40 Modified: jni/java/org/apache/tomcat/jni BIOCallback.java jni/native/src ssl.c Log: Change the BIOCallback interface to use write(byte[] buf) and read(byte[] buf); The buff is in the native encoding that allows to use it for both stdio/stderri redirection and for the sockets (JAVA or APR). Revision Changes Path 1.4 +7 -7 jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/BIOCallback.java Index: BIOCallback.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/java/org/apache/tomcat/jni/BIOCallback.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- BIOCallback.java 9 Jun 2005 09:13:54 -0000 1.3 +++ BIOCallback.java 9 Jun 2005 09:33:40 -0000 1.4 @@ -26,17 +26,17 @@ /** * Write data - * @param data String to write - * @return Number of characters written + * @param buf containg the bytes to write. + * @return Number of characters written. */ - public int write(String data); + public int write(byte [] buf); /** * Read data - * @param len Maximum number of characters to read - * @return String with up to len bytes readed + * @param buf buffer to store the read bytes. + * @return number of bytes read. */ - public String read(int len); + public int read(byte [] buf); /** * Puts string 1.29 +19 -17 jakarta-tomcat-connectors/jni/native/src/ssl.c Index: ssl.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jni/native/src/ssl.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- ssl.c 9 Jun 2005 09:13:55 -0000 1.28 +++ ssl.c 9 Jun 2005 09:33:40 -0000 1.29 @@ -551,10 +551,12 @@ if (b->init && in != NULL) { BIO_JAVA *j = (BIO_JAVA *)b->ptr; JNIEnv *e = j->cb.env; - if ((*e)->CallIntMethod(e, j->cb.obj, - j->cb.mid[0], - tcn_new_string(e, in, inl))) - ret = inl; + jbyteArray jb = (*e)->NewByteArray(e, inl); + (*e)->SetByteArrayRegion(e, jb, 0, inl, (jbyte *)in); + jint o = (*e)->CallIntMethod(e, j->cb.obj, + j->cb.mid[0], jb); + (*e)->ReleaseByteArrayElements(e, jb, (jbyte *)in, 0); + ret = o; } return ret; } @@ -565,16 +567,16 @@ if (b->init && out != NULL) { BIO_JAVA *j = (BIO_JAVA *)b->ptr; JNIEnv *e = j->cb.env; - jobject o; - if ((o = (*e)->CallObjectMethod(e, j->cb.obj, - j->cb.mid[1], (jint)(outl - 1)))) { - TCN_ALLOC_CSTRING(o); - if (J2S(o)) { - int l = (int)strlen(J2S(o)); - ret = TCN_MIN(outl, l); - memcpy(out, J2S(o), ret); - } - TCN_FREE_CSTRING(o); + jbyteArray jb = (*e)->NewByteArray(e, outl); + + jint o = (*e)->CallObjectMethod(e, j->cb.obj, + j->cb.mid[1], jb); + if (o>=0) { + int i; + jbyte *jout = (*e)->GetByteArrayElements(e, jb, 0); + memcpy(out, jout, o); + (*e)->ReleaseByteArrayElements(e, jb, jout, 0); + ret = o; } } return ret; @@ -666,8 +668,8 @@ cls = (*e)->GetObjectClass(e, callback); j->cb.env = e; - j->cb.mid[0] = (*e)->GetMethodID(e, cls, "write", "(Ljava/lang/String;)I"); - j->cb.mid[1] = (*e)->GetMethodID(e, cls, "read", "(I)Ljava/lang/String;"); + j->cb.mid[0] = (*e)->GetMethodID(e, cls, "write", "([B)I"); + j->cb.mid[1] = (*e)->GetMethodID(e, cls, "read", "([B)I"); j->cb.mid[2] = (*e)->GetMethodID(e, cls, "puts", "(Ljava/lang/String;)I"); j->cb.mid[3] = (*e)->GetMethodID(e, cls, "gets", "(I)Ljava/lang/String;"); /* TODO: Check if method id's are valid */
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]