costin 02/02/06 09:43:08 Modified: jk/java/org/apache/jk/common ChannelJni.java ChannelSocket.java ChannelUn.java Log: Update for the api changes. Added isSameAddress from Ajp12Interceptor - will be used with the secret for the shutdown handler. Few changes in jni - less code in static methods ( we'll eventually remove all, but for now it's easier on the C side ) Revision Changes Path 1.4 +63 -47 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelJni.java Index: ChannelJni.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelJni.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ChannelJni.java 26 Jan 2002 07:24:37 -0000 1.3 +++ ChannelJni.java 6 Feb 2002 17:43:08 -0000 1.4 @@ -73,7 +73,7 @@ import org.apache.jk.apr.*; -/** Pass messages using unix domain sockets. +/** Pass messages using jni * * @author Costin Manolache */ @@ -88,20 +88,20 @@ public void init() throws IOException { // static field init, temp - wEnv=we; + wEnvStatic=wEnv; } - public int receive( Msg msg, Endpoint ep ) + public int receive( Msg msg, MsgContext ep ) throws IOException { Msg sentResponse=(Msg)ep.getNote( receivedNote ); // same buffer is used, no need to copy if( msg==sentResponse ) { - d("Returned previously received message "); + if( dL > 0 ) d("Returned previously received message "); return 0; } - d("XXX Copy previously received message "); + if( dL > 0 ) d("XXX Copy previously received message "); // send will alter the msg and insert the response. // copy... // XXX TODO @@ -113,14 +113,14 @@ * We could use 2 packets, or sendAndReceive(). * */ - public int send( Msg msg, Endpoint ep ) + public int send( Msg msg, MsgContext ep ) throws IOException { byte buf[]=msg.getBuffer(); EpData epData=(EpData)ep.getNote( epDataNote ); // send and get the response - d( "Sending packet "); + if( dL > 0 ) d( "Sending packet "); msg.end(); // msg.dump("Outgoing: "); @@ -128,43 +128,78 @@ epData.jkServiceP, buf, msg.getLen() ); ep.setNote( receivedNote, msg ); - d( "Sending packet - done "); + if( dL > 0 ) d( "Sending packet - done "); return 0; } - /* ==================== ==================== */ - - static WorkerEnv wEnv=null; static int epDataNote=-1; - static ChannelJni chJni=new ChannelJni(); - static class EpData { - public long jkEnvP; - public long jkEndpointP; - public long jkServiceP; - } - - public static Endpoint createEndpointStatic(long env, long epP) { - Endpoint ep=new Endpoint(); + public MsgContext createEndpoint(long env, long epP) { + MsgContext ep=new MsgContext(); if( epDataNote==-1) epDataNote=wEnv.getNoteId(WorkerEnv.ENDPOINT_NOTE, "epData"); - d("createEndpointStatic() " + env + " " + epP); + if( dL > 0 ) d("createEndpointStatic() " + env + " " + epP); + EpData epData=new EpData(); epData.jkEnvP=env; epData.jkEndpointP=epP; ep.setNote( epDataNote, epData ); + ep.setWorkerEnv( wEnv ); + + ep.setChannel( this ); return ep; } + public int receive( long env, long rP, MsgContext ep, + MsgAjp msg) + { + try { + // first, we need to get an endpoint. It should be + // per/thread - and probably stored by the C side. + if( dL > 0 ) d("Received request " + rP); + // The endpoint will store the message pt. + + msg.processHeader(); + if( dL > 5 ) msg.dump("Incoming msg "); + + EpData epData=(EpData)ep.getNote( epDataNote ); + + epData.jkServiceP=rP; + + int status= this.invoke( msg, ep ); + + if(dL > 0 ) d("after processCallbacks " + status); + + return status; + } catch( Exception ex ) { + ex.printStackTrace(); + } + return 0; + } + + /* ==================== ==================== */ + + static WorkerEnv wEnvStatic=null; + static ChannelJni chJni=new ChannelJni(); + + static class EpData { + public long jkEnvP; + public long jkEndpointP; + public long jkServiceP; + } + + public static MsgContext createEndpointStatic(long env, long epP) { + return chJni.createEndpoint( env, epP ); + } + public static MsgAjp createMessage() { - System.out.println("XXX CreateMessage"); return new MsgAjp(); } public static byte[] getBuffer(MsgAjp msg) { - System.out.println("XXX getBuffer " + msg.getBuffer() + " " - + msg.getBuffer().length); + //if( dL > 0 ) d("XXX getBuffer " + msg.getBuffer() + " " + // + msg.getBuffer().length); return msg.getBuffer(); } @@ -187,31 +222,12 @@ * the conversion done in java ( after we know the encoding and * if anyone asks for it - same lazy behavior as in 3.3 ). */ - public static int receiveRequest( long env, long rP, Endpoint ep, + public static int receiveRequest( long env, long rP, MsgContext ep, MsgAjp msg) { - try { - // first, we need to get an endpoint. It should be - // per/thread - and probably stored by the C side. - d("Received request " + rP); - // The endpoint will store the message pt. - msg.processHeader(); - // msg.dump("Incoming msg "); - - EpData epData=(EpData)ep.getNote( epDataNote ); - - epData.jkServiceP=rP; - - int status=wEnv.processCallbacks( chJni, ep, msg ); - - d("after processCallbacks "); - - } catch( Exception ex ) { - ex.printStackTrace(); - } - return 0; + return chJni.receive(env, rP, ep, msg ); } - + /** Send the packet to the C side. On return it contains the response * or indication there is no response. Asymetrical because we can't * do things like continuations. @@ -219,7 +235,7 @@ public static native int sendPacket(long env, long e, long s, byte data[], int len); - private static final int dL=10; + private static final int dL=0; private static void d(String s ) { System.err.println( "ChannelJni: " + s ); } 1.4 +70 -16 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java Index: ChannelSocket.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ChannelSocket.java 26 Jan 2002 07:25:09 -0000 1.3 +++ ChannelSocket.java 6 Feb 2002 17:43:08 -0000 1.4 @@ -86,7 +86,7 @@ * Various container adapters should load this object ( as a bean ), * set configurations and use it. Note that the connector will handle * all incoming protocols - it's not specific to ajp1x. The protocol - * is abstracted by Endpoint/Message/Channel. + * is abstracted by MsgContext/Message/Channel. */ @@ -119,6 +119,14 @@ this.inet=inet; } + public void setAddress(String inet) { + try { + this.inet= InetAddress.getByName( inet ); + } catch( Exception ex ) { + ex.printStackTrace(); + } + } + /** * Sets the timeout in ms of the server sockets created by this * server. This method allows the developer to make servers @@ -149,13 +157,15 @@ int isNote=2; int osNote=3; - public void accept( Endpoint ep ) throws IOException { + public void accept( MsgContext ep ) throws IOException { Socket s=sSocket.accept(); ep.setNote( socketNote, s ); if(dL>0 ) d("Accepted socket " + s ); if( linger > 0 ) s.setSoLinger( true, linger); + if( socketTimeout > 0 ) + s.setSoTimeout( socketTimeout ); InputStream is=new BufferedInputStream(s.getInputStream()); OutputStream os= s.getOutputStream(); @@ -174,11 +184,11 @@ tp.runIt( acceptAjp); } - public void open(Endpoint ep) throws IOException { + public void open(MsgContext ep) throws IOException { } - public void close(Endpoint ep) throws IOException { + public void close(MsgContext ep) throws IOException { Socket s=(Socket)ep.getNote( socketNote ); s.close(); } @@ -204,7 +214,7 @@ } } - public int send( Msg msg, Endpoint ep) + public int send( Msg msg, MsgContext ep) throws IOException { msg.end(); // Write the packet header @@ -219,7 +229,7 @@ return len; } - public int receive( Msg msg, Endpoint ep ) + public int receive( Msg msg, MsgContext ep ) throws IOException { if (dL > 0) { @@ -289,7 +299,7 @@ * case it is left unspecified whether the file position (if any) changes. * **/ - public int read( Endpoint ep, byte[] b, int offset, int len) + public int read( MsgContext ep, byte[] b, int offset, int len) throws IOException { InputStream is=(InputStream)ep.getNote( isNote ); @@ -320,8 +330,11 @@ return pos; } - public Endpoint createEndpoint() { - return new Endpoint(); + public MsgContext createEndpoint() { + MsgContext mc=new MsgContext(); + mc.setChannel(this); + mc.setWorkerEnv( wEnv ); + return mc; } boolean running=true; @@ -333,7 +346,7 @@ d("Accepting ajp connections on " + port); while( running ) { try { - Endpoint ep=this.createEndpoint(); + MsgContext ep=this.createEndpoint(); this.accept(ep); SocketConnection ajpConn= new SocketConnection(this, ep); @@ -346,15 +359,15 @@ /** Process a single ajp connection. */ - void processConnection(Endpoint ep) { + void processConnection(MsgContext ep) { if( dL > 0 ) d( "New ajp connection "); try { MsgAjp recv=new MsgAjp(); while( running ) { this.receive( recv, ep ); - int status=we.processCallbacks( this, ep, recv ); - if( status!= Handler.OK ) { + int status= this.invoke( recv, ep ); + if( status!= JkHandler.OK ) { d("processCallbacks status " + status ); break; } @@ -364,8 +377,49 @@ ex.printStackTrace(); } } + + public boolean isSameAddress(MsgContext ep) { + Socket s=(Socket)ep.getNote( socketNote ); + return isSameAddress( s.getLocalAddress(), s.getInetAddress()); + } + + + /** + * Return <code>true</code> if the specified client and server addresses + * are the same. This method works around a bug in the IBM 1.1.8 JVM on + * Linux, where the address bytes are returned reversed in some + * circumstances. + * + * @param server The server's InetAddress + * @param client The client's InetAddress + */ + public static boolean isSameAddress(InetAddress server, InetAddress client) + { + // Compare the byte array versions of the two addresses + byte serverAddr[] = server.getAddress(); + byte clientAddr[] = client.getAddress(); + if (serverAddr.length != clientAddr.length) + return (false); + boolean match = true; + for (int i = 0; i < serverAddr.length; i++) { + if (serverAddr[i] != clientAddr[i]) { + match = false; + break; + } + } + if (match) + return (true); + + // Compare the reversed form of the two addresses + for (int i = 0; i < serverAddr.length; i++) { + if (serverAddr[i] != clientAddr[(serverAddr.length-1)-i]) + return (false); + } + return (true); + } + - private static final int dL=10; + private static final int dL=0; private static void d(String s ) { System.err.println( "ChannelSocket: " + s ); } @@ -390,9 +444,9 @@ class SocketConnection implements ThreadPoolRunnable { ChannelSocket wajp; - Endpoint ep; + MsgContext ep; - SocketConnection(ChannelSocket wajp, Endpoint ep) { + SocketConnection(ChannelSocket wajp, MsgContext ep) { this.wajp=wajp; this.ep=ep; } 1.6 +16 -13 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelUn.java Index: ChannelUn.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelUn.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ChannelUn.java 26 Jan 2002 07:25:09 -0000 1.5 +++ ChannelUn.java 6 Feb 2002 17:43:08 -0000 1.6 @@ -108,7 +108,7 @@ AprImpl apr; long gPool; - public void accept( Endpoint ep ) throws IOException { + public void accept( MsgContext ep ) throws IOException { long l= apr.unAccept(gPool, unixListenSocket); /* We could create a real java.net.Socket, or a UnixSocket, etc */ @@ -145,11 +145,11 @@ tp.runIt( acceptAjp); } - public void open(Endpoint ep) throws IOException { + public void open(MsgContext ep) throws IOException { } - public void close(Endpoint ep) throws IOException { + public void close(MsgContext ep) throws IOException { Long s=(Long)ep.getNote( socketNote ); apr.unSocketClose(gPool, s.longValue(),3); } @@ -163,7 +163,7 @@ e.printStackTrace(); } } - public int send( Msg msg, Endpoint ep) + public int send( Msg msg, MsgContext ep) throws IOException { msg.end(); // Write the packet header @@ -179,7 +179,7 @@ return len; } - public int receive( Msg msg, Endpoint ep ) + public int receive( Msg msg, MsgContext ep ) throws IOException { if (dL > 0) { @@ -249,7 +249,7 @@ * case it is left unspecified whether the file position (if any) changes. * **/ - public int read( Endpoint ep, byte[] b, int offset, int len) throws IOException { + public int read( MsgContext ep, byte[] b, int offset, int len) throws IOException { Long s=(Long)ep.getNote( socketNote ); int pos = 0; int got; @@ -274,8 +274,11 @@ - public Endpoint createEndpoint() { - return new Endpoint(); + public MsgContext createEndpoint() { + MsgContext mc=new MsgContext(); + mc.setChannel( this ); + mc.setWorkerEnv( wEnv ); + return mc; } boolean running=true; @@ -287,7 +290,7 @@ d("Accepting ajp connections on " + file); while( running ) { try { - Endpoint ep=this.createEndpoint(); + MsgContext ep=this.createEndpoint(); this.accept(ep); AprConnection ajpConn= new AprConnection(this, ep); @@ -300,7 +303,7 @@ /** Process a single ajp connection. */ - void processConnection(Endpoint ep) { + void processConnection(MsgContext ep) { if( dL > 0 ) d( "New ajp connection "); try { @@ -311,7 +314,7 @@ // EOS break; } - int status=we.processCallbacks( this, ep, recv ); + int status=this.invoke( recv, ep ); } this.close( ep ); } catch( Exception ex ) { @@ -344,9 +347,9 @@ class AprConnection implements ThreadPoolRunnable { ChannelUn wajp; - Endpoint ep; + MsgContext ep; - AprConnection(ChannelUn wajp, Endpoint ep) { + AprConnection(ChannelUn wajp, MsgContext ep) { this.wajp=wajp; this.ep=ep; }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>