* connection and put it in conns. When the thread should stop, it is
* interrupted by the thread creator.
*/
public void run() {
Socket client_sock=null;
Connection conn=null;
Address peer_addr;
while(srv_sock != null) {
try {
conn=null;
client_sock=srv_sock.accept();
if(!running) {
if(log.isWarnEnabled())
log.warn("cannot accept connection from " + client_sock.getRemoteSocketAddress() + " as I'm closed");
break;
}
if(log.isTraceEnabled())
log.trace("accepted connection from " + client_sock.getInetAddress() + ":" + client_sock.getPort());
try {
client_sock.setSendBufferSize(send_buf_size);
}
catch(IllegalArgumentException ex) {
if(log.isErrorEnabled()) log.error("exception setting send buffer size to " +
send_buf_size + " bytes", ex);
}
try {
client_sock.setReceiveBufferSize(recv_buf_size);
}
catch(IllegalArgumentException ex) {
if(log.isErrorEnabled()) log.error("exception setting receive buffer size to " +
send_buf_size + " bytes", ex);
}
client_sock.setKeepAlive(true);
client_sock.setTcpNoDelay(tcp_nodelay);
if(linger > 0)
client_sock.setSoLinger(true, linger);
else
client_sock.setSoLinger(false, -1);
// create new thread and add to conn table
conn=new Connection(client_sock, null); // will call receive(msg)
// get peer's address
peer_addr=conn.readPeerAddress(client_sock);
// client_addr=new IpAddress(client_sock.getInetAddress(), client_port);
conn.setPeerAddress(peer_addr);
synchronized(conns) {
Connection tmp=(Connection) conns.get(peer_addr);
//Vladimir Nov, 5th, 2007
//we might have a connection to peer but is that
//connection still open?
boolean connectionOpen = tmp != null && !tmp.isSocketClosed();
if(connectionOpen) {
if(peer_addr.compareTo(local_addr) > 0) {
if(log.isTraceEnabled())
log.trace("peer's address (" + peer_addr + ") is greater than our local address (" +
local_addr + "), replacing our existing connection");