lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
psalg::shmem::ShmemClient Class Reference

Client of the shared-memory monitor server: connect() finds the server for a tag, maps its shared memory read-only and opens the transition socket and event queues; get() returns the next datagram and free() hands its buffer back. More...

#include <ShmemClient.hh>

Public Member Functions

 ShmemClient ()
 Construct unconnected: no socket, queues or handler.
 
virtual ~ShmemClient ()
 Close the message queues and the transition socket and delete the handler.
 
int connect (const char *tag, int tr_index=0)
 Drop any previous connection, read the server port from the discovery queue for tag (retrying), connect a TCP socket to 127.0.0.1 on that port (retrying), read the first XtcMonitorMsg, map the shared memory read-only, and open this client's event input and output queues.
 
void * get (int &index, size_t &size)
 Block in poll() until the transition socket or the event queue is readable, serving transitions first, and return a pointer to the datagram in shared memory with index and size set to its buffer index and buffer size.
 
void * get (int &index, size_t &size, bool &eventSkipped, bool transitionsOnly=false)
 Same as get(int&, size_t&), but if transitionsOnly is true and poll() returns with no transition pending, set eventSkipped to true and return NULL without reading the event.
 
void free (int index, size_t size)
 Return buffer index (located with size) to the server: for an L1Accept datagram send the message on this client's output event queue, otherwise send it on the transition socket (perror() on failure).
 

Detailed Description

Client of the shared-memory monitor server: connect() finds the server for a tag, maps its shared memory read-only and opens the transition socket and event queues; get() returns the next datagram and free() hands its buffer back.

Constructor & Destructor Documentation

◆ ShmemClient()

psalg::shmem::ShmemClient::ShmemClient ( )

Construct unconnected: no socket, queues or handler.

◆ ~ShmemClient()

virtual psalg::shmem::ShmemClient::~ShmemClient ( )
virtual

Close the message queues and the transition socket and delete the handler.

Member Function Documentation

◆ connect()

int psalg::shmem::ShmemClient::connect ( const char *  tag,
int  tr_index = 0 
)

Drop any previous connection, read the server port from the discovery queue for tag (retrying), connect a TCP socket to 127.0.0.1 on that port (retrying), read the first XtcMonitorMsg, map the shared memory read-only, and open this client's event input and output queues.

tr_index is used only in an error message.

Returns
0 on success; 1 if the socket cannot be created; a positive error count if the first message cannot be read or a queue cannot be opened; -42 if the discovery queue cannot be opened while PSANA_TESTS_SHMEM_TMO is set.

◆ free()

void psalg::shmem::ShmemClient::free ( int  index,
size_t  size 
)

Return buffer index (located with size) to the server: for an L1Accept datagram send the message on this client's output event queue, otherwise send it on the transition socket (perror() on failure).

◆ get() [1/2]

void * psalg::shmem::ShmemClient::get ( int &  index,
size_t &  size 
)

Block in poll() until the transition socket or the event queue is readable, serving transitions first, and return a pointer to the datagram in shared memory with index and size set to its buffer index and buffer size.

Returns NULL, with index -1 and size 0, on a receive error, a closed socket or an invalid buffer index.

◆ get() [2/2]

void * psalg::shmem::ShmemClient::get ( int &  index,
size_t &  size,
bool &  eventSkipped,
bool  transitionsOnly = false 
)

Same as get(int&, size_t&), but if transitionsOnly is true and poll() returns with no transition pending, set eventSkipped to true and return NULL without reading the event.

eventSkipped is never set to false here.


The documentation for this class was generated from the following file: