ips++;
}
}
}
}catch( Throwable e ){
Logger.log(new LogEvent(LOGID, "", e));
}
if ( ips > 1 ){
filter_override = true;
use_filter = true;
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID,
"ClientIDManager: overriding filter "
+ "option to support local bind IP"));
}
}
}
if ( use_filter ){
try{
thread_pool = new ThreadPool( "ClientIDManager", 32 );
String connect_timeout = System.getProperty("sun.net.client.defaultConnectTimeout");
String read_timeout = System.getProperty("sun.net.client.defaultReadTimeout");
int timeout = Integer.parseInt( connect_timeout ) + Integer.parseInt( read_timeout );
thread_pool.setExecutionLimit( timeout );
final ServerSocket ss = new ServerSocket( 0, 1024, InetAddress.getByName("127.0.0.1"));
filter_port = ss.getLocalPort();
ss.setReuseAddress(true);
Thread accept_thread =
new AEThread("ClientIDManager::filterloop")
{
public void
runSupport()
{
long successfull_accepts = 0;
long failed_accepts = 0;
while(true){
try{
Socket socket = ss.accept();
successfull_accepts++;
thread_pool.run( new httpFilter( socket ));
}catch( Throwable e ){
failed_accepts++;
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID,
"ClientIDManager: listener failed on port "
+ filter_port, e ));
if ( failed_accepts > 100 && successfull_accepts == 0 ){
// looks like its not going to work...
// some kind of socket problem
Logger.logTextResource(new LogAlert(LogAlert.UNREPEATABLE,
LogAlert.AT_ERROR, "Network.alert.acceptfail"),
new String[] { "" + filter_port, "TCP" });
use_filter = false;
break;
}
}
}
}
};
accept_thread.setDaemon( true );
accept_thread.start();
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID,
"ClientIDManager: listener established on port " + filter_port));
}catch( Throwable e){
Logger.logTextResource(new LogAlert(LogAlert.UNREPEATABLE,
LogAlert.AT_ERROR, "Tracker.alert.listenfail"), new String[] { ""
+ filter_port });
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID,
"ClientIDManager: listener failed on port " + filter_port, e));
use_filter = false;
}
}