Add a set of message handlers to a server connection object
int PtConnectionAddMsgHandlers( PtConnectionServer_t *connection, PtConnectionMsgHandler_t const handlers[], unsigned nhandlers );
ph
This function adds a set of message handlers to a server connection object. The handlers[] argument points to an array of PtConnectionMsgHandler_t structures:
typedef void const *PtConnectionMsgFunc_t( PtConnectionServer_t *connection, void *user_data, unsigned long type, void const *msg, unsigned len, unsigned *reply_len ); typedef struct Pt_connection_msg_handler { unsigned long type; PtConnectionMsgFunc_t *fun; } PtConnectionMsgHandler_t;
These structures describe your message handler functions. Your message handler should have these arguments:
The array must be sorted with respect to the type field; it also must not be destroyed or modified as long as the connection object using it exists.
If you add multiple tables to a connection object, they're searched in the reverse order: a call to PtConnectionAddMsgHandlers() can override handlers that were attached by a previous call.
A special value of zero in the type field means “any type.” When a message from a client arrives, all the tables are searched for an exact match on the type, and if this search fails, the tables is searched again for a handler with type 0.
A message handler can do one of three things:
A message handler shouldn't perform any blocking operations and isn't allowed to process Photon events (e.g. don't call PtBkgdHandlerProcess() from an event handler). There's no way to delay the reply to the client — if none of the handlers returns a non-NULL value, the library sends a zero-length reply.
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
PtConnectionAddEventHandlers(), PtConnectionReply(), PtConnectionReplymx(), PtConnectionSend(), PtConnectionSendmx()
“Connections” in the Interprocess Communication chapter of the Photon Programmer's Guide