mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Add Java API rebind for mdp sockets
This commit is contained in:
parent
68bd515241
commit
8667060ae0
@ -35,6 +35,15 @@ public abstract class AbstractMdpProtocol<T> extends ChannelSelector.Handler {
|
||||
socket.close();
|
||||
}
|
||||
|
||||
public void rebind() throws IOException {
|
||||
selector.unregister(this);
|
||||
try{
|
||||
socket.rebind();
|
||||
}finally{
|
||||
selector.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void parse(MdpPacket response);
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +51,8 @@ public class MdpSocket{
|
||||
public synchronized void bind(SubscriberId sid, int port) throws IOException {
|
||||
if (loopbackMdpPort==0)
|
||||
throw new IOException("Loopback MDP port has not been set");
|
||||
if (sid==null)
|
||||
throw new NullPointerException();
|
||||
if (sid.equals(this.sid) && this.port == port)
|
||||
return;
|
||||
if (this.sid!=null)
|
||||
@ -80,6 +82,14 @@ public class MdpSocket{
|
||||
this.port = packet.getLocalPort();
|
||||
}
|
||||
|
||||
public void rebind() throws IOException{
|
||||
if (this.sid==null)
|
||||
return;
|
||||
SubscriberId sid = this.sid;
|
||||
this.sid=null;
|
||||
bind(sid, this.port);
|
||||
}
|
||||
|
||||
public SelectableChannel getChannel() throws IOException {
|
||||
if (channel == null){
|
||||
channel = DatagramChannel.open();
|
||||
@ -114,6 +124,7 @@ public class MdpSocket{
|
||||
// ignore errors due to servald stopping.
|
||||
e.printStackTrace();
|
||||
}
|
||||
sid = null;
|
||||
}
|
||||
if (channel!=null){
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user