reverted to UdpRxSocket.h version of revision fc27cfd (with gcc problem fixed)

This commit is contained in:
2020-02-21 11:07:24 +01:00
parent 3b84684415
commit 8953235268
2 changed files with 104 additions and 99 deletions

View File

@ -1,4 +1,13 @@
hostname bchip085+ #############################################
### edit with hostname or IP address of your detector
############################################
hostname bchip181+
runclk 40
adcclk 20
dbitclk 40
patword 0000 0000000000000000 patword 0000 0000000000000000
patword 0001 0000000000000000 patword 0001 0000000000000000
@ -408,84 +417,80 @@ patnloop1 0
patloop2 0400 0400 patloop2 0400 0400
patnloop2 0 patnloop2 0
patwait0 00aa patwait0 00aa
patwaittime0 40000 patwaittime0 10000
patwait1 0400 patwait1 0400
patwaittime1 0 patwaittime1 0
patwait2 0400 patwait2 0400
patwaittime2 0 patwaittime2 0
####mcp2011 #0:rx_tcpport 1977
#0:rx_udpip 10.1.1.102
#0:detectorip 10.1.1.19
#0:rx_udpport 32410
####gui listening to
#zmqip 129.129.202.131
#zmqport 30001
####data streaming out of
#rx_zmqip 10.1.2.103
#rx_zmqport 30003
#0:rx_hostname mpc2011
####mx-test-1 #############################################
0:rx_udpip 10.1.1.100 ### edit with 10 Gbs IP of your server
0:detectorip 10.1.1.19 ############################################
0:rx_udpport 32410 0:udp_dstip 10.1.2.102
####gui listening to (on receiver pc) #############################################
zmqip 129.129.202.92 ### edit with any number in the subnet of your server (first 3 numbers as above)
zmqport 30001 ############################################
####data streaming out of 0:udp_srcip 10.1.2.19
rx_zmqip 10.1.1.100
rx_zmqport 30003 0:udp_dstport 32410
0:rx_hostname pcmoench01 #############################################
### edit with 10 Gbs IP of your server
############################################
#zmqip 129.129.202.110
rx_zmqip 10.1.1.102
rx_zmqport 30001
#############################################
### edit with 1 Gbs IP of PC where you will run the GUI
############################################
#zmqip 129.129.202.110
#zmqport 50001
#############################################
### edit with hostname or 1Gbs IP address of your server
############################################
0:rx_hostname mpc2011
tengiga 1
#rx_datastream 1
#rx_readfreq 1
dac 6 800
dac 0 1300
dac 4 1428
dac 1 1000
dac 7 900
dac 3 680
dac 2 1400
#turn on datastream from commandline dac 5 1200
rx_datastream 1
r_readfreq 1
#0:configuremac -1
rx_datastream 1
r_readfreq 1
dac:6 800
dac:0 1300
dac:4 1428
dac:1 1000
dac:7 900
dac:3 680
dac:2 1400
dac:5 1200
adcinvert 4a342593 adcinvert 4a342593
samples 5000 samples 5000
adcphase 90 adcphase 30 deg
adcpipeline 15 adcpipeline 14
adcreg 14 40 adcreg 14 40
powerchip 1
frames 1000
period 0.001
#############################################
### edit with directory you want to write to
############################################
fpath /tmp/
fwrite 0
romode analog
#rx_jsonaddheader frameMode
rx_jsonpara frameMode newpedestal
#rx_jsonaddheader detectorMode
rx_jsonpara detectorMode analog
#flags newpedestal
#flags analog
reg 0x5e 0x00010000
#powerchip 1
vhighvoltage 90 vhighvoltage 90
period 0.005
frames 100
period 0.1
outdir /scratch/
enablefwrite 0

View File

