Dhanya Thattil 9834b07b47
Dev/fix port size (#805)
* port datatype changing from int to uint16_t
* throwing for -1 given for uint16_t ports
2023-09-28 09:36:39 +02:00

30 lines
744 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 <stdint.h>
#include <sys/types.h> //ssize_t
namespace sls {
class UdpRxSocket {
const ssize_t packet_size_;
int sockfd_{-1};
public:
UdpRxSocket(uint16_t 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