IOCallback(3I)

πŸ’– IOCallback β€” bestie edition πŸ’–

IOCallback(3I) Β· from the InterViews Reference Manual Β· yes we're reading a whole manual together, it's giving study date πŸŽ€


✨ NAME ✨

IOCallback β€” the generic callback class for readers, writers, or I/O exception handlers πŸ¦‹

Like, it's the plug anything in here class. Reader energy, writer energy, exception-handler energy, all of it. Slay.


🌸 SYNOPSIS 🌸

#include <Dispatch/iocallback.h>

That's it. That's the whole vibe check. One include and you're in. πŸ’…


🫢 DESCRIPTION 🫢

Okay so listen, bestie β€” the macros in iocallback.h exist purely for convenience, and what they do is let you define an iohandler that literally does nothing except call some arbitrary object's member function. That's it. That's the whole job. No cap. 🧚

Which means the actual code β€” the part that reads data from a file descriptor, writes data to a file descriptor, handles an I/O exception on a file descriptor, or handles a timer's expiration β€” gets to live in any arbitrary class you want instead of being trapped inside the iohandler. Main character energy for your own classes, honestly. πŸ‘‘


⭐ MACROS ⭐

  • declareIOCallback(T) β€” declares an iocallback type for the given class type T. Announce it, bestie. πŸ“£
  • implementIOCallback(T) β€” emits code at this point to implement the iocallback's member functions. This is where you actually make it real. πŸ’ͺ
  • IOCallback(T)* instance = new IOCallback(T)(...) β€” defines an instance of the iocallback type for the given class type T. New instance, who dis. ✨

🌈 CONSTRUCTORS 🌈

First, the typedefs. These are the shapes of the member functions you'll be handing over:

typedef int T::IOReady(T)(int fd)
typedef void T::IOTimer(T)(long sec, long usec)

And now the constructors themselves:

IOCallback(T)(T*, IOReady(T)* in, IOReady(T)* out = nil, IOReady(T)* ex
= nil)
IOCallback(T)(T*, IOTimer(T)*, IOReady(T)* in = nil, IOReady(T)* out =
nil, IOReady(T)* ex = nil)

What they do: they construct an instance of the iocallback type that will call the given member functions of the given class type T's instance. πŸŽ€

And no, bestie, you do not have to use the IOReady(T) or IOTimer(T) macros. All you actually have to do is pass the address of a T member function β€” like &T::inputReady. That's it. That's the whole trick. iykyk πŸ’œ

πŸ’œ SEE ALSO πŸ’œ

  • Dispatcher(3I)
  • IOHandler(3I)

Go read those next, you know you want to. 🌸


InterViews Β· 21 December 1990 β€” mwah, thanks for reading, this page came straight from the InterViews reference manual and it's lowkey iconic for being this old and still this useful πŸ’…πŸ¦‹βœ¨ periodt.