Send UDP disconnect when UDP is finished

This commit is contained in:
QuantumEntangledAndy authored and Andrew committed 2021-08-31 20:47:34 +07:00
1 parent 08d174a89d
commit af1e52b850
4 files changed
+27 -18

No files matched your search

@@ -517,4 +517,27 @@ impl UdpDiscover {
Err(e) => Err(e),
}
}
pub fn send_client_disconnect(&self, socket: &UdpSocket) {
if let Ok(addr) = socket.peer_addr() {
let mut rng = thread_rng();
let tid: u32 = (rng.gen::<u8>()) as u32;
let bcudp_msg = BcUdp::Discovery(UdpDiscovery {
tid,
payload: UdpXml {
c2d_disc: Some(C2dDisc {
cid: self.client_id,
did: self.camera_id,
}),
..Default::default()
},
});
let mut buf = vec![];
let buf = bcudp_msg
.serialize(&mut buf)
.expect("Unable to serliaze udp disconnect");
let _ = Self::retrying_send_to(socket, buf, addr);
}
}
}
@@ -131,6 +131,8 @@ impl UdpSource {
}
}
error!("Udp read poll aborted");
// We send client disconnect here
thread_discovery_result.send_client_disconnect(&thread_socket);
});
let thread_aborter = aborter.clone();
@@ -227,7 +227,6 @@ impl UdpTransmit {
let bcudp_msg = BcUdp::deserialize(&buf[0..amount_recv])?;
match bcudp_msg {
BcUdp::Discovery(UdpDiscovery {
tid,
payload:
UdpXml {
d2c_disc: Some(D2cDisc { cid, did }),
@@ -238,22 +237,7 @@ impl UdpTransmit {
&& did == discovery_result.camera_id =>
{
// Reply with C2D_Disc and end
let bcudp_msg = BcUdp::Discovery(UdpDiscovery {
tid,
payload: UdpXml {
c2d_disc: Some(C2dDisc {
cid: discovery_result.client_id,
did: discovery_result.camera_id,
}),
..Default::default()
},
});
let mut buf = vec![];
bcudp_msg.serialize(&mut buf)?;
socket
.send(&buf)
.map_err(|e| TransmitError::SocketSend { err: e })?;
discovery_result.send_client_disconnect(socket);
return Err(TransmitError::Disc);
}
BcUdp::Discovery(packet) => {
+1 -1
View File
@@ -120,7 +120,7 @@ standard tcp bc connection
**Udp Camera**
If the camera supports UDP the client will send this xml packet
If the camera supports UDP the client will send the following xml packet
as a broadcast on 255.255.255.255 on port 2018/2015
**Known UID**