mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
esrf changes: rx_udpsocksize sets/gets udp socket buffer size to be set, rx_realudpsocksize gets the real udp sock size buffer. At receiver config and at rx_udpsocksize command, dummy udp sockets created to know if set udp sock size fails (if fail, set to previous value), and also to get the real udp sock buffer size
This commit is contained in:
@ -83,6 +83,9 @@ public:
|
||||
/** if standard header implemented in firmware */
|
||||
bool standardheader;
|
||||
|
||||
/** default udp socket buffer size */
|
||||
uint32_t defaultUdpSocketBufferSize;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -109,7 +112,8 @@ public:
|
||||
nPixelsXComplete(0),
|
||||
nPixelsYComplete(0),
|
||||
imageSizeComplete(0),
|
||||
standardheader(false)
|
||||
standardheader(false),
|
||||
defaultUdpSocketBufferSize(RECEIVE_SOCKET_BUFFER_SIZE)
|
||||
{};
|
||||
|
||||
/** Destructor */
|
||||
@ -214,6 +218,7 @@ public:
|
||||
FILE_LOG(logDEBUG) << "Complete Pixels Y: " << nPixelsYComplete;
|
||||
FILE_LOG(logDEBUG) << "Complete Image Size: " << imageSizeComplete;
|
||||
FILE_LOG(logDEBUG) << "Standard Header: " << standardheader;
|
||||
FILE_LOG(logDEBUG) << "UDP Socket Buffer Size: " << defaultUdpSocketBufferSize;
|
||||
};
|
||||
};
|
||||
|
||||
@ -494,6 +499,7 @@ class JungfrauData : public GeneralData {
|
||||
fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + sizeof(slsReceiverDefs::sls_detector_header);
|
||||
defaultFifoDepth = 2500;
|
||||
standardheader = true;
|
||||
defaultUdpSocketBufferSize = (2000 * 1024 * 1024);
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -31,9 +31,12 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
* @param act pointer to activated
|
||||
* @param nf pointer to number of images to catch
|
||||
* @param dr pointer to dynamic range
|
||||
* @param us pointer to udp socket buffer size
|
||||
* @param as pointer to actual udp socket buffer size
|
||||
*/
|
||||
Listener(int& ret, int ind, detectorType dtype, Fifo*& f, runStatus* s,
|
||||
uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr);
|
||||
uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr,
|
||||
uint32_t* us, uint32_t* as);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
@ -131,7 +134,13 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
*/
|
||||
void SetSilentMode(bool mode);
|
||||
|
||||
|
||||
/**
|
||||
* Create & closes a dummy UDP socket
|
||||
* to set & get actual buffer size
|
||||
* @param s UDP socket buffer size to be set
|
||||
* @return OK or FAIL of dummy socket creation
|
||||
*/
|
||||
int CreateDummySocketForUDPSocketBufferSize(uint32_t s);
|
||||
|
||||
|
||||
private:
|
||||
@ -223,6 +232,12 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
||||
/** Dynamic Range */
|
||||
uint32_t* dynamicRange;
|
||||
|
||||
/** UDP Socket Buffer Size */
|
||||
uint32_t* udpSocketBufferSize;
|
||||
|
||||
/** actual UDP Socket Buffer Size (double due to kernel bookkeeping) */
|
||||
uint32_t* actualUDPSocketBufferSize;
|
||||
|
||||
|
||||
// acquisition start
|
||||
/** Aquisition Started flag */
|
||||
|
@ -277,6 +277,18 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
*/
|
||||
char *getAdditionalJsonHeader() const;
|
||||
|
||||
/** (not saved in client shared memory)
|
||||
* Get UDP Socket Buffer Size
|
||||
* @return UDP Socket Buffer Size
|
||||
*/
|
||||
uint32_t getUDPSocketBufferSize() const;
|
||||
|
||||
|
||||
/** (not saved in client shared memory)
|
||||
* Get actual UDP Socket Buffer Size
|
||||
* @return actual UDP Socket Buffer Size
|
||||
*/
|
||||
uint32_t getActualUDPSocketBufferSize() const;
|
||||
|
||||
/*************************************************************************
|
||||
* Setters ***************************************************************
|
||||
@ -566,6 +578,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
*/
|
||||
void setAdditionalJsonHeader(const char* c);
|
||||
|
||||
/** (not saved in client shared memory)
|
||||
* Set UDP Socket Buffer Size
|
||||
* @param s UDP Socket Buffer Size
|
||||
* @return OK or FAIL if dummy socket could be created
|
||||
*/
|
||||
int setUDPSocketBufferSize(const uint32_t s);
|
||||
|
||||
/*
|
||||
* Restream stop dummy packet from receiver
|
||||
* @return OK or FAIL
|
||||
@ -691,6 +710,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter
|
||||
char eth[MAX_STR_LENGTH];
|
||||
/** Server UDP Port Number*/
|
||||
uint32_t udpPortNum[MAX_NUMBER_OF_LISTENING_THREADS];
|
||||
/** udp socket buffer size */
|
||||
uint32_t udpSocketBufferSize;
|
||||
/** actual UDP Socket Buffer Size (halved due to kernel bookkeeping) */
|
||||
uint32_t actualUDPSocketBufferSize;
|
||||
|
||||
//***file parameters***
|
||||
/** File format */
|
||||
|
@ -332,7 +332,7 @@ class UDPInterface {
|
||||
*/
|
||||
virtual slsReceiverDefs::runStatus getStatus() const = 0;
|
||||
|
||||
/**
|
||||
/** (not saved in client shared memory)
|
||||
* Get Silent Mode
|
||||
* @return silent mode
|
||||
*/
|
||||
@ -365,6 +365,18 @@ class UDPInterface {
|
||||
virtual char *getAdditionalJsonHeader() const = 0;
|
||||
|
||||
|
||||
/** (not saved in client shared memory)
|
||||
* Get UDP Socket Buffer Size
|
||||
* @return UDP Socket Buffer Size
|
||||
*/
|
||||
virtual uint32_t getUDPSocketBufferSize() const = 0;
|
||||
|
||||
/** (not saved in client shared memory)
|
||||
* Get actual UDP Socket Buffer Size
|
||||
* @return actual UDP Socket Buffer Size
|
||||
*/
|
||||
virtual uint32_t getActualUDPSocketBufferSize() const = 0;
|
||||
|
||||
/*************************************************************************
|
||||
* Setters ***************************************************************
|
||||
* They modify the local cache of configuration or detector parameters ***
|
||||
@ -655,6 +667,13 @@ class UDPInterface {
|
||||
*/
|
||||
virtual void setAdditionalJsonHeader(const char* c) = 0;
|
||||
|
||||
/** (not saved in client shared memory)
|
||||
* Set UDP Socket Buffer Size
|
||||
* @param s UDP Socket Buffer Size
|
||||
* @return OK or FAIL if dummy socket could be created
|
||||
*/
|
||||
virtual int setUDPSocketBufferSize(const uint32_t s) = 0;
|
||||
|
||||
/*
|
||||
* Restream stop dummy packet from receiver
|
||||
* @return OK or FAIL
|
||||
|
@ -184,6 +184,13 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
|
||||
*/
|
||||
void closeFiles();
|
||||
|
||||
/** (not saved in client shared memory)
|
||||
* Set UDP Socket Buffer Size
|
||||
* @param s UDP Socket Buffer Size
|
||||
* @return OK or FAIL if dummy socket could be created
|
||||
*/
|
||||
int setUDPSocketBufferSize(const uint32_t s);
|
||||
|
||||
/**
|
||||
* Restream stop dummy packet from receiver
|
||||
* @return OK or FAIL
|
||||
|
@ -49,6 +49,8 @@ class sockaddr_in;
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <sys/prctl.h> // capabilities
|
||||
#include <linux/capability.h>
|
||||
|
||||
#endif
|
||||
|
||||
@ -63,7 +65,7 @@ class sockaddr_in;
|
||||
using namespace std;
|
||||
|
||||
#define DEFAULT_PACKET_SIZE 1286
|
||||
#define SOCKET_BUFFER_SIZE (2000*1024*1024) //2GB, previously 100MB
|
||||
#define SOCKET_BUFFER_SIZE (100*1024*1024) //100 MB
|
||||
#define DEFAULT_BACKLOG 5
|
||||
|
||||
|
||||
@ -92,7 +94,8 @@ enum communicationProtocol{
|
||||
nsending(0),
|
||||
nsent(0),
|
||||
total_sent(0),// sender (client): where to? ip
|
||||
header_packet_size(0)
|
||||
header_packet_size(0),
|
||||
actual_udp_socket_buffer_size(0)
|
||||
{
|
||||
memset(&serverAddress, 0, sizeof(serverAddress));
|
||||
memset(&clientAddress, 0, sizeof(clientAddress));
|
||||
@ -143,7 +146,7 @@ enum communicationProtocol{
|
||||
|
||||
genericSocket(unsigned short int const port_number, communicationProtocol p,
|
||||
int ps = DEFAULT_PACKET_SIZE, const char *eth=NULL, int hsize=0,
|
||||
int buf_size=SOCKET_BUFFER_SIZE):
|
||||
uint32_t buf_size=SOCKET_BUFFER_SIZE):
|
||||
portno(port_number),
|
||||
protocol(p),
|
||||
is_a_server(1),
|
||||
@ -153,7 +156,8 @@ enum communicationProtocol{
|
||||
nsending(0),
|
||||
nsent(0),
|
||||
total_sent(0),
|
||||
header_packet_size(hsize)
|
||||
header_packet_size(hsize),
|
||||
actual_udp_socket_buffer_size(0)
|
||||
{
|
||||
|
||||
|
||||
@ -209,49 +213,69 @@ enum communicationProtocol{
|
||||
|
||||
|
||||
// reuse port
|
||||
int val=1;
|
||||
if (setsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(int)) == -1) {
|
||||
cprintf(RED, "setsockopt REUSEADDR failed\n");
|
||||
socketDescriptor=-1;
|
||||
return;
|
||||
{
|
||||
int val=1;
|
||||
if (setsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(int)) == -1) {
|
||||
cprintf(RED, "setsockopt REUSEADDR failed\n");
|
||||
socketDescriptor=-1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//increase buffer size if its udp
|
||||
if (p == UDP) {
|
||||
val = buf_size;
|
||||
int real_val = -1;
|
||||
uint32_t desired_size = buf_size;
|
||||
uint32_t real_size = desired_size * 2; // kernel doubles this value for bookkeeping overhead
|
||||
uint32_t ret_size = -1;
|
||||
socklen_t optlen = sizeof(int);
|
||||
// set buffer size (could not set)
|
||||
if (setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &val, optlen) == -1) {
|
||||
FILE_LOG(logWARNING) << "Could not set socket receive buffer size: "
|
||||
<< val << " : no root privileges?";
|
||||
|
||||
// confirm if sufficient
|
||||
if (getsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &ret_size, &optlen) == -1) {
|
||||
FILE_LOG(logWARNING) << "[Port " << port_number << "] Could not get Socket Receive Buffer Size";
|
||||
} else if (ret_size >= real_size) {
|
||||
actual_udp_socket_buffer_size = ret_size;
|
||||
#ifdef VEBOSE
|
||||
FILE_LOG(logINFO) << "[Port " << port_number << "] UDP Socket Buffer Size is sufficient (" << ret_size << ")";
|
||||
#endif
|
||||
}
|
||||
// confirm size (could not get)
|
||||
else if (getsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &real_val, &optlen) == -1) {
|
||||
FILE_LOG(logWARNING) << "Could not get socket receive buffer size";
|
||||
}
|
||||
// set buffer size worked if real val is twice the requested value
|
||||
else if (real_val == val * 2) {
|
||||
cprintf(GREEN, "UDP Socket buffer size modified to %d\n", real_val);
|
||||
}
|
||||
// buffer size too large
|
||||
|
||||
// not sufficient, enhance size
|
||||
else {
|
||||
// force a value larger than system limit (if run in a privileged context (capability CAP_NET_ADMIN set))
|
||||
int ret = setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUFFORCE, &val, optlen);
|
||||
getsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &real_val, &optlen);
|
||||
if (ret == -1) {
|
||||
FILE_LOG(logWARNING) << "Could not force socket receive buffer size to "
|
||||
<< val << ", real size is " << real_val <<
|
||||
" : no root privileges?";
|
||||
} else {
|
||||
cprintf(GREEN, "UDP socket buffer size modified to %d\n", real_val);
|
||||
// set buffer size (could not set)
|
||||
if (setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &desired_size, optlen) == -1) {
|
||||
FILE_LOG(logWARNING) << "[Port " << port_number << "] Could not set Socket Receive Buffer Size to "
|
||||
<< desired_size << ". No Root Privileges?";
|
||||
}
|
||||
// confirm size
|
||||
else if (getsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &ret_size, &optlen) == -1) {
|
||||
FILE_LOG(logWARNING) << "[Port " << port_number << "] Could not get Socket Receive Buffer Size";
|
||||
}
|
||||
else if (ret_size >= real_size) {
|
||||
actual_udp_socket_buffer_size = ret_size;
|
||||
FILE_LOG(logINFO) << "[Port " << port_number << "] UDP Socket Buffer Size modified to " << ret_size;
|
||||
}
|
||||
// buffer size too large
|
||||
else {
|
||||
actual_udp_socket_buffer_size = ret_size;
|
||||
cprintf(BLUE, "[Port %u] wanted : %u, actualsize: %u\n", port_number, real_size, ret_size);
|
||||
// force a value larger than system limit (if run in a privileged context (capability CAP_NET_ADMIN set))
|
||||
int ret = setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUFFORCE, &desired_size, optlen);
|
||||
getsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &ret_size, &optlen);
|
||||
if (ret == -1) {
|
||||
FILE_LOG(logWARNING) << "[Port " << port_number << "] "
|
||||
"Could not force Socket Receive Buffer Size to "
|
||||
<< desired_size << ". Real size is " << ret_size <<
|
||||
". (No Root Privileges?)\n"
|
||||
"Set rx_udpsocksize from the client to <= " <<
|
||||
(ret_size/2) << " (Real size:" << ret_size << ") to remove this warning.\n";
|
||||
} else {
|
||||
FILE_LOG(logINFO) << "[Port " << port_number << "] UDP socket buffer size modified to " << ret_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(bind(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
||||
cprintf(RED, "Can not bind socket\n");
|
||||
socketDescriptor=-1;
|
||||
@ -267,8 +291,13 @@ enum communicationProtocol{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns actual udp socket buffer size/2.
|
||||
* Halving is because of kernel book keeping
|
||||
*/
|
||||
int getActualUDPSocketBufferSize(){
|
||||
return actual_udp_socket_buffer_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -464,7 +493,7 @@ enum communicationProtocol{
|
||||
|
||||
|
||||
void ShutDownSocket(){
|
||||
while(!shutdown(socketDescriptor, SHUT_RDWR));
|
||||
shutdown(socketDescriptor, SHUT_RDWR);
|
||||
Disconnect();
|
||||
};
|
||||
|
||||
@ -801,6 +830,7 @@ enum communicationProtocol{
|
||||
int nsent;
|
||||
int total_sent;
|
||||
int header_packet_size;
|
||||
int actual_udp_socket_buffer_size;
|
||||
|
||||
// pthread_mutex_t mp;
|
||||
};
|
||||
|
@ -7,6 +7,7 @@
|
||||
//socket
|
||||
#define GOODBYE -200
|
||||
#define RECEIVE_SOCKET_BUFFER_SIZE (100*1024*1024)
|
||||
|
||||
#define MAX_SOCKET_INPUT_PACKET_QUEUE 250000
|
||||
|
||||
|
||||
|
@ -300,6 +300,12 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs {
|
||||
/** set additional json header */
|
||||
int set_additional_json_header();
|
||||
|
||||
/** set udp socket buffer size */
|
||||
int set_udp_socket_buffer_size();
|
||||
|
||||
/** get real udp socket buffer size */
|
||||
int get_real_udp_socket_buffer_size();
|
||||
|
||||
|
||||
|
||||
/** detector type */
|
||||
|
@ -64,7 +64,8 @@ enum recFuncs{
|
||||
F_ENABLE_GAPPIXELS_IN_RECEIVER, /** < sets gap pixels in the receiver */
|
||||
F_RESTREAM_STOP_FROM_RECEIVER, /** < restream stop from receiver */
|
||||
F_ADDITIONAL_JSON_HEADER, /** < additional json header */
|
||||
|
||||
F_RECEIVER_UDP_SOCK_BUF_SIZE, /** < UDP socket buffer size */
|
||||
F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE, /** < real UDP socket buffer size */
|
||||
|
||||
/* Always append functions hereafter!!! */
|
||||
|
||||
|
Reference in New Issue
Block a user