xpamainloop(3)

πŸ“¦
version 2.1.20 Β· 2 versions
  • 2.1.20 Β· debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 2.1.20 Β· fedora 43, fedora 44
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

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 the select() readfds variable so that select() 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, this select() 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 maxreq requests 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 before select() to add the access points.
  • if that first argument is NULL, then all active XPA access points get added. if it's not NULL? 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, maxreq is running the show: maxreq <=0 means all currently pending requests get processed, otherwise it's up to maxreq requests. 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. πŸ’…βœ¨πŸŽ€