try {
// Accept the next incoming connection from the server socket
Socket socket = serverSocketFactory.acceptSocket(serverSocket);
- // Hand this socket off to an appropriate processor
- if (!processSocket(socket)) {
+
+ // Configure the socket
+ if (setSocketOptions(socket)) {
+ // Hand this socket off to an appropriate processor
+ if (!processSocket(socket)) {
+ // Close socket right away
+ try {
+ socket.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ } else {
// Close socket right away
try {
socket.close();
}
SocketState state = SocketState.OPEN;
- // Process the request from this socket
- if ( (!socket.isInitialized()) && (!setSocketOptions(socket.getSocket())) ) {
+
+ try {
+ // SSL handshake
+ serverSocketFactory.handshake(socket.getSocket());
+ } catch (Throwable t) {
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("endpoint.err.handshake"), t);
+ }
+ // Tell to close the socket
state = SocketState.CLOSED;
}
- socket.setInitialized(true);
if ( (state != SocketState.CLOSED) ) {
state = (status==null)?handler.process(socket):handler.process(socket,status);
/**
- * Set the options for the current socket.
+ * Configure the socket.
*/
protected boolean setSocketOptions(Socket socket) {
- // Process the connection
-
+ serverSocketFactory.initSocket(socket);
+
try {
// 1: Set socket options: timeout, linger, etc
socketProperties.setProperties(socket);
// Close the socket
return false;
}
- try {
- // 2: SSL handshake
- serverSocketFactory.handshake(socket);
- } catch (Throwable t) {
- if (log.isDebugEnabled()) {
- log.debug(sm.getString("endpoint.err.handshake"), t);
- }
- // Tell to close the socket
- return false;
- }
return true;
}
-
+
/**
* Process given socket.
*/
protected boolean processSocket(Socket socket) {
- serverSocketFactory.initSocket(socket);
+ // Process the request from this socket
try {
SocketWrapper<Socket> wrapper = new SocketWrapper<Socket>(socket);
wrapper.setKeepAliveLeft(getMaxKeepAliveRequests());
/**
* Stop the endpoint. This will cause all processing threads to stop.
*/
+ @Override
public void stop() {
if (!paused) {
pause();
return selectorPool;
}
+ @Override
public boolean getUseSendfile() {
return useSendfile;
}
//TODO FIXME - this is currently a blocking call, meaning we will be blocking
//further accepts until there is a thread available.
if ( running && (!paused) && socket != null ) {
- //processSocket(socket);
+ // setSocketOptions() will add channel to the poller
+ // if successful
if (!setSocketOptions(socket)) {
try {
socket.socket().close();
protected volatile int keepAliveLeft = 100;
protected boolean async = false;
protected boolean keptAlive = false;
- protected boolean initialized = false;
public AtomicBoolean processing = new AtomicBoolean(false);
public SocketWrapper(E socket) {
public int decrementKeepAlive() { return (--keepAliveLeft);}
public boolean isKeptAlive() {return keptAlive;}
public void setKeptAlive(boolean keptAlive) {this.keptAlive = keptAlive;}
- public boolean isInitialized() {return initialized;}
- public void setInitialized(boolean initialized) {this.initialized = initialized;}
-
}