TRTrackerServerUDPpublic class TRTrackerServerUDP extends TRTrackerServerImpl
Fields Summary |
---|
private static final LogIDs | LOGID | private static final int | THREAD_POOL_SIZE | private ThreadPool | thread_pool | private int | port | private DatagramSocket | dg_socket | private volatile boolean | closed |
Constructors Summary |
---|
public TRTrackerServerUDP(String _name, int _port, boolean _start_up_ready)
super( _name, _start_up_ready );
port = _port;
thread_pool = new ThreadPool( "TrackerServer:UDP:"+port, THREAD_POOL_SIZE );
try{
InetAddress bind_ip = NetworkAdmin.getSingleton().getDefaultBindAddress();
InetSocketAddress address;
DatagramSocket socket;
if ( bind_ip == null ){
address = new InetSocketAddress(InetAddress.getByName("127.0.0.1"),port);
socket = new DatagramSocket( port );
}else{
address = new InetSocketAddress( bind_ip, port);
socket = new DatagramSocket(address);
}
socket.setReuseAddress(true);
dg_socket = socket;
final InetSocketAddress f_address = address;
Thread recv_thread =
new AEThread("TRTrackerServerUDP:recv.loop")
{
public void
runSupport()
{
recvLoop( dg_socket, f_address );
}
};
recv_thread.setDaemon( true );
recv_thread.start();
Logger.log(new LogEvent(LOGID,
"TRTrackerServerUDP: recv established on port " + port));
}catch( Throwable e ){
Logger.log(new LogEvent(LOGID, "TRTrackerServerUDP: "
+ "DatagramSocket bind failed on port " + port, e));
}
|
Methods Summary |
---|
public void | addRequestListener(TRTrackerServerRequestListener l)
| protected void | closeSupport()
closed = true;
try{
dg_socket.close();
}catch( Throwable e ){
}
destroySupport();
| public java.lang.String | getHost()
return( COConfigurationManager.getStringParameter( "Tracker IP", "" ));
| public int | getPort()
return( port );
| public boolean | isSSL()
return( false );
| protected void | recvLoop(java.net.DatagramSocket socket, java.net.InetSocketAddress address)
long successful_accepts = 0;
long failed_accepts = 0;
while( !closed ){
try{
byte[] buf = new byte[PRUDPPacket.MAX_PACKET_SIZE];
DatagramPacket packet = new DatagramPacket( buf, buf.length, address );
socket.receive( packet );
successful_accepts++;
failed_accepts = 0;
String ip = packet.getAddress().getHostAddress();
if ( !ip_filter.isInRange( ip, "Tracker", null )){
thread_pool.run( new TRTrackerServerProcessorUDP( this, socket, packet ));
}
}catch( Throwable e ){
if ( !closed ){
failed_accepts++;
Logger.log(new LogEvent(LOGID,
"TRTrackerServer: receive failed on port " + port, e));
if (( failed_accepts > 100 && successful_accepts == 0 ) || failed_accepts > 1000 ){
// 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[] {
"" + port, "UDP" });
break;
}
}
}
}
| public void | removeRequestListener(TRTrackerServerRequestListener l)
|
|