mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-06 11:09:13 +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();
|
socket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void rebind() throws IOException {
|
||||||
|
selector.unregister(this);
|
||||||
|
try{
|
||||||
|
socket.rebind();
|
||||||
|
}finally{
|
||||||
|
selector.register(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract void parse(MdpPacket response);
|
protected abstract void parse(MdpPacket response);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,6 +51,8 @@ public class MdpSocket{
|
|||||||
public synchronized void bind(SubscriberId sid, int port) throws IOException {
|
public synchronized void bind(SubscriberId sid, int port) throws IOException {
|
||||||
if (loopbackMdpPort==0)
|
if (loopbackMdpPort==0)
|
||||||
throw new IOException("Loopback MDP port has not been set");
|
throw new IOException("Loopback MDP port has not been set");
|
||||||
|
if (sid==null)
|
||||||
|
throw new NullPointerException();
|
||||||
if (sid.equals(this.sid) && this.port == port)
|
if (sid.equals(this.sid) && this.port == port)
|
||||||
return;
|
return;
|
||||||
if (this.sid!=null)
|
if (this.sid!=null)
|
||||||
@ -80,6 +82,14 @@ public class MdpSocket{
|
|||||||
this.port = packet.getLocalPort();
|
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 {
|
public SelectableChannel getChannel() throws IOException {
|
||||||
if (channel == null){
|
if (channel == null){
|
||||||
channel = DatagramChannel.open();
|
channel = DatagramChannel.open();
|
||||||
@ -114,6 +124,7 @@ public class MdpSocket{
|
|||||||
// ignore errors due to servald stopping.
|
// ignore errors due to servald stopping.
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
sid = null;
|
||||||
}
|
}
|
||||||
if (channel!=null){
|
if (channel!=null){
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user