Commit 6397111c authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Corrected behavior of PortListener (not critical)

parent bbc87f64
......@@ -240,6 +240,8 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
private final int localPort;
private final ITransProtocol transport;
private TransMessageListener listener;
public ProtocolAdapter(NetID localAddress, int localPort,
ITransProtocol transport) {
......@@ -250,6 +252,7 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
@Override
public void setTransportMessageListener(TransMessageListener listener) {
this.listener = listener;
addTransMsgListener(listener, localPort);
}
......@@ -257,7 +260,9 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
* FIXME add @Override lateron, as soon as the API is updated globally.
*/
public void removeTransportMessageListener() {
removeTransMsgListener(localPort);
assert listener != null;
removeTransMsgListener(listener, localPort);
listener = null;
}
@Override
......@@ -403,9 +408,12 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
pl.addListener(receiver);
}
protected void removeTransMsgListener(int port) {
// assuming there is only one
portListeners.remove(port);
protected void removeTransMsgListener(TransMessageListener listener, int port) {
PortListener pl = portListeners.get(port);
pl.removeListener(listener);
if (pl.isEmpty()) {
portListeners.remove(port);
}
}
@Override
......@@ -527,9 +535,8 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
}
/**
* A very simple data structure to allow multiple Listeners on one port
*
* FIXME why would we need to support more than one listener per port?
* A very simple data structure to allow multiple Listeners on one port (e.g., if TCP and UDP are
* both instantiated on the same port)
*
* @author Bjoern Richerzhagen
* @version 1.0, 07.05.2012
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment