1 18 package net.sf.drftpd.slave; 19 20 import java.io.IOException ; 21 import java.net.InetSocketAddress ; 22 import java.net.Socket ; 23 import java.net.SocketAddress ; 24 25 import javax.net.SocketFactory; 26 import javax.net.ssl.SSLContext; 27 import javax.net.ssl.SSLSocket; 28 29 import org.apache.log4j.Logger; 30 31 35 public class ActiveConnection extends Connection { 36 private static final Logger logger = 37 Logger.getLogger(ActiveConnection.class); 38 private SSLContext _ctx; 39 private SocketAddress _addr; 40 private Socket _sock; 41 public ActiveConnection(SSLContext ctx, InetSocketAddress addr) { 42 _addr = addr; 43 _ctx = ctx; 44 } 45 46 public Socket connect() throws IOException { 47 if (_ctx != null) { 48 SSLSocket sslsock; 49 sslsock = (SSLSocket) _ctx.getSocketFactory().createSocket(); 50 sslsock.connect(_addr, TIMEOUT); 51 sslsock.setUseClientMode(false); 52 sslsock.startHandshake(); 53 _sock = sslsock; 54 } else { 55 _sock = SocketFactory.getDefault().createSocket(); 56 _sock.connect(_addr, TIMEOUT); 57 } 58 setSockOpts(_sock); 59 Socket sock = _sock; 60 _sock = null; 61 return sock; 62 } 63 64 public void abort() { 65 try { 66 if (_sock != null) 67 _sock.close(); 68 } catch (IOException e) { 69 logger.warn("abort() failed to close() socket", e); 70 } 71 } 72 73 } 74 | Popular Tags |