@ -9,14 +9,12 @@ this might be deprecated in the future
*/ */
#include "container_utils.h"
#include "genericSocket.h" #include "genericSocket.h"
#include "network_utils.h" #include "network_utils.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include <cstdint> #include <cstdint>
#include <errno.h> #include <errno.h>
#include <iostream> #include <iostream>
#include <memory>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
@ -28,12 +26,12 @@ namespace sls {
class UdpRxSocket { class UdpRxSocket {
const ssize_t packet_size; const ssize_t packet_size;
std::unique_ptr<char[]> buff; char *buff;
int sockfd = -1; int fd = -1;
public: public:
UdpRxSocket(int port, ssize_t packet_size, const char *hostname = nullptr, UdpRxSocket(int port, ssize_t packet_size, const char *hostname = nullptr,
ssize_t kernel_rbuffer_size = 0) ssize_t buffer_size = 0)
: packet_size(packet_size) { : packet_size(packet_size) {
/* hostname = nullptr -> wildcard */ /* hostname = nullptr -> wildcard */
@ -50,11 +48,11 @@ class UdpRxSocket {
throw RuntimeError("Failed at getaddrinfo with " + throw RuntimeError("Failed at getaddrinfo with " +
std::string(hostname)); std::string(hostname));
} }
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sockfd == -1) { if (fd == -1) {
throw RuntimeError("Failed to create UDP RX socket"); throw RuntimeError("Failed to create UDP RX socket");
} }
if (bind(sockfd, res->ai_addr, res->ai_addrlen) == -1) { if (bind(fd, res->ai_addr, res->ai_addrlen) == -1) {
throw RuntimeError("Failed to bind UDP RX socket"); throw RuntimeError("Failed to bind UDP RX socket");
} }
freeaddrinfo(res); freeaddrinfo(res);
@ -62,19 +60,19 @@ class UdpRxSocket {
// If we get a specified buffer size that is larger than the set one // If we get a specified buffer size that is larger than the set one
// we set it. Otherwise we leave it there since it could have been // we set it. Otherwise we leave it there since it could have been
// set by the rx_udpsocksize command // set by the rx_udpsocksize command
if (kernel_rbuffer_size) { if (buffer_size) {
auto current = getBufferSize() / 2; auto current = getBufferSize() / 2;
if (current < kernel_rbuffer_size) { if (current < buffer_size) {
setBufferSize(kernel_rbuffer_size); setBufferSize(buffer_size);
if (getBufferSize() / 2 < kernel_rbuffer_size) { if (getBufferSize() / 2 < buffer_size) {
FILE_LOG(logWARNING) FILE_LOG(logWARNING)
<< "Could not set buffer size. Got: " << "Could not set buffer size. Got: "
<< getBufferSize() / 2 << " instead of " << getBufferSize() / 2 << " instead of " << buffer_size;
<< kernel_rbuffer_size;
} }
} }
} }
buff = sls::make_unique<char[]>(packet_size); // Allocate at the end to avoid memory leak if we throw
buff = new char[packet_size];
} }
// Delegating constructor to allow drop in replacement for old socket class // Delegating constructor to allow drop in replacement for old socket class
@ -87,33 +85,35 @@ class UdpRxSocket {
buf_size) {} buf_size) {}
~UdpRxSocket() { ~UdpRxSocket() {
if (sockfd >= 0) delete[] buff;
close(sockfd); Shutdown();
} }
UdpRxSocket(const UdpRxSocket &) = delete; const char *LastPacket() const noexcept { return buff; }
UdpRxSocket(UdpRxSocket &&) = delete; //constexpr
const char *LastPacket() const noexcept { return buff.get(); }
ssize_t getPacketSize() const noexcept { return packet_size; } ssize_t getPacketSize() const noexcept { return packet_size; }
bool ReceivePacket() noexcept { return ReceivePacket(buff.get()); } bool ReceivePacket() noexcept {
auto bytes_received =
recvfrom(fd, buff, packet_size, 0, nullptr, nullptr);
return bytes_received == packet_size;
}
bool ReceivePacket(char *dst) noexcept { bool ReceivePacket(char *dst) noexcept {
auto bytes_received = auto bytes_received =
recvfrom(sockfd, dst, packet_size, 0, nullptr, nullptr); recvfrom(fd, buff, packet_size, 0, nullptr, nullptr);
return bytes_received == packet_size; return bytes_received == packet_size;
} }
// Only for backwards compatibility this function will be removed during // Only for backwards compatibility this function will be removed during
// refactoring of the receiver // refactoring of the receiver
ssize_t ReceiveDataOnly(char *dst) { ssize_t ReceiveDataOnly(char *dst) {
auto r = recvfrom(sockfd, dst, packet_size, 0, nullptr, nullptr); auto r = recvfrom(fd, dst, packet_size, 0, nullptr, nullptr);
constexpr ssize_t eiger_header_packet = constexpr ssize_t eiger_header_packet =
40; // only detector that has this 40; // only detector that has this
if (r == eiger_header_packet) { if (r == eiger_header_packet) {
FILE_LOG(logWARNING) << "Got header pkg"; FILE_LOG(logWARNING) << "Got header pkg";
r = recvfrom(sockfd, dst, packet_size, 0, nullptr, nullptr); r = recvfrom(fd, dst, packet_size, 0, nullptr, nullptr);
} }
return r; return r;
} }
@ -121,7 +121,7 @@ class UdpRxSocket {
ssize_t getBufferSize() const { ssize_t getBufferSize() const {
uint64_t ret_size = 0; uint64_t ret_size = 0;
socklen_t optlen = sizeof(uint64_t); socklen_t optlen = sizeof(uint64_t);
if (getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &ret_size, &optlen) == -1) if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &ret_size, &optlen) == -1)
return -1; return -1;
else else
return ret_size; return ret_size;
@ -131,20 +131,20 @@ class UdpRxSocket {
ssize_t getActualUDPSocketBufferSize() const { return getBufferSize(); } ssize_t getActualUDPSocketBufferSize() const { return getBufferSize(); }
// Only for backwards compatibility will be removed // Only for backwards compatibility will be removed
void ShutDownSocket() { Close(); } void ShutDownSocket() { Shutdown(); }
void setBufferSize(ssize_t size) { void setBufferSize(ssize_t size) {
socklen_t optlen = sizeof(size); socklen_t optlen = sizeof(size);
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &size, optlen)) { if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, optlen)) {
throw RuntimeError("Could not set socket buffer size"); throw RuntimeError("Could not set socket buffer size");
} }
} }
// Do we need this function or can we rely on scope? void Shutdown() {
void Close() { shutdown(fd, SHUT_RDWR);
if (sockfd >= 0) { if (fd >= 0) {
close(sockfd); close(fd);
sockfd = -1; fd = -1;
} }
} }
}; };