mturk 2005/06/17 02:43:35
Modified: http11/src/java/org/apache/coyote/http11
Http11AprProcessor.java Http11AprProtocol.java
jk/java/org/apache/coyote/ajp AjpAprProcessor.java
AjpAprProtocol.java
util/java/org/apache/tomcat/util/net AprEndpoint.java
Log:
Implement new socket abstraction.
We don't need to maintain the pool, so the poll size can be half the size.
Revision Changes Path
1.15 +3 -3
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11AprProcessor.java
Index: Http11AprProcessor.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11AprProcessor.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Http11AprProcessor.java 26 May 2005 09:06:16 -0000 1.14
+++ Http11AprProcessor.java 17 Jun 2005 09:43:35 -0000 1.15
@@ -729,7 +729,7 @@
*
* @throws IOException error during an I/O operation
*/
- public boolean process(long socket, long pool)
+ public boolean process(long socket)
throws IOException {
ThreadWithAttributes thrA=
(ThreadWithAttributes)Thread.currentThread();
@@ -779,7 +779,7 @@
rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
openSocket = true;
// Add the socket to the poller
- endpoint.getPoller().add(socket, pool);
+ endpoint.getPoller().add(socket);
break;
}
request.setStartTime(System.currentTimeMillis());
@@ -884,7 +884,7 @@
// Do sendfile as needed: add socket to sendfile and end
if (sendfileData != null) {
sendfileData.socket = socket;
- sendfileData.pool = pool;
+ sendfileData.pool = 0;
if (!endpoint.getSendfile().add(sendfileData)) {
keepAlive = false;
}
1.9 +2 -2
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11AprProtocol.java
Index: Http11AprProtocol.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11AprProtocol.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Http11AprProtocol.java 27 May 2005 15:40:23 -0000 1.8
+++ Http11AprProtocol.java 17 Jun 2005 09:43:35 -0000 1.9
@@ -664,7 +664,7 @@
return thData;
}
- public boolean process(long socket, long pool) {
+ public boolean process(long socket) {
Http11AprProcessor processor=null;
try {
// FIXME: It is also possible to use the TWA data, so keep
init() [] for
@@ -696,7 +696,7 @@
processor.setSocket( socket );
*/
- return processor.process(socket, pool);
+ return processor.process(socket);
} catch(java.net.SocketException e) {
// SocketExceptions are normal
1.5 +2 -2
jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java
Index: AjpAprProcessor.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AjpAprProcessor.java 16 Jun 2005 11:52:26 -0000 1.4
+++ AjpAprProcessor.java 17 Jun 2005 09:43:35 -0000 1.5
@@ -352,7 +352,7 @@
*
* @throws IOException error during an I/O operation
*/
- public boolean process(long socket, long pool)
+ public boolean process(long socket)
throws IOException {
ThreadWithAttributes thrA=
(ThreadWithAttributes)Thread.currentThread();
@@ -464,7 +464,7 @@
// Add the socket to the poller
if (!error) {
- endpoint.getPoller().add(socket, pool);
+ endpoint.getPoller().add(socket);
} else {
openSocket = false;
}
1.2 +2 -2
jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/AjpAprProtocol.java
Index: AjpAprProtocol.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/AjpAprProtocol.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AjpAprProtocol.java 9 Jun 2005 16:14:51 -0000 1.1
+++ AjpAprProtocol.java 17 Jun 2005 09:43:35 -0000 1.2
@@ -568,7 +568,7 @@
return thData;
}
- public boolean process(long socket, long pool) {
+ public boolean process(long socket) {
AjpAprProcessor processor=null;
try {
// FIXME: It is also possible to use the TWA data, so keep
init() [] for
@@ -600,7 +600,7 @@
processor.setSocket( socket );
*/
- return processor.process(socket, pool);
+ return processor.process(socket);
} catch(java.net.SocketException e) {
// SocketExceptions are normal
1.46 +31 -35
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.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- AprEndpoint.java 14 Jun 2005 13:14:19 -0000 1.45
+++ AprEndpoint.java 17 Jun 2005 09:43:35 -0000 1.46
@@ -576,7 +576,7 @@
/**
* Process the specified connection.
*/
- protected boolean processSocket(long socket, long pool) {
+ protected boolean processSocket(long socket) {
// Process the connection
int step = 1;
boolean result = true;
@@ -596,7 +596,7 @@
// 3: Process the connection
step = 3;
- result = getHandler().process(socket, pool);
+ result = getHandler().process(socket);
} catch (Throwable t) {
if (step == 2) {
@@ -728,7 +728,7 @@
pool = Pool.create(serverSockPool);
socket = Socket.accept(serverSock, pool);
// Hand this socket off to an appropriate processor
- workerThread.assign(socket, pool);
+ workerThread.assign(socket);
} catch (Exception e) {
log.error(sm.getString("endpoint.accept.fail"), e);
}
@@ -760,7 +760,6 @@
protected long[] desc;
protected long[] addS;
- protected long[] addP;
protected int addCount = 0;
/**
@@ -785,10 +784,9 @@
log.error(sm.getString("endpoint.poll.initfail"), e);
}
}
- desc = new long[pollerSize * 4];
+ desc = new long[pollerSize * 2];
keepAliveCount = 0;
addS = new long[pollerSize];
- addP = new long[pollerSize];
addCount = 0;
}
@@ -798,13 +796,13 @@
protected void destroy() {
// Close all sockets in the add queue
for (int i = 0; i < addCount; i--) {
- Pool.destroy(addP[i]);
+ Socket.destroy(addS[i]);
}
// Close all sockets still in the poller
int rv = Poll.pollset(serverPollset, desc);
if (rv > 0) {
for (int n = 0; n < rv; n++) {
- Pool.destroy(desc[n*4+2]);
+ Socket.destroy(desc[n*2+1]);
}
}
Pool.destroy(pool);
@@ -821,17 +819,16 @@
* @param socket to add to the poller
* @param pool reprenting the memory used for the socket
*/
- public void add(long socket, long pool) {
+ public void add(long socket) {
synchronized (addS) {
// Add socket to the list. Newly added sockets will wait
// at most for pollTime before being polled
if (addCount >= addS.length) {
// Can't do anything: close the socket right away
- Pool.destroy(pool);
+ Socket.destroy(socket);
return;
}
addS[addCount] = socket;
- addP[addCount] = pool;
addCount++;
addS.notify();
}
@@ -874,12 +871,12 @@
synchronized (addS) {
for (int i = (addCount - 1); i >= 0; i--) {
int rv = Poll.add
- (serverPollset, addS[i], addP[i],
Poll.APR_POLLIN);
+ (serverPollset, addS[i],
Poll.APR_POLLIN);
if (rv == Status.APR_SUCCESS) {
keepAliveCount++;
} else {
// Can't do anything: close the socket
right away
- Pool.destroy(addP[i]);
+ Socket.destroy(addS[i]);
}
}
addCount = 0;
@@ -892,14 +889,14 @@
keepAliveCount -= rv;
for (int n = 0; n < rv; n++) {
// Check for failed sockets
- if (((desc[n*4] & Poll.APR_POLLHUP) ==
Poll.APR_POLLHUP)
- || ((desc[n*4] & Poll.APR_POLLERR) ==
Poll.APR_POLLERR)) {
+ if (((desc[n*2] & Poll.APR_POLLHUP) ==
Poll.APR_POLLHUP)
+ || ((desc[n*2] & Poll.APR_POLLERR) ==
Poll.APR_POLLERR)) {
// Close socket and clear pool
- Pool.destroy(desc[n*4+2]);
+ Socket.destroy(desc[n*2+1]);
continue;
}
// Hand this socket off to a worker
- getWorkerThread().assign(desc[n*4+1],
desc[n*4+2]);
+ getWorkerThread().assign(desc[n*2+1]);
}
} else if (rv < 0) {
/* Any non timeup error is critical */
@@ -919,7 +916,7 @@
keepAliveCount -= rv;
for (int n = 0; n < rv; n++) {
// Close socket and clear pool
- Pool.destroy(desc[n*4+2]);
+ Socket.destroy(desc[n*2+1]);
}
}
}
@@ -951,7 +948,6 @@
protected Thread thread = null;
protected boolean available = false;
protected long socket = 0;
- protected long pool = 0;
/**
@@ -963,7 +959,7 @@
*
* @param socket TCP socket to process
*/
- protected synchronized void assign(long socket, long pool) {
+ protected synchronized void assign(long socket) {
// Wait for the Processor to get the previous Socket
while (available) {
@@ -975,7 +971,6 @@
// Store the newly available Socket and notify our thread
this.socket = socket;
- this.pool = pool;
available = true;
notifyAll();
@@ -1021,10 +1016,10 @@
continue;
// Process the request from this socket
- if (!processSocket(socket, pool)) {
+ if (!processSocket(socket)) {
// Close socket and pool
- Pool.destroy(pool);
- pool = 0;
+ Socket.destroy(socket);
+ socket = 0;
}
// Finish up this request
@@ -1125,13 +1120,13 @@
// Close any socket remaining in the add queue
for (int i = (addS.size() - 1); i >= 0; i--) {
SendfileData data = (SendfileData) addS.get(i);
- Pool.destroy(data.pool);
+ Socket.destroy(data.socket);
}
// Close all sockets still in the poller
int rv = Poll.pollset(sendfilePollset, desc);
if (rv > 0) {
for (int n = 0; n < rv; n++) {
- Pool.destroy(desc[n*4+2]);
+ Socket.destroy(desc[n*2+1]);
}
}
Pool.destroy(pool);
@@ -1151,7 +1146,7 @@
public boolean add(SendfileData data) {
// Initialize fd from data given
try {
- data.fdpool = Pool.create(data.pool);
+ data.fdpool = Socket.pool(data.socket);
data.fd = File.open
(data.fileName, File.APR_FOPEN_READ
| File.APR_FOPEN_SENDFILE_ENABLED |
File.APR_FOPEN_BINARY,
@@ -1164,7 +1159,8 @@
data.pos, data.end, 0);
if (nw < 0) {
if (!(-nw == Status.EAGAIN)) {
- Poll.destroy(data.pool);
+ Socket.destroy(data.socket);
+ data.socket = 0;
return false;
} else {
// Break the loop and add the socket to poller.
@@ -1181,7 +1177,7 @@
}
}
}
- } catch (Error e) {
+ } catch (Exception e) {
log.error(sm.getString("endpoint.sendfile.error"), e);
return false;
}
@@ -1243,7 +1239,7 @@
synchronized (addS) {
for (int i = (addS.size() - 1); i >= 0; i--) {
SendfileData data = (SendfileData)
addS.get(i);
- int rv = Poll.add(sendfilePollset,
data.socket, 0, Poll.APR_POLLOUT);
+ int rv = Poll.add(sendfilePollset,
data.socket, Poll.APR_POLLOUT);
if (rv == Status.APR_SUCCESS) {
sendfileData.put(new Long(data.socket),
data);
sendfileCount++;
@@ -1264,8 +1260,8 @@
SendfileData state =
(SendfileData) sendfileData.get(new
Long(desc[n*4+1]));
// Problem events
- if (((desc[n*4] & Poll.APR_POLLHUP) ==
Poll.APR_POLLHUP)
- || ((desc[n*4] & Poll.APR_POLLERR) ==
Poll.APR_POLLERR)) {
+ if (((desc[n*2] & Poll.APR_POLLHUP) ==
Poll.APR_POLLHUP)
+ || ((desc[n*2] & Poll.APR_POLLERR) ==
Poll.APR_POLLERR)) {
// Close socket and clear pool
remove(state);
// Destroy file descriptor pool, which
should close the file
@@ -1275,7 +1271,7 @@
continue;
}
// Write some data using sendfile
- long nw = Socket.sendfile(desc[n*4+1], state.fd,
+ long nw = Socket.sendfile(desc[n*2+1], state.fd,
null, null, state.pos,
state.end - state.pos,
0);
if (nw < 0) {
@@ -1294,7 +1290,7 @@
Pool.destroy(state.fdpool);
// If all done hand this socket off to a
worker for
// processing of further requests
- getWorkerThread().assign(desc[n*4+1],
state.pool);
+ getWorkerThread().assign(desc[n*2+1]);
}
}
} else if (rv < 0) {
@@ -1335,7 +1331,7 @@
* thread local fields.
*/
public interface Handler {
- public boolean process(long socket, long pool);
+ public boolean process(long socket);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]