}
private HttpTunnelPacket waitForPacket(ConnKey connKey, Connection conn) {
Vector pullQ = conn.getPullQ();
int pullPeriod = conn.getPullPeriod();
HttpTunnelPacket p = null;
boolean removeConn = false;
synchronized (pullQ) {
if (pullPeriod > 0) {
if (pullQ.isEmpty()) {
return null; // Don't tie-up web server resources...
}
}
long startTime = System.currentTimeMillis();
long maxwait = MAX_PULL_BLOCK_PERIOD;
while (pullQ.isEmpty() && (linkTableState == RUNNING)) {
try {
pullQ.wait(maxwait);
} catch (Exception e) {
}
maxwait -= (System.currentTimeMillis() - startTime);
if (maxwait <= 0) {
return null;
}
}
if (pullQ.isEmpty()) {
return null;
}
p = (HttpTunnelPacket) pullQ.elementAt(0);
pullQ.removeElementAt(0);
switch (p.getPacketType()) {
case CONN_ABORT_PACKET:
removeConn = true;
pullQ.insertElementAt(p, 0); // Let all threads find the CONN_ABORT_PACKET
pullQ.notifyAll();