Lines 2251-2333
Link Here
|
2251 |
} |
2251 |
} |
2252 |
|
2252 |
|
2253 |
public void run() { |
2253 |
public void run() { |
2254 |
NioEndpoint.this.activeSocketProcessors.addAndGet(1); |
2254 |
synchronized (socket) { |
2255 |
SelectionKey key = null; |
2255 |
NioEndpoint.this.activeSocketProcessors.addAndGet(1); |
2256 |
try { |
2256 |
SelectionKey key = null; |
2257 |
key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); |
|
|
2258 |
int handshake = -1; |
2259 |
|
2260 |
try { |
2257 |
try { |
2261 |
if (key!=null) handshake = socket.handshake(key.isReadable(), key.isWritable()); |
2258 |
key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); |
2262 |
}catch ( IOException x ) { |
2259 |
int handshake = -1; |
2263 |
handshake = -1; |
2260 |
|
2264 |
if ( log.isDebugEnabled() ) log.debug("Error during SSL handshake",x); |
2261 |
try { |
2265 |
}catch ( CancelledKeyException ckx ) { |
2262 |
if (key!=null) handshake = socket.handshake(key.isReadable(), key.isWritable()); |
2266 |
handshake = -1; |
2263 |
}catch ( IOException x ) { |
2267 |
} |
2264 |
handshake = -1; |
2268 |
if ( handshake == 0 ) { |
2265 |
if ( log.isDebugEnabled() ) log.debug("Error during SSL handshake",x); |
2269 |
// Process the request from this socket |
2266 |
}catch ( CancelledKeyException ckx ) { |
2270 |
boolean closed = (status==null)?(handler.process(socket)==Handler.SocketState.CLOSED) : |
2267 |
handshake = -1; |
2271 |
(handler.event(socket,status)==Handler.SocketState.CLOSED); |
2268 |
} |
2272 |
|
2269 |
if ( handshake == 0 ) { |
2273 |
if (closed) { |
2270 |
// Process the request from this socket |
2274 |
// Close socket and pool |
2271 |
boolean closed = (status==null)?(handler.process(socket)==Handler.SocketState.CLOSED) : |
2275 |
try { |
2272 |
(handler.event(socket,status)==Handler.SocketState.CLOSED); |
2276 |
KeyAttachment ka = null; |
2273 |
|
2277 |
if (key!=null) { |
2274 |
if (closed) { |
2278 |
ka = (KeyAttachment) key.attachment(); |
2275 |
// Close socket and pool |
2279 |
if (ka!=null) ka.setComet(false); |
2276 |
try { |
2280 |
socket.getPoller().cancelledKey(key, SocketStatus.ERROR, false); |
2277 |
KeyAttachment ka = null; |
|
|
2278 |
if (key!=null) { |
2279 |
ka = (KeyAttachment) key.attachment(); |
2280 |
if (ka!=null) ka.setComet(false); |
2281 |
socket.getPoller().cancelledKey(key, SocketStatus.ERROR, false); |
2282 |
} |
2283 |
if (socket!=null) nioChannels.offer(socket); |
2284 |
socket = null; |
2285 |
if ( ka!=null ) keyCache.offer(ka); |
2286 |
ka = null; |
2287 |
}catch ( Exception x ) { |
2288 |
log.error("",x); |
2281 |
} |
2289 |
} |
2282 |
if (socket!=null) nioChannels.offer(socket); |
2290 |
} |
2283 |
socket = null; |
2291 |
} else if (handshake == -1 ) { |
2284 |
if ( ka!=null ) keyCache.offer(ka); |
2292 |
KeyAttachment ka = null; |
2285 |
ka = null; |
2293 |
if (key!=null) { |
2286 |
}catch ( Exception x ) { |
2294 |
ka = (KeyAttachment) key.attachment(); |
2287 |
log.error("",x); |
2295 |
socket.getPoller().cancelledKey(key, SocketStatus.DISCONNECT, false); |
2288 |
} |
2296 |
} |
2289 |
} |
2297 |
if (socket!=null) nioChannels.offer(socket); |
2290 |
} else if (handshake == -1 ) { |
2298 |
socket = null; |
2291 |
KeyAttachment ka = null; |
2299 |
if ( ka!=null ) keyCache.offer(ka); |
2292 |
if (key!=null) { |
2300 |
ka = null; |
2293 |
ka = (KeyAttachment) key.attachment(); |
2301 |
} else { |
2294 |
socket.getPoller().cancelledKey(key, SocketStatus.DISCONNECT, false); |
2302 |
final SelectionKey fk = key; |
|
|
2303 |
final int intops = handshake; |
2304 |
final KeyAttachment ka = (KeyAttachment)fk.attachment(); |
2305 |
ka.getPoller().add(socket,intops); |
2295 |
} |
2306 |
} |
2296 |
if (socket!=null) nioChannels.offer(socket); |
2307 |
}catch(CancelledKeyException cx) { |
|
|
2308 |
socket.getPoller().cancelledKey(key,null,false); |
2309 |
} catch (OutOfMemoryError oom) { |
2310 |
try { |
2311 |
oomParachuteData = null; |
2312 |
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false); |
2313 |
releaseCaches(); |
2314 |
log.error("", oom); |
2315 |
}catch ( Throwable oomt ) { |
2316 |
try { |
2317 |
System.err.println(oomParachuteMsg); |
2318 |
oomt.printStackTrace(); |
2319 |
}catch (Throwable letsHopeWeDontGetHere){} |
2320 |
} |
2321 |
}catch ( Throwable t ) { |
2322 |
log.error("",t); |
2323 |
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false); |
2324 |
} finally { |
2297 |
socket = null; |
2325 |
socket = null; |
2298 |
if ( ka!=null ) keyCache.offer(ka); |
2326 |
status = null; |
2299 |
ka = null; |
2327 |
//return to cache |
2300 |
} else { |
2328 |
processorCache.offer(this); |
2301 |
final SelectionKey fk = key; |
2329 |
NioEndpoint.this.activeSocketProcessors.addAndGet(-1); |
2302 |
final int intops = handshake; |
|
|
2303 |
final KeyAttachment ka = (KeyAttachment)fk.attachment(); |
2304 |
ka.getPoller().add(socket,intops); |
2305 |
} |
2330 |
} |
2306 |
}catch(CancelledKeyException cx) { |
2331 |
} |
2307 |
socket.getPoller().cancelledKey(key,null,false); |
|
|
2308 |
} catch (OutOfMemoryError oom) { |
2309 |
try { |
2310 |
oomParachuteData = null; |
2311 |
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false); |
2312 |
releaseCaches(); |
2313 |
log.error("", oom); |
2314 |
}catch ( Throwable oomt ) { |
2315 |
try { |
2316 |
System.err.println(oomParachuteMsg); |
2317 |
oomt.printStackTrace(); |
2318 |
}catch (Throwable letsHopeWeDontGetHere){} |
2319 |
} |
2320 |
}catch ( Throwable t ) { |
2321 |
log.error("",t); |
2322 |
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false); |
2323 |
} finally { |
2324 |
socket = null; |
2325 |
status = null; |
2326 |
//return to cache |
2327 |
processorCache.offer(this); |
2328 |
NioEndpoint.this.activeSocketProcessors.addAndGet(-1); } |
2329 |
} |
2332 |
} |
2330 |
|
|
|
2331 |
} |
2333 |
} |
2332 |
|
2334 |
|
2333 |
// ---------------------------------------------- TaskQueue Inner Class |
2335 |
// ---------------------------------------------- TaskQueue Inner Class |