Dhanya Thattil e0207cfac1
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
2022-08-11 09:14:29 +02:00

29 lines
719 B
C++

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
/*
UDP socket class to receive data. The intended use is in the
receiver listener loop. Should be used RAII style...
*/
#include <sys/types.h> //ssize_t
namespace sls {
class UdpRxSocket {
const ssize_t packet_size_;
int sockfd_{-1};
public:
UdpRxSocket(int port, ssize_t packet_size, const char *hostname = nullptr,
int kernel_buffer_size = 0);
~UdpRxSocket();
bool ReceivePacket(char *dst) noexcept;
int getBufferSize() const;
void setBufferSize(int size);
ssize_t getPacketSize() const noexcept;
void Shutdown();
};
} // namespace sls