JBossWeb SVN: r211 - in trunk/java/org/apache: tomcat/util/net and 1 other directory.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2007-07-31 08:56:33 -0400 (Tue, 31 Jul 2007)
New Revision: 211
Modified:
trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
Log:
- Fix processing of resume/suspend events.
- Add a fixme to use an int rather than a bunch of booleans.
Modified: trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2007-07-31 12:51:22 UTC (rev 210)
+++ trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2007-07-31 12:56:33 UTC (rev 211)
@@ -1223,9 +1223,9 @@
readNotifications = false;
} else if (actionCode == ActionCode.ACTION_COMET_RESUME) {
readNotifications = true;
- endpoint.getCometPoller().add(socket, timeout, false, false);
+ endpoint.getCometPoller().add(socket, timeout, false, false, true);
} else if (actionCode == ActionCode.ACTION_COMET_WRITE) {
- endpoint.getCometPoller().add(socket, timeout, false, true);
+ endpoint.getCometPoller().add(socket, timeout, false, true, false);
} else if (actionCode == ActionCode.ACTION_COMET_TIMEOUT) {
cometTimeout = ((Integer) param).intValue();
}
Modified: trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2007-07-31 12:51:22 UTC (rev 210)
+++ trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2007-07-31 12:56:33 UTC (rev 211)
@@ -564,7 +564,7 @@
}
} else {
proto.endpoint.getCometPoller().add(socket, result.getCometTimeout(),
- result.getReadNotifications(), false);
+ result.getReadNotifications(), false, false);
}
}
}
@@ -589,7 +589,7 @@
// processor.
connections.put(socket, processor);
proto.endpoint.getCometPoller().add(socket, processor.getCometTimeout(),
- processor.getReadNotifications(), false);
+ processor.getReadNotifications(), false, false);
} else {
recycledProcessors.offer(processor);
}
Modified: trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
===================================================================
--- trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 2007-07-31 12:51:22 UTC (rev 210)
+++ trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 2007-07-31 12:56:33 UTC (rev 211)
@@ -1147,7 +1147,7 @@
public int timeout;
public boolean read;
public boolean write;
-
+ public boolean resume;
}
@@ -1177,15 +1177,16 @@
size++;
}
- public void remove(long socket) {
+ public boolean remove(long socket) {
for (int i = 0; i < size; i++) {
if (sockets[i] == socket) {
sockets[i] = sockets[size - 1];
timeouts[i] = timeouts[size - 1];
size--;
- break;
+ return true;
}
}
+ return false;
}
public long check(long date) {
@@ -1219,8 +1220,10 @@
protected long[] sockets;
protected int[] timeouts;
+ // FIXME: replace with an int[] and flags
protected boolean[] reads;
protected boolean[] writes;
+ protected boolean[] resumes;
protected SocketInfo info = new SocketInfo();
@@ -1231,6 +1234,7 @@
timeouts = new int[size];
reads = new boolean[size];
writes = new boolean[size];
+ resumes = new boolean[size];
}
public int size() {
@@ -1245,6 +1249,7 @@
info.timeout = timeouts[pos];
info.read = reads[pos];
info.write = writes[pos];
+ info.resume = resumes[pos];
pos++;
return info;
}
@@ -1255,7 +1260,7 @@
pos = 0;
}
- public boolean add(long socket, int timeout, boolean read, boolean write) {
+ public boolean add(long socket, int timeout, boolean read, boolean write, boolean resume) {
if (size == sockets.length) {
return false;
} else {
@@ -1263,6 +1268,7 @@
timeouts[size] = timeout;
reads[size] = read;
writes[size] = write;
+ resumes[size] = resume;
size++;
return true;
}
@@ -1275,6 +1281,7 @@
System.arraycopy(timeouts, 0, copy.timeouts, 0, size);
System.arraycopy(reads, 0, copy.reads, 0, size);
System.arraycopy(writes, 0, copy.writes, 0, size);
+ System.arraycopy(resumes, 0, copy.resumes, 0, size);
}
}
@@ -1463,7 +1470,7 @@
synchronized (this) {
// Add socket to the list. Newly added sockets will wait
// at most for pollTime before being polled
- if (!addList.add(socket, timeout, true, false)) {
+ if (!addList.add(socket, timeout, true, false, false)) {
// Can't do anything: close the socket right away
if (comet) {
processSocket(socket, SocketStatus.ERROR);
@@ -1489,12 +1496,13 @@
* @param timeout to use for this connection
* @param read to do read polling
* @param write to do write polling
+ * @param resume to send a callback event
*/
- public void add(long socket, int timeout, boolean read, boolean write) {
+ public void add(long socket, int timeout, boolean read, boolean write, boolean resume) {
synchronized (this) {
// Add socket to the list. Newly added sockets will wait
// at most for pollTime before being polled
- if (!addList.add(socket, timeout, read, write)) {
+ if (!addList.add(socket, timeout, read, write, resume)) {
// Can't do anything: close the socket right away
if (comet) {
processSocket(socket, SocketStatus.ERROR);
@@ -1604,11 +1612,16 @@
}
}
} else {
- // Resume event
- timeouts.remove(info.socket);
if (comet) {
- removeFromPoller(info.socket);
- processSocket(info.socket, SocketStatus.OPEN_CALLBACK);
+ if (info.resume) {
+ // Resume event
+ timeouts.remove(info.socket);
+ removeFromPoller(info.socket);
+ processSocket(info.socket, SocketStatus.OPEN_CALLBACK);
+ } else {
+ // Suspend
+ timeouts.add(info.socket, System.currentTimeMillis() + info.timeout);
+ }
} else {
// Should never happen
// FIXME: ISE ?
17 years, 4 months
JBossWeb SVN: r210 - trunk/java/org/apache/comet.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2007-07-31 08:51:22 -0400 (Tue, 31 Jul 2007)
New Revision: 210
Modified:
trunk/java/org/apache/comet/CometEvent.java
Log:
- Clarify the resume method (there's no reason to call it synchronously, of course).
Modified: trunk/java/org/apache/comet/CometEvent.java
===================================================================
--- trunk/java/org/apache/comet/CometEvent.java 2007-07-31 00:06:49 UTC (rev 209)
+++ trunk/java/org/apache/comet/CometEvent.java 2007-07-31 12:51:22 UTC (rev 210)
@@ -182,6 +182,7 @@
* some asynchronous processing is done). This also resumes read events
* if they have been disabled using suspend. It is then possible to call suspend
* again later. It is also possible to call resume without calling suspend before.
+ * This method must be called asynchronously.
*/
public void resume();
17 years, 4 months
JBossWeb SVN: r209 - trunk/java/org/apache/tomcat/util/net.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2007-07-30 20:06:49 -0400 (Mon, 30 Jul 2007)
New Revision: 209
Modified:
trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
Log:
- Basic bugfixing.
- Support multiple pollers.
Modified: trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
===================================================================
--- trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 2007-07-27 08:35:42 UTC (rev 208)
+++ trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 2007-07-31 00:06:49 UTC (rev 209)
@@ -1225,7 +1225,7 @@
protected SocketInfo info = new SocketInfo();
public SocketList(int size) {
- size = 0;
+ this.size = 0;
pos = 0;
sockets = new long[size];
timeouts = new int[size];
@@ -1234,7 +1234,7 @@
}
public int size() {
- return size;
+ return this.size;
}
public SocketInfo get() {
@@ -1294,6 +1294,11 @@
protected long[] pollers = null;
/**
+ * Actual poller size.
+ */
+ protected int actualPollerSize = 0;
+
+ /**
* Amount of spots left in the poller.
*/
protected int[] pollerSpace = null;
@@ -1357,11 +1362,11 @@
timeouts = new SocketTimeouts(pollerSize);
pool = Pool.create(serverSockPool);
- int size = pollerSize / pollerThreadCount;
- if ((OS.IS_WIN32 || OS.IS_WIN64) && (size > 1024)) {
+ actualPollerSize = pollerSize / pollerThreadCount;
+ if ((OS.IS_WIN32 || OS.IS_WIN64) && (actualPollerSize > 1024)) {
// The maximum per poller to get reasonable performance is 1024
// Adjust poller size so that it won't reach the limit
- size = 1024;
+ actualPollerSize = 1024;
}
int timeout = keepAliveTimeout;
if (timeout < 0) {
@@ -1369,31 +1374,31 @@
}
// FIXME: timeout is useless, look into removing it
- long pollset = allocatePoller(size, pool, timeout);
- if (pollset == 0 && size > 1024) {
- size = 1024;
- pollset = allocatePoller(size, pool, timeout);
+ long pollset = allocatePoller(actualPollerSize, pool, timeout);
+ if (pollset == 0 && actualPollerSize > 1024) {
+ actualPollerSize = 1024;
+ pollset = allocatePoller(actualPollerSize, pool, timeout);
}
if (pollset == 0) {
- size = 62;
- pollset = allocatePoller(size, pool, timeout);
+ actualPollerSize = 62;
+ pollset = allocatePoller(actualPollerSize, pool, timeout);
}
- pollerCount = (pollerSize / pollerThreadCount) / size;
+ pollerCount = (pollerSize / pollerThreadCount) / actualPollerSize;
pollerTime = pollTime / pollerCount;
pollers = new long[pollerCount];
pollers[0] = pollset;
for (int i = 1; i < pollerCount; i++) {
- pollers[i] = allocatePoller(size, pool, timeout);
+ pollers[i] = allocatePoller(actualPollerSize, pool, timeout);
}
pollerSpace = new int[pollerCount];
for (int i = 0; i < pollerCount; i++) {
- pollerSpace[i] = size;
+ pollerSpace[i] = actualPollerSize;
}
- desc = new long[size * 2];
+ desc = new long[actualPollerSize * 2];
keepAliveCount = 0;
addList = new SocketList(pollerSize / pollerThreadCount);
localAddList = new SocketList(pollerSize / pollerThreadCount);
@@ -1471,7 +1476,6 @@
}
}
- // FIXME: Maybe CometPoller extends Poller could make some sense
/**
* 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
@@ -1504,6 +1508,40 @@
}
/**
+ * Add specified socket to one of the pollers.
+ */
+ protected boolean addToPoller(long socket, int events) {
+ int rv = 0;
+ for (int i = 0; i < pollers.length; i++) {
+ if (pollerSpace[i] > 0) {
+ rv = Poll.add(pollers[i], socket, events);
+ if (rv == Status.APR_SUCCESS) {
+ pollerSpace[i]--;
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Remove specified socket from the pollers.
+ */
+ protected boolean removeFromPoller(long socket) {
+ int rv = 0;
+ for (int i = 0; i < pollers.length; i++) {
+ if (pollerSpace[i] < actualPollerSize) {
+ rv = Poll.remove(pollers[i], socket);
+ if (rv != Status.APR_NOTFOUND) {
+ pollerSpace[i]++;
+ break;
+ }
+ }
+ }
+ return (rv == Status.APR_SUCCESS);
+ }
+
+ /**
* The background thread that listens for incoming TCP/IP connections and
* hands them off to an appropriate processor.
*/
@@ -1537,21 +1575,6 @@
// Add sockets which are waiting to the poller
if (addList.size() > 0) {
synchronized (this) {
- /*
- for (int i = (addCount - 1); i >= 0; i--) {
- int rv = Poll.add
- (serverPollset, addS[i], Poll.APR_POLLIN);
- if (rv == Status.APR_SUCCESS) {
- keepAliveCount++;
- } else {
- // Can't do anything: close the socket right away
- if (comet) {
- processSocket(addS[i], SocketStatus.ERROR);
- } else {
- Socket.destroy(addS[i]);
- }
- }
- }*/
// Duplicate to another list, so that the syncing is minimal
addList.duplicate(localAddList);
addList.clear();
@@ -1560,10 +1583,10 @@
while (info != null) {
if (info.read || info.write) {
// Store timeout
- // FIXME: remove sockets from structure when processing them
timeouts.add(info.socket, System.currentTimeMillis() + info.timeout);
- // FIXME: what is the status code if the socket is not present in that poller
- int rv = Poll.remove(pollers[0], info.socket);
+ if (comet) {
+ removeFromPoller(info.socket);
+ }
// Windows only: check status code and loop over the other pollers
int events = 0;
if (info.read) {
@@ -1572,16 +1595,19 @@
if (info.write) {
events = events | Poll.APR_POLLOUT;
}
- // FIXME: need to iterate over the pollers array, iterate over pollers until one is found
- rv = Poll.add(pollers[0], info.socket, events);
- // FIXME: check return value
+ if (!addToPoller(info.socket, events)) {
+ // Can't do anything: close the socket right away
+ if (comet) {
+ processSocket(info.socket, SocketStatus.ERROR);
+ } else {
+ Socket.destroy(info.socket);
+ }
+ }
} else {
// Resume event
timeouts.remove(info.socket);
- // FIXME: what is the status code if the socket is not present in that poller
- int rv = Poll.remove(pollers[0], info.socket);
- // Windows only: check status code and loop over the other pollers
if (comet) {
+ removeFromPoller(info.socket);
processSocket(info.socket, SocketStatus.OPEN_CALLBACK);
} else {
// Should never happen
@@ -1594,49 +1620,57 @@
}
maintainTime += pollTime;
- // Pool for the specified interval
- // FIXME: need to iterate over the pollers array
- int rv = Poll.poll(pollers[0], pollerTime, desc, true);
- if (rv > 0) {
- keepAliveCount -= rv;
- for (int n = 0; n < rv; n++) {
- // Check for failed sockets and hand this socket off to a worker
- if (((desc[n*2] & Poll.APR_POLLHUP) == Poll.APR_POLLHUP)
- || ((desc[n*2] & Poll.APR_POLLERR) == Poll.APR_POLLERR)
- || (comet && (!processSocket(desc[n*2+1], SocketStatus.OPEN_READ)))
- || (!comet && (!processSocket(desc[n*2+1])))) {
- // Close socket and clear pool
- if (comet) {
- processSocket(desc[n*2+1], SocketStatus.DISCONNECT);
- } else {
- Socket.destroy(desc[n*2+1]);
+
+ // Poll for the specified interval
+ for (int i = 0; i < pollers.length; i++) {
+ int rv = 0;
+ // Iterate on each pollers, but no need to poll empty pollers
+ if (pollerSpace[i] < actualPollerSize) {
+ rv = Poll.poll(pollers[i], pollerTime, desc, true);
+ }
+ if (rv > 0) {
+ keepAliveCount -= rv;
+ for (int n = 0; n < rv; n++) {
+ timeouts.remove(desc[n*2+1]);
+ // Check for failed sockets and hand this socket off to a worker
+ if (((desc[n*2] & Poll.APR_POLLHUP) == Poll.APR_POLLHUP)
+ || ((desc[n*2] & Poll.APR_POLLERR) == Poll.APR_POLLERR)
+ || (comet && (!processSocket(desc[n*2+1], SocketStatus.OPEN_READ)))
+ || (!comet && (!processSocket(desc[n*2+1])))) {
+ // Close socket and clear pool
+ if (comet) {
+ processSocket(desc[n*2+1], SocketStatus.DISCONNECT);
+ } else {
+ Socket.destroy(desc[n*2+1]);
+ }
+ continue;
}
+ }
+ } else if (rv < 0) {
+ int errn = -rv;
+ /* Any non timeup or interrupted error is critical */
+ if ((errn != Status.TIMEUP) && (errn != Status.EINTR)) {
+ if (errn > Status.APR_OS_START_USERERR) {
+ errn -= Status.APR_OS_START_USERERR;
+ }
+ log.error(sm.getString("endpoint.poll.fail", "" + errn, Error.strerror(errn)));
+ // Handle poll critical failure
+ synchronized (this) {
+ destroy();
+ init();
+ }
continue;
}
}
- } else if (rv < 0) {
- int errn = -rv;
- /* Any non timeup or interrupted error is critical */
- if ((errn != Status.TIMEUP) && (errn != Status.EINTR)) {
- if (errn > Status.APR_OS_START_USERERR) {
- errn -= Status.APR_OS_START_USERERR;
- }
- log.error(sm.getString("endpoint.poll.fail", "" + errn, Error.strerror(errn)));
- // Handle poll critical failure
- synchronized (this) {
- destroy();
- init();
- }
- continue;
- }
}
+
+ // Process socket timeouts
if (soTimeout > 0 && maintainTime > 1000000L && running) {
maintainTime = 0;
long date = System.currentTimeMillis();
long socket = timeouts.check(date);
while (socket != 0) {
- // FIXME: what is the status code if the socket is not present in that poller
- rv = Poll.remove(pollers[0], socket);
+ removeFromPoller(socket);
if (comet) {
processSocket(socket, SocketStatus.TIMEOUT);
} else {
@@ -1645,6 +1679,7 @@
socket = timeouts.check(date);
}
}
+
} catch (Throwable t) {
log.error(sm.getString("endpoint.poll.error"), t);
}
17 years, 4 months
JBossWeb SVN: r208 - trunk.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-07-27 04:35:42 -0400 (Fri, 27 Jul 2007)
New Revision: 208
Modified:
trunk/build.xml
Log:
Add juli to the servlets-php.jar for the log stuff.
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2007-07-27 08:12:12 UTC (rev 207)
+++ trunk/build.xml 2007-07-27 08:35:42 UTC (rev 208)
@@ -284,6 +284,7 @@
<jar jarfile="${tomcat.build}/lib/servlets-php.jar" index="true">
<fileset dir="${tomcat.classes}">
<include name="org/jboss/web/php/**" />
+ <include name="org/apache/juli/**" />
<!-- Javadoc and i18n exclusions -->
<exclude name="**/package.html" />
<exclude name="**/LocalStrings_*" />
17 years, 5 months
JBossWeb SVN: r207 - trunk/java/org/jboss/web/php.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-07-27 04:12:12 -0400 (Fri, 27 Jul 2007)
New Revision: 207
Modified:
trunk/java/org/jboss/web/php/Constants.java
Log:
Correct the package name.
Modified: trunk/java/org/jboss/web/php/Constants.java
===================================================================
--- trunk/java/org/jboss/web/php/Constants.java 2007-07-26 15:16:35 UTC (rev 206)
+++ trunk/java/org/jboss/web/php/Constants.java 2007-07-27 08:12:12 UTC (rev 207)
@@ -32,6 +32,6 @@
*/
public class Constants {
- public static final String Package = "org.apache.catalina.servlets.php";
+ public static final String Package = "org.jboss.web.php";
}
17 years, 5 months
JBossWeb SVN: r206 - in trunk: java/org/jboss/web/php and 1 other directory.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-07-26 11:16:35 -0400 (Thu, 26 Jul 2007)
New Revision: 206
Modified:
trunk/build.xml
trunk/java/org/jboss/web/php/LifecycleListener.java
Log:
Arrange the pacakge and add the jar file in the build.xml
bump the php version to the lastest.
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2007-07-24 00:18:10 UTC (rev 205)
+++ trunk/build.xml 2007-07-26 15:16:35 UTC (rev 206)
@@ -280,6 +280,16 @@
</fileset>
</jar>
+ <!-- JBoss Web - PHP Servlet -->
+ <jar jarfile="${tomcat.build}/lib/servlets-php.jar" index="true">
+ <fileset dir="${tomcat.classes}">
+ <include name="org/jboss/web/php/**" />
+ <!-- Javadoc and i18n exclusions -->
+ <exclude name="**/package.html" />
+ <exclude name="**/LocalStrings_*" />
+ </fileset>
+ </jar>
+
</target>
<target name="build-docs">
Modified: trunk/java/org/jboss/web/php/LifecycleListener.java
===================================================================
--- trunk/java/org/jboss/web/php/LifecycleListener.java 2007-07-24 00:18:10 UTC (rev 205)
+++ trunk/java/org/jboss/web/php/LifecycleListener.java 2007-07-26 15:16:35 UTC (rev 206)
@@ -53,8 +53,8 @@
protected static final int REQUIRED_MAJOR = 5;
- protected static final int REQUIRED_MINOR = 1;
- protected static final int REQUIRED_PATCH = 0;
+ protected static final int REQUIRED_MINOR = 2;
+ protected static final int REQUIRED_PATCH = 3;
// ---------------------------------------------- LifecycleListener Methods
@@ -77,7 +77,7 @@
paramTypes[0] = String.class;
Object paramValues[] = new Object[1];
paramValues[0] = null;
- Class clazz = Class.forName("org.apache.catalina.servlets.php.Library");
+ Class clazz = Class.forName("org.jboss.web.php.Library");
Method method = clazz.getMethod(methodName, paramTypes);
// TODO: Use sm to obtain optional library name.
method.invoke(null, paramValues);
@@ -108,7 +108,7 @@
else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
try {
String methodName = "terminate";
- Method method = Class.forName("org.apache.catalina.servlets.php.Library")
+ Method method = Class.forName("org.jboss.php.servlets.php.Library")
.getMethod(methodName, (Class [])null);
method.invoke(null, (Object []) null);
}
17 years, 5 months
JBossWeb SVN: r205 - trunk/java/org/apache/tomcat/util/net.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2007-07-23 20:18:10 -0400 (Mon, 23 Jul 2007)
New Revision: 205
Modified:
trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
Log:
- Working draft for new Comet implementation.
- Add write polling.
- Per connection timeout value, and stop using Poll.maintain.
- New multiple poller algorithm, which may or may not be faster, but is needed when using Comet.
- More work to do for Windows (where multiple pollers must be used). In particular status codes when
removing are needed.
- New structures for per socket timeouts, socket add list.
- The HTTP connector itself is missing the setTimeout calls for switching to non blocking and back.
- Not tested at all.
Modified: trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
===================================================================
--- trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 2007-07-19 16:02:38 UTC (rev 204)
+++ trunk/java/org/apache/tomcat/util/net/AprEndpoint.java 2007-07-24 00:18:10 UTC (rev 205)
@@ -343,6 +343,8 @@
*/
protected Poller[] pollers = null;
protected int pollerRoundRobin = 0;
+ // FIXME: due to Comet and the socket state, getPoller should accept the socket as an argument,
+ // or (better) a getPoller(long socket) should be added for cases that need it
public Poller getPoller() {
pollerRoundRobin = (pollerRoundRobin + 1) % pollers.length;
return pollers[pollerRoundRobin];
@@ -632,6 +634,9 @@
acceptorThreadCount = 1;
}
if (pollerThreadCount == 0) {
+ // FIXME: Default to one per CPU ?
+ pollerThreadCount = 1;
+ /*
if ((OS.IS_WIN32 || OS.IS_WIN64) && (pollerSize > 1024)) {
// The maximum per poller to get reasonable performance is 1024
pollerThreadCount = pollerSize / 1024;
@@ -639,10 +644,14 @@
pollerSize = pollerSize - (pollerSize % 1024);
} else {
// No explicit poller size limitation
+ // FIXME: Default to one per CPU ?
pollerThreadCount = 1;
- }
+ }*/
}
if (sendfileThreadCount == 0) {
+ // FIXME: Default to one per CPU ?
+ sendfileThreadCount = 1;
+ /*
if ((OS.IS_WIN32 || OS.IS_WIN64) && (sendfileSize > 1024)) {
// The maximum per poller to get reasonable performance is 1024
sendfileThreadCount = sendfileSize / 1024;
@@ -652,7 +661,7 @@
// No explicit poller size limitation
// FIXME: Default to one per CPU ?
sendfileThreadCount = 1;
- }
+ }*/
}
// Delay accepting of new connections until data is available
@@ -725,14 +734,6 @@
workers = new WorkerStack(maxThreads);
}
- // Start acceptor threads
- for (int i = 0; i < acceptorThreadCount; i++) {
- Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i);
- acceptorThread.setPriority(threadPriority);
- acceptorThread.setDaemon(daemon);
- acceptorThread.start();
- }
-
// Start poller threads
pollers = new Poller[pollerThreadCount];
for (int i = 0; i < pollerThreadCount; i++) {
@@ -767,6 +768,15 @@
sendfileThread.start();
}
}
+
+ // Start acceptor threads
+ for (int i = 0; i < acceptorThreadCount; i++) {
+ Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i);
+ acceptorThread.setPriority(threadPriority);
+ acceptorThread.setDaemon(daemon);
+ acceptorThread.start();
+ }
+
}
}
@@ -1125,6 +1135,151 @@
}
+ // ------------------------------------------------- SocketInfo Inner Class
+
+
+ /**
+ * Socket list class, used to avoid using a possibly large amount of objects
+ * with very little actual use.
+ */
+ public class SocketInfo {
+ public long socket;
+ public int timeout;
+ public boolean read;
+ public boolean write;
+
+ }
+
+
+ // --------------------------------------------- SocketTimeouts Inner Class
+
+
+ /**
+ * Socket list class, used to avoid using a possibly large amount of objects
+ * with very little actual use.
+ */
+ public class SocketTimeouts {
+ protected int size;
+
+ protected long[] sockets;
+ protected long[] timeouts;
+ protected int pos = 0;
+
+ public SocketTimeouts(int size) {
+ this.size = 0;
+ sockets = new long[size];
+ timeouts = new long[size];
+ }
+
+ public void add(long socket, long timeout) {
+ sockets[size] = socket;
+ timeouts[size] = timeout;
+ size++;
+ }
+
+ public void remove(long socket) {
+ for (int i = 0; i < size; i++) {
+ if (sockets[i] == socket) {
+ sockets[i] = sockets[size - 1];
+ timeouts[i] = timeouts[size - 1];
+ size--;
+ break;
+ }
+ }
+ }
+
+ public long check(long date) {
+ while (pos < size) {
+ if (date > timeouts[pos]) {
+ long result = sockets[pos];
+ sockets[pos] = sockets[size - 1];
+ timeouts[pos] = timeouts[size - 1];
+ size--;
+ return result;
+ }
+ pos++;
+ }
+ pos = 0;
+ return 0;
+ }
+
+ }
+
+
+ // ------------------------------------------------- SocketList Inner Class
+
+
+ /**
+ * Socket list class, used to avoid using a possibly large amount of objects
+ * with very little actual use.
+ */
+ public class SocketList {
+ protected int size;
+ protected int pos;
+
+ protected long[] sockets;
+ protected int[] timeouts;
+ protected boolean[] reads;
+ protected boolean[] writes;
+
+ protected SocketInfo info = new SocketInfo();
+
+ public SocketList(int size) {
+ size = 0;
+ pos = 0;
+ sockets = new long[size];
+ timeouts = new int[size];
+ reads = new boolean[size];
+ writes = new boolean[size];
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public SocketInfo get() {
+ if (pos == size) {
+ return null;
+ } else {
+ info.socket = sockets[pos];
+ info.timeout = timeouts[pos];
+ info.read = reads[pos];
+ info.write = writes[pos];
+ pos++;
+ return info;
+ }
+ }
+
+ public void clear() {
+ size = 0;
+ pos = 0;
+ }
+
+ public boolean add(long socket, int timeout, boolean read, boolean write) {
+ if (size == sockets.length) {
+ return false;
+ } else {
+ sockets[size] = socket;
+ timeouts[size] = timeout;
+ reads[size] = read;
+ writes[size] = write;
+ size++;
+ return true;
+ }
+ }
+
+ public void duplicate(SocketList copy) {
+ copy.size = size;
+ copy.pos = pos;
+ System.arraycopy(sockets, 0, copy.sockets, 0, size);
+ System.arraycopy(timeouts, 0, copy.timeouts, 0, size);
+ System.arraycopy(reads, 0, copy.reads, 0, size);
+ System.arraycopy(writes, 0, copy.writes, 0, size);
+ }
+
+ }
+
+
// ----------------------------------------------------- Poller Inner Class
@@ -1133,15 +1288,59 @@
*/
public class Poller implements Runnable {
- protected long serverPollset = 0;
+ /**
+ * Pointers to the pollers.
+ */
+ protected long[] pollers = null;
+
+ /**
+ * Amount of spots left in the poller.
+ */
+ protected int[] pollerSpace = null;
+
+ /**
+ * Amount of low level pollers in use by this poller.
+ */
+ protected int pollerCount;
+
+ /**
+ * Timeout value for the poll call.
+ */
+ protected int pollerTime;
+
+ /**
+ * Root pool.
+ */
protected long pool = 0;
+
+ /**
+ * Socket descriptors.
+ */
protected long[] desc;
- protected long[] addS;
- protected int addCount = 0;
-
+ /**
+ * List of sockets to be added to the poller.
+ */
+ protected SocketList addList = null;
+
+ /**
+ * List of sockets to be added to the poller.
+ */
+ protected SocketList localAddList = null;
+
+ /**
+ * Comet mode flag.
+ */
protected boolean comet = true;
+ /**
+ * Structure used for storing timeouts.
+ */
+ protected SocketTimeouts timeouts = null;
+
+ /**
+ * Amount of kept alive connections inside this poller.
+ */
protected int keepAliveCount = 0;
public int getKeepAliveCount() { return keepAliveCount; }
@@ -1154,33 +1353,59 @@
* be 62 (recompiling APR is necessary to remove this limitation).
*/
protected void init() {
+
+ timeouts = new SocketTimeouts(pollerSize);
+
pool = Pool.create(serverSockPool);
int size = pollerSize / pollerThreadCount;
+ if ((OS.IS_WIN32 || OS.IS_WIN64) && (size > 1024)) {
+ // The maximum per poller to get reasonable performance is 1024
+ // Adjust poller size so that it won't reach the limit
+ size = 1024;
+ }
int timeout = keepAliveTimeout;
if (timeout < 0) {
timeout = soTimeout;
}
- serverPollset = allocatePoller(size, pool, timeout);
- if (serverPollset == 0 && size > 1024) {
+
+ // FIXME: timeout is useless, look into removing it
+ long pollset = allocatePoller(size, pool, timeout);
+ if (pollset == 0 && size > 1024) {
size = 1024;
- serverPollset = allocatePoller(size, pool, timeout);
+ pollset = allocatePoller(size, pool, timeout);
}
- if (serverPollset == 0) {
+ if (pollset == 0) {
size = 62;
- serverPollset = allocatePoller(size, pool, timeout);
+ pollset = allocatePoller(size, pool, timeout);
}
+
+ pollerCount = (pollerSize / pollerThreadCount) / size;
+ pollerTime = pollTime / pollerCount;
+
+ pollers = new long[pollerCount];
+ pollers[0] = pollset;
+ for (int i = 1; i < pollerCount; i++) {
+ pollers[i] = allocatePoller(size, pool, timeout);
+ }
+
+ pollerSpace = new int[pollerCount];
+ for (int i = 0; i < pollerCount; i++) {
+ pollerSpace[i] = size;
+ }
+
desc = new long[size * 2];
keepAliveCount = 0;
- addS = new long[size];
- addCount = 0;
+ addList = new SocketList(pollerSize / pollerThreadCount);
+ localAddList = new SocketList(pollerSize / pollerThreadCount);
+
}
/**
* Destroy the poller.
*/
protected void destroy() {
- // Wait for polltime before doing anything, so that the poller threads
- // exit, otherwise parallel descturction of sockets which are still
+ // Wait for pollerTime before doing anything, so that the poller threads
+ // exit, otherwise parallel destruction of sockets which are still
// in the poller can cause problems
try {
synchronized (this) {
@@ -1190,27 +1415,31 @@
// Ignore
}
// Close all sockets in the add queue
- for (int i = 0; i < addCount; i++) {
+ SocketInfo info = addList.get();
+ while (info != null) {
if (comet) {
- processSocket(addS[i], SocketStatus.STOP);
+ processSocket(info.socket, SocketStatus.STOP);
} else {
- Socket.destroy(addS[i]);
+ Socket.destroy(info.socket);
}
+ info = addList.get();
}
+ addList.clear();
// Close all sockets still in the poller
- int rv = Poll.pollset(serverPollset, desc);
- if (rv > 0) {
- for (int n = 0; n < rv; n++) {
- if (comet) {
- processSocket(desc[n*2+1], SocketStatus.STOP);
- } else {
- Socket.destroy(desc[n*2+1]);
+ for (int i = 0; i < pollerCount; i++) {
+ int rv = Poll.pollset(pollers[i], desc);
+ if (rv > 0) {
+ for (int n = 0; n < rv; n++) {
+ if (comet) {
+ processSocket(desc[n*2+1], SocketStatus.STOP);
+ } else {
+ Socket.destroy(desc[n*2+1]);
+ }
}
}
}
Pool.destroy(pool);
keepAliveCount = 0;
- addCount = 0;
}
/**
@@ -1222,10 +1451,14 @@
* @param socket to add to the poller
*/
public void add(long socket) {
+ int timeout = keepAliveTimeout;
+ if (timeout < 0) {
+ timeout = soTimeout;
+ }
synchronized (this) {
// Add socket to the list. Newly added sockets will wait
// at most for pollTime before being polled
- if (addCount >= addS.length) {
+ if (!addList.add(socket, timeout, true, false)) {
// Can't do anything: close the socket right away
if (comet) {
processSocket(socket, SocketStatus.ERROR);
@@ -1234,8 +1467,6 @@
}
return;
}
- addS[addCount] = socket;
- addCount++;
this.notify();
}
}
@@ -1256,12 +1487,10 @@
* @param write to do write polling
*/
public void add(long socket, int timeout, boolean read, boolean write) {
- // FIXME: Implement. At the moment, no support for both read and write polling, although
- // there's no problem in theory.
synchronized (this) {
// Add socket to the list. Newly added sockets will wait
// at most for pollTime before being polled
- if (addCount >= addS.length) {
+ if (!addList.add(socket, timeout, read, write)) {
// Can't do anything: close the socket right away
if (comet) {
processSocket(socket, SocketStatus.ERROR);
@@ -1270,8 +1499,6 @@
}
return;
}
- addS[addCount] = socket;
- addCount++;
this.notify();
}
}
@@ -1294,7 +1521,7 @@
}
}
- while (keepAliveCount < 1 && addCount < 1) {
+ while (keepAliveCount < 1 && addList.size() < 1) {
// Reset maintain time.
maintainTime = 0;
try {
@@ -1308,8 +1535,9 @@
try {
// Add sockets which are waiting to the poller
- if (addCount > 0) {
+ if (addList.size() > 0) {
synchronized (this) {
+ /*
for (int i = (addCount - 1); i >= 0; i--) {
int rv = Poll.add
(serverPollset, addS[i], Poll.APR_POLLIN);
@@ -1323,19 +1551,56 @@
Socket.destroy(addS[i]);
}
}
+ }*/
+ // Duplicate to another list, so that the syncing is minimal
+ addList.duplicate(localAddList);
+ addList.clear();
+ }
+ SocketInfo info = localAddList.get();
+ while (info != null) {
+ if (info.read || info.write) {
+ // Store timeout
+ // FIXME: remove sockets from structure when processing them
+ timeouts.add(info.socket, System.currentTimeMillis() + info.timeout);
+ // FIXME: what is the status code if the socket is not present in that poller
+ int rv = Poll.remove(pollers[0], info.socket);
+ // Windows only: check status code and loop over the other pollers
+ int events = 0;
+ if (info.read) {
+ events = Poll.APR_POLLIN;
+ }
+ if (info.write) {
+ events = events | Poll.APR_POLLOUT;
+ }
+ // FIXME: need to iterate over the pollers array, iterate over pollers until one is found
+ rv = Poll.add(pollers[0], info.socket, events);
+ // FIXME: check return value
+ } else {
+ // Resume event
+ timeouts.remove(info.socket);
+ // FIXME: what is the status code if the socket is not present in that poller
+ int rv = Poll.remove(pollers[0], info.socket);
+ // Windows only: check status code and loop over the other pollers
+ if (comet) {
+ processSocket(info.socket, SocketStatus.OPEN_CALLBACK);
+ } else {
+ // Should never happen
+ // FIXME: ISE ?
+ Socket.destroy(info.socket);
+ }
}
- addCount = 0;
+ info = localAddList.get();
}
}
maintainTime += pollTime;
// Pool for the specified interval
- int rv = Poll.poll(serverPollset, pollTime, desc, true);
+ // FIXME: need to iterate over the pollers array
+ int rv = Poll.poll(pollers[0], pollerTime, desc, true);
if (rv > 0) {
keepAliveCount -= rv;
for (int n = 0; n < rv; n++) {
// Check for failed sockets and hand this socket off to a worker
- System.out.println("Desc: " + desc[n*2]);
if (((desc[n*2] & Poll.APR_POLLHUP) == Poll.APR_POLLHUP)
|| ((desc[n*2] & Poll.APR_POLLERR) == Poll.APR_POLLERR)
|| (comet && (!processSocket(desc[n*2+1], SocketStatus.OPEN_READ)))
@@ -1366,18 +1631,18 @@
}
}
if (soTimeout > 0 && maintainTime > 1000000L && running) {
- rv = Poll.maintain(serverPollset, desc, true);
maintainTime = 0;
- if (rv > 0) {
- keepAliveCount -= rv;
- for (int n = 0; n < rv; n++) {
- // Close socket and clear pool
- if (comet) {
- processSocket(desc[n], SocketStatus.TIMEOUT);
- } else {
- Socket.destroy(desc[n]);
- }
+ long date = System.currentTimeMillis();
+ long socket = timeouts.check(date);
+ while (socket != 0) {
+ // FIXME: what is the status code if the socket is not present in that poller
+ rv = Poll.remove(pollers[0], socket);
+ if (comet) {
+ processSocket(socket, SocketStatus.TIMEOUT);
+ } else {
+ Socket.destroy(socket);
}
+ socket = timeouts.check(date);
}
}
} catch (Throwable t) {
17 years, 5 months
JBossWeb SVN: r204 - trunk/java/org/apache/catalina/valves.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2007-07-19 12:02:38 -0400 (Thu, 19 Jul 2007)
New Revision: 204
Added:
trunk/java/org/apache/catalina/valves/SSLValve.java
Log:
- Add SSL valve (WIP).
Added: trunk/java/org/apache/catalina/valves/SSLValve.java
===================================================================
--- trunk/java/org/apache/catalina/valves/SSLValve.java (rev 0)
+++ trunk/java/org/apache/catalina/valves/SSLValve.java 2007-07-19 16:02:38 UTC (rev 204)
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.catalina.valves;
+
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+
+import javax.servlet.ServletException;
+
+import org.apache.catalina.valves.ValveBase;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.catalina.util.StringManager;
+
+/*
+ * Valve to fill the SSL informations in the request
+ * mod_header is used to fill the headers and the valve
+ * will fill the parameters of the request.
+ * In httpd.conf add the following:
+ * <IfModule ssl_module>
+ * RequestHeader set SSL_CLIENT_CERT "%{SSL_CLIENT_CERT}s"
+ * RequestHeader set SSL_CIPHER "%{SSL_CIPHER}s"
+ * RequestHeader set SSL_SESSION_ID "%{SSL_SESSION_ID}s"
+ * RequestHeader set SSL_CIPHER_USEKEYSIZE "%{SSL_CIPHER_USEKEYSIZE}s"
+ * </IfModule>
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $
+ */
+
+public class SSLValve
+ extends ValveBase {
+/*
+ private static final String info =
+ "SSLValve/1.0";
+ protected static StringManager sm =
+ StringManager.getManager(Constants.Package);
+ public String getInfo() {
+ return (info);
+ }
+ public String toString() {
+ StringBuffer sb = new StringBuffer("SSLValve[");
+ if (container != null)
+ sb.append(container.getName());
+ sb.append("]");
+ return (sb.toString());
+ }
+ */
+ public String mygetHeader(Request request, String header) {
+ String strcert0 = request.getHeader(header);
+ if (strcert0 == null)
+ return null;
+ /* mod_header writes "(null)" when the ssl variable is no filled */
+ if ("(null)".equals(strcert0))
+ return null;
+ return strcert0;
+ }
+ public void invoke(Request request, Response response)
+ throws IOException, ServletException {
+
+ /* mod_header converts the '\n' into ' ' so we have to rebuild the client certificate */
+ String strcert0 = mygetHeader(request, "ssl_client_cert");
+ if (strcert0 != null && strcert0.length()>28) {
+ String strcert1 = strcert0.replace(' ', '\n');
+ String strcert2 = strcert1.substring(28, strcert1.length()-26);
+ String strcert3 = new String("-----BEGIN CERTIFICATE-----\n");
+ String strcert4 = strcert3.concat(strcert2);
+ String strcerts = strcert4.concat("\n-----END CERTIFICATE-----\n");
+ // ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes("UTF-8"));
+ ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes());
+ X509Certificate jsseCerts[] = null;
+ try {
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ X509Certificate cert = (X509Certificate) cf.generateCertificate(bais);
+ jsseCerts = new X509Certificate[1];
+ jsseCerts[0] = cert;
+ } catch (java.security.cert.CertificateException e) {
+ System.out.println("SSLValve failed " + strcerts);
+ System.out.println("SSLValve failed " + e);
+ }
+ request.setAttribute("javax.servlet.request.X509Certificate", jsseCerts);
+ }
+ strcert0 = mygetHeader(request, "ssl_cipher");
+ if (strcert0 != null) {
+ request.setAttribute("javax.servlet.request.cipher_suite", strcert0);
+ }
+ strcert0 = mygetHeader(request, "ssl_session_id");
+ if (strcert0 != null) {
+ request.setAttribute("javax.servlet.request.ssl_session", strcert0);
+ }
+ strcert0 = mygetHeader(request, "ssl_cipher_usekeysize");
+ if (strcert0 != null) {
+ request.setAttribute("javax.servlet.request.key_size", strcert0);
+ }
+ getNext().invoke(request, response);
+ }
+}
Property changes on: trunk/java/org/apache/catalina/valves/SSLValve.java
___________________________________________________________________
Name: svn:eol-style
+ native
17 years, 5 months
JBossWeb SVN: r203 - trunk/bin.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-07-19 03:29:13 -0400 (Thu, 19 Jul 2007)
New Revision: 203
Modified:
trunk/bin/catalina.sh
trunk/bin/digest.sh
trunk/bin/setclasspath.sh
trunk/bin/shutdown.sh
trunk/bin/startup.sh
trunk/bin/tool-wrapper.sh
trunk/bin/version.sh
Log:
Put the right permissions on the files.
Property changes on: trunk/bin/catalina.sh
___________________________________________________________________
Name: svn:executable
+ *
Property changes on: trunk/bin/digest.sh
___________________________________________________________________
Name: svn:executable
+ *
Property changes on: trunk/bin/setclasspath.sh
___________________________________________________________________
Name: svn:executable
+ *
Property changes on: trunk/bin/shutdown.sh
___________________________________________________________________
Name: svn:executable
+ *
Property changes on: trunk/bin/startup.sh
___________________________________________________________________
Name: svn:executable
+ *
Property changes on: trunk/bin/tool-wrapper.sh
___________________________________________________________________
Name: svn:executable
+ *
Property changes on: trunk/bin/version.sh
___________________________________________________________________
Name: svn:executable
+ *
17 years, 5 months
JBossWeb SVN: r202 - trunk/java/org/apache/comet.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2007-07-18 23:01:32 -0400 (Wed, 18 Jul 2007)
New Revision: 202
Modified:
trunk/java/org/apache/comet/CometEvent.java
Log:
- Another small javadoc improvement.
Modified: trunk/java/org/apache/comet/CometEvent.java
===================================================================
--- trunk/java/org/apache/comet/CometEvent.java 2007-07-19 03:00:49 UTC (rev 201)
+++ trunk/java/org/apache/comet/CometEvent.java 2007-07-19 03:01:32 UTC (rev 202)
@@ -142,8 +142,7 @@
/**
* This method sets the timeout in milliseconds of idle time on the connection.
- * The timeout is reset every time data is received from the connection or data is flushed
- * using <code>response.flushBuffer()</code>. If a timeout occurs, the
+ * The timeout is reset every time data is received from the connection. If a timeout occurs, the
* servlet will receive an ERROR/TIMEOUT event which will not result in automatically closing
* the event (the event may be closed using the close() method).
*
17 years, 5 months