You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mt...@apache.org on 2005/06/17 13:23:33 UTC

cvs commit: jakarta-tomcat-connectors/jni/examples/org/apache/tomcat/jni Echo.java SSLServer.java

mturk       2005/06/17 04:23:33

  Modified:    jni/examples/org/apache/tomcat/jni Echo.java SSLServer.java
  Log:
  Update examples.
  
  Revision  Changes    Path
  1.12      +13 -14    jakarta-tomcat-connectors/jni/examples/org/apache/tomcat/jni/Echo.java
  
  Index: Echo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/examples/org/apache/tomcat/jni/Echo.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Echo.java	28 May 2005 12:13:02 -0000	1.11
  +++ Echo.java	17 Jun 2005 11:23:33 -0000	1.12
  @@ -153,23 +153,23 @@
               }
           }
   
  -        public void add(long socket, int workerId) {
  -            int rv = Poll.add(serverPollset, socket, workerId,
  +        public void add(long socket) {
  +            int rv = Poll.add(serverPollset, socket,
                                 Poll.APR_POLLIN);
               if (rv == Status.APR_SUCCESS) {
  -                System.out.println("Added worker " + workerId + " to pollset");
  +                System.out.println("Added worker to pollset");
                   nsocks++;
               }
           }
   
  -        public void remove(long socket, int workerId) {
  +        public void remove(long socket) {
               int rv = Poll.remove(serverPollset, socket);
               if (rv == Status.APR_SUCCESS) {
                  nsocks--;
  -               System.out.println("Removed worker " + workerId + " from pollset");
  +               System.out.println("Removed worker from pollset");
               }
               else {
  -               System.out.println("Failed removing worker " + workerId + " from pollset");
  +               System.out.println("Failed removing worker from pollset");
               }
           }
   
  @@ -180,17 +180,16 @@
                           Thread.sleep(1);
                           continue;
                       }
  -                    /* Four times size then  created pollset */
  +                    /* Two times size then  created pollset */
                       long [] desc = new long[64];
                       /* USe 1 second poll timeout */
                       int rv = Poll.poll(serverPollset, 1000000, desc, false);
                       if (rv > 0) {
                           for (int n = 0; n < rv; n++) {
  -                            long clientSock = desc[n*4+1];
  -                            int  workerId   = (int)desc[n*4+2];
  -                            System.out.println("Poll flags " + desc[n*4]);
  -                            remove(clientSock, workerId);
  -                            Worker worker = new Worker(clientSock, workerId,
  +                            long clientSock = desc[n*2+1];
  +                            System.out.println("Poll flags " + desc[n*2]);
  +                            remove(clientSock);
  +                            Worker worker = new Worker(clientSock, n,
                                                          this.getClass().getName());
                               Echo.incThreads();
                               worker.start();
  @@ -262,7 +261,7 @@
                           Socket.send(clientSock, msg, 0, msg.length);
                       } catch(Exception e) { }
                       /* Put the socket to the keep-alive poll */
  -                    Echo.echoPoller.add(clientSock, workerId);
  +                    Echo.echoPoller.add(clientSock);
                   }
               } catch (Exception e) {
                   Socket.close(clientSock);
  
  
  
  1.8       +14 -12    jakarta-tomcat-connectors/jni/examples/org/apache/tomcat/jni/SSLServer.java
  
  Index: SSLServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jni/examples/org/apache/tomcat/jni/SSLServer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SSLServer.java	15 Jun 2005 15:15:54 -0000	1.7
  +++ SSLServer.java	17 Jun 2005 11:23:33 -0000	1.8
  @@ -154,7 +154,7 @@
                       }
                       else {
                           System.out.println("Handshake error: " + SSL.getLastError());
  -                        SSLSocket.close(sslSocket);
  +                        Socket.destroy(sslSocket);
                       }
                   }
               }
  @@ -179,27 +179,29 @@
           public void run() {
               boolean doClose = false;
               try {
  -                SSLSocket.send(clientSock, wellcomeMsg, 0, wellcomeMsg.length);
  +                Socket.send(clientSock, wellcomeMsg, 0, wellcomeMsg.length);
                   while (!doClose) {
                       /* Do a blocking read byte at a time */
                       byte [] buf = new byte[1];
  -                    int ret;
  -                    ret = SSLSocket.recv(clientSock, buf, 0, 1);
  -                    if (ret != 1)
  -                        throw(new Exception("SSLSocket.recv failed"));
  -                    if (buf[0] == 'Q')
  -                        doClose = true;
  +                    while (Socket.recv(clientSock, buf, 0, 1) == 1) {
  +                        if (buf[0] == '\n')
  +                            break;
  +                        else if (buf[0] == 'Q') {
  +                            doClose = true;
  +                            break;
  +                        }
  +                    }
                       if (doClose) {
                           try {
                               byte [] msg = ("Bye from worker: " + workerId + "\r\n").getBytes();
  -                            SSLSocket.send(clientSock, msg, 0, msg.length);
  +                            Socket.send(clientSock, msg, 0, msg.length);
                           } catch(Exception e) { }
   
  -                        SSLSocket.close(clientSock);
  +                        Socket.close(clientSock);
                       }
                   }
               } catch (Exception e) {
  -                SSLSocket.close(clientSock);
  +                Socket.destroy(clientSock);
                   e.printStackTrace();
               }
               Echo.decThreads();
  
  
  

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