Files
i2p.i2p/apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocketImpl.java

53 lines
1.2 KiB
Java
Raw Normal View History

2004-04-08 04:41:54 +00:00
package net.i2p.client.streaming;
import net.i2p.I2PException;
import net.i2p.util.Log;
/**
* Initial stub implementation for the server socket
*
*/
class I2PServerSocketImpl implements I2PServerSocket {
private final static Log _log = new Log(I2PServerSocketImpl.class);
private I2PSocketManager mgr;
2004-04-10 11:50:11 +00:00
private I2PSocket cached = null; // buffer one socket here
2004-04-08 04:41:54 +00:00
public I2PServerSocketImpl(I2PSocketManager mgr) {
2004-04-10 11:50:11 +00:00
this.mgr = mgr;
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:50:11 +00:00
2004-04-08 04:41:54 +00:00
public synchronized I2PSocket accept() throws I2PException {
2004-04-10 11:50:11 +00:00
while (cached == null) {
myWait();
}
I2PSocket ret = cached;
cached = null;
notifyAll();
_log.debug("TIMING: handed out accept result " + ret.hashCode());
return ret;
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:50:11 +00:00
public synchronized boolean getNewSocket(I2PSocket s) {
while (cached != null) {
myWait();
}
cached = s;
notifyAll();
return true;
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:50:11 +00:00
2004-04-08 04:41:54 +00:00
public void close() throws I2PException {
2004-04-10 11:50:11 +00:00
//noop
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:50:11 +00:00
2004-04-08 04:41:54 +00:00
private void myWait() {
2004-04-10 11:50:11 +00:00
try {
wait();
} catch (InterruptedException ex) {
}
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:50:11 +00:00
public I2PSocketManager getManager() {
return mgr;
}
}