Udpsocket (#507)

* udp socket refactor from reuss: closing socket before throwing for bind error in constructor, closing socket at destructor and not at shutdown to allow other thread to read with a -1, so the object can still be accessed

* check for size of packet for every detector

* nullptr to unique ptr to call its destructor, when deallocating resources moved out of shutdown

* minor
This commit is contained in:
Dhanya Thattil
2022-08-11 09:14:29 +02:00
committed by GitHub
parent 07ff28e9e5
commit e0207cfac1
4 changed files with 15 additions and 38 deletions

View File

@ -151,14 +151,13 @@ void Listener::CreateUDPSocket(int &actualSize) {
if (disabledPort) {
return;
}
ShutDownUDPSocket();
uint32_t packetSize = generalData->packetSize;
if (generalData->detType == GOTTHARD2 && index != 0) {
packetSize = generalData->vetoPacketSize;
}
try {
udpSocket = nullptr;
udpSocket = make_unique<UdpRxSocket>(
udpPortNumber, packetSize,
(eth.length() ? InterfaceNameToIp(eth).str().c_str() : nullptr),
@ -340,18 +339,13 @@ uint32_t Listener::ListenToAnImage(sls_receiver_header &dstHeader,
// never entering this loop)
while (numpackets < pperFrame) {
// listen to new packet
int rc = 0;
if (udpSocketAlive) {
rc = udpSocket->ReceiveDataOnly(&listeningPacket[0]);
}
// end of acquisition
if (rc <= 0) {
if (!udpSocketAlive || !udpSocket->ReceivePacket(&listeningPacket[0])) {
// end of acquisition
if (numpackets == 0)
return 0;
return HandleFuturePacket(true, numpackets, fnum, isHeaderEmpty,
imageSize, dstHeader);
}
numPacketsCaught++;
numPacketsStatistic++;
GetPacketIndices(fnum, pnum, bnum, standardHeader,