public void timeout() throws IOException { try { this.sendResponse("421 Timeout waiting for data from client."); } finally { closeConnection(); } }
private void closeConnection() { try { try { this.writer.close(); this.input.close(); } finally { closeSocket(); } } catch (IOException e) { log.debug(e); } }
@Override public int read() throws IOException { int read = super.read(); this.connectionHandler.refreshLastActiveTime(); return read; }
ConnectionHandler connectionHandler = new ConnectionHandler(this, this.serverSocket.accept()); connectionHandler.start();
long lastActiveTime = aThread.getLastActiveTime() + (this.server.connectionTimeout); if (lastActiveTime < System.currentTimeMillis()) aThread.timeout();
public ConnectionHandler(SMTPServer server, Socket socket) throws IOException { super(server.getConnectionGroup(), ConnectionHandler.class.getName()); this.server = server; setSocket(socket); this.startTime = System.currentTimeMillis(); this.lastActiveTime = this.startTime; }
/** * Grabs all ThreadGroup instances of ConnectionHander's and attempts to close the * socket if it is still open. */ protected void shutDownOpenConnections() { Thread[] groupThreads = new Thread[maxConnections]; ThreadGroup connectionGroup = getConnectionGroup(); connectionGroup.enumerate(groupThreads); for (int i=0; i<connectionGroup.activeCount(); i++) { ConnectionHandler handler = ((ConnectionHandler)groupThreads[i]); if (handler != null) { Socket socket = handler.getSocket(); if (socket != null && !socket.isClosed()) { try { socket.close(); } catch (IOException e) { } } } } }
session.setDataMode(true); InputStream stream = context.getConnection().getInput(); stream = new BufferedInputStream(stream); stream = new CharTerminatedInputStream(stream, SMTP_TERMINATOR);
this.sendResponse("554 Transaction failed. Too many connections."); return; this.sendResponse("220 " + this.server.getHostName() + " ESMTP " + this.server.getName()); this.sendResponse(msg); this.sendResponse(msg); this.sendResponse("450 Problem attempting to execute commands. Please try again later."); closeConnection();
@Override public int read(byte[] b, int off, int len) throws IOException { int read = super.read(b, off, len); this.connectionHandler.refreshLastActiveTime(); return read; }
@Override public int read(byte[] b) throws IOException { int read = super.read(b); this.connectionHandler.refreshLastActiveTime(); return read; } }