/* ------------------------------------------------------------ */ protected void configure(Socket socket) throws IOException { try { socket.setTcpNoDelay(true); if (_maxIdleTime >= 0) socket.setSoTimeout(_maxIdleTime); if (_soLingerTime >= 0) socket.setSoLinger(true, _soLingerTime / 1000); else socket.setSoLinger(false, 0); } catch (Exception e) { Log.ignore(e); } }
/* ------------------------------------------------------------ */ protected boolean checkConnection() { super.checkConnection(); try { if (_jarConnection != _connection) newConnection(); } catch (IOException e) { Log.ignore(e); _jarConnection = null; } return _jarConnection != null; }
/* ------------------------------------------------------------ */ public void run() { Thread current = Thread.currentThread(); String name; synchronized (AbstractConnector.this) { if (_acceptorThread == null) return; _acceptorThread[_acceptor] = current; name = _acceptorThread[_acceptor].getName(); current.setName(name + " - Acceptor" + _acceptor + " " + AbstractConnector.this); } int old_priority = current.getPriority(); try { current.setPriority(old_priority - _acceptorPriorityOffset); while (isRunning() && getConnection() != null) { try { accept(_acceptor); } catch (EofException e) { Log.ignore(e); } catch (IOException e) { Log.ignore(e); } catch (ThreadDeath e) { throw e; } catch (Throwable e) { Log.warn(e); } } } finally { current.setPriority(old_priority); current.setName(name); try { if (_acceptor == 0) close(); } catch (IOException e) { Log.warn(e); } synchronized (AbstractConnector.this) { if (_acceptorThread != null) _acceptorThread[_acceptor] = null; } } }
/* ------------------------------------------------------------ */ public void accept(int acceptorID) throws IOException { try { // TODO - this may not exactly be right. accept is called in a loop, so we // may need to wait on the _selectorThread somehow? // maybe we just set acceptors to zero and don't need to bother here as // grizzly has it's own accepting threads. if (controller.isStarted()) { Thread.sleep(5000); } } catch (Throwable e) { // TODO Auto-generated catch block Log.ignore(e); } }
/* ------------------------------------------------------------ */ protected void checkForwardedHeaders(EndPoint endpoint, Request request) throws IOException { HttpFields httpFields = request.getConnection().getRequestFields(); // Retrieving headers from the request String forwardedHost = getLeftMostValue(httpFields.getStringField(getForwardedHostHeader())); String forwardedServer = getLeftMostValue(httpFields.getStringField(getForwardedServerHeader())); String forwardedFor = getLeftMostValue(httpFields.getStringField(getForwardedForHeader())); if (_hostHeader != null) { // Update host header httpFields.put(HttpHeaders.HOST_BUFFER, _hostHeader); request.setServerName(null); request.setServerPort(-1); request.getServerName(); } else if (forwardedHost != null) { // Update host header httpFields.put(HttpHeaders.HOST_BUFFER, forwardedHost); request.setServerName(null); request.setServerPort(-1); request.getServerName(); } else if (forwardedServer != null) { // Use provided server name request.setServerName(forwardedServer); } if (forwardedFor != null) { request.setRemoteAddr(forwardedFor); InetAddress inetAddress = null; if (_useDNS) { try { inetAddress = InetAddress.getByName(forwardedFor); } catch (UnknownHostException e) { Log.ignore(e); } } request.setRemoteHost(inetAddress == null ? forwardedFor : inetAddress.getHostName()); } }