xpamainloop(3)
xpamainloop(3) β the whole vibe π
ok so bestie, welcome to the SAORD Documentation page for XPAMainLoop, and honestly? it's giving "the party doesn't start until the event loop shows up." pull up a chair, we're doing this. π«Ά
β¨ NAME β¨
XPAMainLoop β it's the optional main loop for XPA. yes, optional. yes, that's the whole personality. π
π¦ SYNOPSIS π¦
#include <xpa.h>
void XPAMainLoop();
that's it. that's the girl. short, sweet, slays. β¨
π DESCRIPTION π
So here's the tea, bestie: once you've defined your XPA access points, your program has to get itself into an event loop, otherwise it's just sitting there with no idea that external programs are out here trying to talk to it. Rude of it, honestly. π
You've got options for how you do that, and it really depends on whether your event loop is handling stuff that isn't XPA events.
πΈ the no-other-events path
If there are literally no non-XPA events to deal with? Easy. Your program can just call XPAMainLoop() and let it cook. no cap. π
That loop is implemented essentially like this (and yeah, the error checking here is simplified, don't come for her):
FD_ZERO(&readfds);
while( XPAAddSelect(NULL, &readfds) ){
if( sgot = select(swidth, &readfds, NULL, NULL, NULL) >0 )
XPAProcessSelect(&readfds, 0);
else
break;
FD_ZERO(&readfds);
}
Let's break it down because the way this works is lowkey iconic:
XPAAddSelect()sets up theselect()readfdsvariable so thatselect()will just wait for I/O on all the active XPA channels. it hands back the number of XPAs that are active β and the loop ends when there are no active XPAs left. bye bestie π- the standard
select()routine gets called to wait for an external I/O request. and because no timeout struct is passed in argument 5, thisselect()call just hangs there until an external request shows up. no rush, she's patient. π - the moment an external I/O request does happen,
XPAProcessSelect()runs and processes those pending requests.
Now, inside that routine, maxreq decides how many requests get handled:
- if
maxreq <=0β all currently pending requests get processed. the whole buffet. π - otherwise β up to
maxreqrequests get processed.
(the most usual value for maxreq is 0, aka process everything. periodt.)
π the "I already have my own select() loop" path
If your program has its own Unix select() loop, no worries β you can still add XPA access points to it with a little variation on the standard XPAMainLoop:
XPAAddSelect(xpa, &readfds);
[app-specific ...]
if( select(width, &readfds, ...) ){
XPAProcessSelect(&readfds, maxreq);
[app-specific ...]
FD_ZERO(&readfds);
}
Here's the flow, bestie:
XPAAddSelect()gets called beforeselect()to add the access points.- if that first argument is
NULL, then all active XPA access points get added. if it's notNULL? only the access point you specified gets added. picky, but valid. π - after
select()is called,XPAProcessSelect()can be called to process the XPA requests. - and once again,
maxreqis running the show:maxreq <=0means all currently pending requests get processed, otherwise it's up tomaxreqrequests. same rules, different venue. β¨
π§ adding XPA to Xt and Tcl/Tk loops
You can also add XPA access points to Xt event loops (using XtAppMainLoop()) and to Tcl/Tk event loops (using vwait and the Tk loop). when you're doing it that way, you literally only need to call:
int XPAXtAddInput(XtAppContext app, XPA xpa)
or
int XPATclAddInput(XPA xpa)
respectively β before you enter the loop. that's it. you're done. go be the main character. ππ
π SEE ALSO π
- See
xpa(n)for a list of XPA help pages. go read the whole family, iykyk. π
and that's the page!! version 2.1.15, dated July 23, 2013 β like, a whole legend. ty for coming to my ted talk, now go write an event loop and slay. π
β¨π
π¦ 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