remm        2005/05/17 05:20:20

  Modified:    util/java/org/apache/tomcat/util/net AprEndpoint.java
  Log:
  - Add javadocs.
  - Fix sync on the arrylist for sendfile (in the case where stuff is added to 
the
    array list, which I haven't seen happen yet).
  
  Revision  Changes    Path
  1.27      +62 -24    
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/AprEndpoint.java
  
  Index: AprEndpoint.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/AprEndpoint.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- AprEndpoint.java  14 May 2005 15:42:30 -0000      1.26
  +++ AprEndpoint.java  17 May 2005 12:20:20 -0000      1.27
  @@ -727,6 +727,10 @@
           protected long[] addP;
           protected int addCount = 0;
   
  +        /**
  +         * Create the poller. With some versions of APR, the maximum poller 
size will
  +         * be 62 (reocmpiling APR is necessary to remove this limitation).
  +         */
           protected synchronized void init() {
               pool = Pool.create(serverSockPool);
               try {
  @@ -751,10 +755,22 @@
               addP = new long[pollerSize];
           }
   
  +        /**
  +         * Destroy the poller.
  +         */
           protected void destroy() {
               Pool.destroy(pool);
           }
   
  +        /**
  +         * Add specified socket and associated pool to the poller. The 
socket will
  +         * be added to a temporary array, and polled first after a maximum 
amount
  +         * of time equal to pollTime (in most cases, latency will be much 
lower,
  +         * however).
  +         * 
  +         * @param socket to add to the poller
  +         * @param pool reprenting the memory used for the socket
  +         */
           public void add(long socket, long pool) {
               synchronized (addS) {
                   // Add socket to the list. Newly added sockets will wait 
  @@ -1018,6 +1034,10 @@
   
           protected ArrayList addS;
   
  +        /**
  +         * Create the sendfile poller. With some versions of APR, the 
maximum poller size will
  +         * be 62 (reocmpiling APR is necessary to remove this limitation).
  +         */
           protected void init() {
               pool = Pool.create(serverSockPool);
               try {
  @@ -1041,11 +1061,24 @@
               addS = new ArrayList();
           }
   
  +        /**
  +         * Destroy the poller.
  +         */
           protected void destroy() {
               sendfileData.clear();
               Pool.destroy(pool);
           }
   
  +        /**
  +         * Add the sendfile data to the sendfile poller. Note that in most 
cases,
  +         * the initial non blocking calls to sendfile will return right 
away, and
  +         * will be handled asynchronously inside the kernel. As a result, 
  +         * the poller will never be used.
  +         * 
  +         * @param data containing the reference to the data which should be 
snet
  +         * @return true if all the data has been sent right away, and false 
  +         *              otherwise
  +         */
           public boolean add(SendfileData data) {
               // Initialize fd from data given
               try {
  @@ -1091,16 +1124,19 @@
               return false;
           }
   
  -        public void remove(long socket) {
  -            synchronized (this) {
  -                int rv = Poll.remove(sendfilePollset, socket);
  -                if (rv == Status.APR_SUCCESS) {
  -                    sendfileCount--;
  -                }
  -                // Set the socket to blocking mode again
  -                Socket.optSet(socket, Socket.APR_SO_NONBLOCK, 0);
  -                sendfileData.remove(new Long(socket));
  -            }
  +        /**
  +         * Remove socket from the poller.
  +         * 
  +         * @param data the sendfile data which should be removed
  +         */
  +        protected void remove(SendfileData data) {
  +            int rv = Poll.remove(sendfilePollset, data.socket);
  +            if (rv == Status.APR_SUCCESS) {
  +                sendfileCount--;
  +            }
  +            // Set the socket to blocking mode again
  +            Socket.optSet(data.socket, Socket.APR_SO_NONBLOCK, 0);
  +            sendfileData.remove(data);
           }
   
           /**
  @@ -1132,19 +1168,21 @@
                   try {
                       // Add socket to the poller
                       if (addS.size() > 0) {
  -                        for (int i = 0; i < addS.size(); i++) {
  -                            SendfileData data = (SendfileData) addS.get(i);
  -                            int rv = Poll.add(sendfilePollset, data.socket, 
0, Poll.APR_POLLOUT);
  -                            if (rv == Status.APR_SUCCESS) {
  -                                sendfileData.put(new Long(data.socket), 
data);
  -                                sendfileCount++;
  -                            } else {
  -                                
log.warn(sm.getString("endpoint.sendfile.addfail", "" + rv));
  -                                // Can't do anything: close the socket right 
away
  -                                Pool.destroy(data.pool);
  +                        synchronized (addS) {
  +                            for (int i = 0; i < addS.size(); i++) {
  +                                SendfileData data = (SendfileData) 
addS.get(i);
  +                                int rv = Poll.add(sendfilePollset, 
data.socket, 0, Poll.APR_POLLOUT);
  +                                if (rv == Status.APR_SUCCESS) {
  +                                    sendfileData.put(new Long(data.socket), 
data);
  +                                    sendfileCount++;
  +                                } else {
  +                                    
log.warn(sm.getString("endpoint.sendfile.addfail", "" + rv));
  +                                    // Can't do anything: close the socket 
right away
  +                                    Pool.destroy(data.pool);
  +                                }
                               }
  +                            addS.clear();
                           }
  -                        addS.clear();
                       }
                       // Pool for the specified interval
                       int rv = Poll.poll(sendfilePollset, pollTime, desc, 
false);
  @@ -1157,7 +1195,7 @@
                               if (((desc[n*4] & Poll.APR_POLLHUP) == 
Poll.APR_POLLHUP)
                                       || ((desc[n*4] & Poll.APR_POLLERR) == 
Poll.APR_POLLERR)) {
                                   // Close socket and clear pool
  -                                remove(desc[n*4+1]);
  +                                remove(state);
                                   // Destroy file descriptor pool, which 
should close the file
                                   Pool.destroy(state.fdpool);
                                   // Close the socket, as the reponse would be 
incomplete
  @@ -1170,7 +1208,7 @@
                                                        state.end - state.pos, 
0);
                               if (nw < 0) {
                                   // Close socket and clear pool
  -                                remove(desc[n*4+1]);
  +                                remove(state);
                                   // Close the socket, as the reponse would be 
incomplete
                                   // This will close the file too.
                                   Pool.destroy(state.pool);
  @@ -1179,7 +1217,7 @@
   
                               state.pos = state.pos + nw;
                               if (state.pos >= state.end) {
  -                                remove(desc[n*4+1]);
  +                                remove(state);
                                   // Destroy file descriptor pool, which 
should close the file
                                   Pool.destroy(state.fdpool);
                                   // If all done hand this socket off to a 
worker for
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to