xpanew(3)
β¨ NAME β¨
XPANew β create a new XPA access point π
(yes bestie, this is xpanew(3) from the SAORD Documentation, and it's lowkey the moment your program becomes findable)
π SYNOPSIS π
#include <xpa.h>
XPA XPANew(char *class, char *name, char *help,
int (*send_callback)(),
void *send_data, char *send_mode,
int (*rec_callback)(),
void *rec_data, char *rec_mode);
π¦ DESCRIPTION π¦
Okay so here's the vibe: you're making a brand-new XPA public access point with the class:name identifier template, and you're entering that access point into the XPA name server so all the external processes can come find it. Main character behaviour, honestly. XPANew() hands you back an XPA struct.
Heads up bestie: the length of theclassandnamedesignations must each be less than or equal to 1024 characters. No essays in the class field, okay? π
The XPA name server daemon, xpans, gets started automatically if it isn't already running (assuming it can be found in the path). The program's ip address and listening port are specified by the environment variable XPA_NSINET, which takes the form :. If no such environment variable exists, then xpans is started on the current machine listening on port 14285. It also uses 14286 as a known port for its public access point (so that routines do not have to go to the name server to find the name server ip and port! β iconic shortcut, we love her). As of XPA 2.1.1, version information is exchanged between the xpans process and the new access point. If the access point uses an XPA major/minor version newer than xpans, a warning is issued by both processes, since mixing of new servers and old xpa programs (xpaset, xpaget, xpans, etc.) is not likely to work. You can turn off the warning message by setting the XPA_VERSIONCHECK environment variable to "false".
The help string is meant to be returned by a request from xpaget:
xpaget class:name -help
A send_callback and/or a receive_callback can be specified; at least one of them must be specified. No callback-less access points, periodt. π
π the send_callback π
A send_callback can be specified that will be executed in response to an external request from the xpaget program, the XPAGet() routine, or the XPAGetFd() routine. This callback is used to send data to the requesting client.
The calling sequence for send_callback() is:
int send_callback(void *send_data, void *call_data,
char *paramlist, char **buf, size_t *len)
{
XPA xpa = (XPA)call_data;
...
return(stat);
}
The send_mode string is of the form: "key1=value1,key2=value2,..." The following keywords are recognized:
aclβ valuetrue/false, defaulttrueβ enable access controlfreebufβ valuetrue/false, defaulttrueβ free buf after callback completes
The call_data should be recast to the XPA struct as shown. In addition, client-specific data can be passed to the callback in send_data.
The paramlist will be supplied by the client as qualifying parameters for the callback. There are two ways in which the send_callback() routine can send data back to the client:
- The
send_callback()routine can fill in a buffer and pass back a pointer to this buffer. An integerlenalso is returned to specify the number of bytes of data inbuf. XPA will send this buffer to the client after the callback is complete. - The
send_callbackcan send data directly to the client by writing to the fd pointed by the macro:
xpa_datafd(xpa)
Note that this fd is of the kind returned by socket() or open().
If a buf has been allocated by a standard malloc routine, filled, and returned to XPA, then freebuf generally is set so that the buffer will be freed automatically when the callback is completed and data has been sent to the client. If a static buf is returned, freebuf should be set to false to avoid a system error when freeing static storage. Note that default value for freebuf implies that the callback will allocate a buffer rather than use static storage.
On the other hand, if buf is dynamically allocated using a method other than a standard malloc/calloc/realloc routine (e.g. using Perl's memory allocation and garbage collection scheme), then it is necessary to tell XPA how to free the allocated buffer. To do this, use the XPASetFree() routine within your callback:
void XPASetFree(XPA xpa, void (*myfree)(void *), void *myfree_ptr);
The first argument is the usual XPA handle. The second argument is the special routine to call to free your allocated memory. The third argument is an optional pointer. If not NULL, the specified free routine is called with that pointer as its sole argument. If NULL, the free routine is called with the standard buf pointer as its sole argument. This is useful in cases where there is a mapping between the buffer pointer and the actual allocated memory location, and the special routine is expecting to be passed the former.
If, while the callback performs its processing, an error occurs that should be communicated to the client, then the routine XPAError should be called:
XPAError(XPA xpa, char *s);
where s is an arbitrary error message. The returned error message string will be of the form:
XPA$ERROR [error] (class:name ip:port)
If the callback wants to send a specific acknowledgment message back to the client, the routine XPAMessage can be called:
XPAMessage(XPA xpa, char *s);
where s is an arbitrary error message. The returned error message string will be of the form:
XPA$MESSAGE [message] (class:name ip:port)
Otherwise, a standard acknowledgment is sent back to the client after the callback is completed.
The callback routine should return 0 if no error occurs, or -1 to signal an error. π«Ά
π the receive_callback π
A receive_callback can be specified that will be executed in response to an external request from the xpaset program, or the XPASet (or XPASetFd()) routine. This callback is used to process data received from an external process.
The calling sequence for receive_callback is:
int receive_callback(void *receive_data, void *call_data,
char *paramlist, char *buf, size_t len)
{
XPA xpa = (XPA)call_data;
...
return(stat);
}
The mode string is of the form: "key1=value1,key2=value2,..." The following keywords are recognized:
aclβ valuetrue/false, defaulttrueβ enable access controlbufβ valuetrue/false, defaulttrueβ server expects data bytes from clientfillbufβ valuetrue/false, defaulttrueβ read data into buf before executing callbackfreebufβ valuetrue/false, defaulttrueβ free buf after callback completes
The call_data should be recast to the XPA struct as shown. In addition, client-specific data can be passed to the callback in receive_data.
The paramlist will be supplied by the client. In addition, if the receive_mode keywords buf and fillbuf are true, then on entry into the receive_callback() routine, buf will contain the data sent by the client. If buf is true but fillbuf is false, it becomes the callback's responsibility to retrieve the data from the client, using the data fd pointed to by the macro xpa_datafd(xpa). If freebuf is true, then buf will be freed when the callback is complete. π§
If, while the callback is performing its processing, an error occurs that should be communicated to the client, then the routine XPAError can be called:
XPAError(XPA xpa, char *s);
where s is an arbitrary error message.
The callback routine should return 0 if no error occurs, or -1 to signal an error.
π SEE ALSO π
See xpa(n) for a list of XPA help pages β go read it, bestie, it's giving lore. π
Okay that's the whole page, no notes, you ate. π
β¨ This little masterpiece is version 2.1.15, dated July 23, 2013, and it lives under the xpanew(3) page of the SAORD Documentation. Byeee ππ¦πΈ
π¦ where this page comes from
- debian bookworm: libxpa-dev 2.1.20-1 Β· MIT
- debian trixie: libxpa-dev 2.1.20-3 Β· MIT
- ubuntu jammy: libxpa-dev 2.1.20-1 Β· MIT
- ubuntu noble: libxpa-dev 2.1.20-1build1 Β· MIT
- ubuntu questing: libxpa-dev 2.1.20-3
- ubuntu resolute: libxpa-dev 2.1.20-3build1 Β· MIT
- ubuntu stonking: libxpa-dev 2.1.20-3build1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms