explain_poll(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– explain_poll(3) β€” the group chat guide πŸ’–

okay bestie, sit DOWN, because we're about to make friends with explain_poll(3), a little library function from the Library Functions Manual that turns your cursed poll(2) errors into actual sentences. it's giving "therapist but for errno" and honestly? we're obsessed. 🫢


✨ NAME ✨

explain_poll β€” explain poll(2) errors πŸ’…


✨ SYNOPSIS ✨

#include <libexplain/poll.h>
const char *explain_poll(struct pollfd *fds, int nfds, int timeout);
const char *explain_errno_poll(int errnum, struct pollfd *fds, int nfds,
int timeout);
void explain_message_poll(char *message, int message_size, struct pollfd
*fds, int nfds, int timeout);
void explain_message_errno_poll(char *message, int message_size, int
errnum, struct pollfd *fds, int nfds, int timeout);

🌸 DESCRIPTION 🌸

so basically, these functions are your lil translators ✨ they hand you explanations for errors that come back from the poll(2) system call. no more staring at a cryptic number like it personally wronged you. 😭

πŸŽ€ explain_poll

const char *explain_poll(struct pollfd *fds, int nfds, int timeout);

the explain_poll function is how you get an explanation of an error that poll(2) threw back at you. the bare minimum the message will contain is the value of strerror(errno), but usually it does so much better than that and tells you the actual underlying cause in more detail. it's giving detective energy. πŸ”

the errno global variable is what gets used to obtain the error value that's gonna be decoded. she reads your mind (well, your errno).

  • fds β€” the original fds, exactly as passed to the poll(2) system call. we do not touch it, we do not improve it, we just report on it. periodt.
  • nfds β€” the original nfds, exactly as passed to the poll(2) system call.
  • timeout β€” the original timeout, exactly as passed to the poll(2) system call.

Returns: the message explaining the error. ⚠️ heads up bestie, this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. that means it will get overwritten by the next call to any libexplain function that shares this buffer β€” including calls from other threads. πŸ’€

Note: this function is not thread safe, because it shares a return buffer across all threads, and so do many other functions in this library. no cap.

Example: this function is intended to be used in a fashion similar to the following example:

int result = poll(fds, nfds, timeout);
if (result < 0)
{
    fprintf(stderr, "%s\n", explain_poll(fds, nfds, timeout));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_poll_or_die(3) function. so if you're feeling lazy (valid), that's your girl. πŸ’…


πŸ¦‹ explain_errno_poll

const char *explain_errno_poll(int errnum, struct pollfd *fds, int nfds,
int timeout);

the explain_errno_poll function is used to obtain an explanation of an error returned by the poll(2) system call. the least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. ✨

  • errnum β€” the error value to be decoded, usually obtained from the errno global variable just before this function is called. 🚨 this one matters: it's necessary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. like, they'll just change it on you. rude.
  • fds β€” the original fds, exactly as passed to the poll(2) system call.
  • nfds β€” the original nfds, exactly as passed to the poll(2) system call.
  • timeout β€” the original timeout, exactly as passed to the poll(2) system call.

Returns: the message explaining the error. this message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. this will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. 😭

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library.

Example: this function is intended to be used in a fashion similar to the following example:

int result = poll(fds, nfds, timeout);
if (result < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_poll(err, fds, nfds,
    timeout));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_poll_or_die(3) function. πŸŽ€


🧚 explain_message_poll

void explain_message_poll(char *message, int message_size, struct pollfd
*fds, int nfds, int timeout);

the explain_message_poll function is used to obtain an explanation of an error returned by the poll(2) system call. the least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. πŸ’–

the errno global variable will be used to obtain the error value to be decoded.

  • message β€” the location in which to store the returned message. 🌟 and here's the glow-up: if a suitable message return buffer is supplied, this function is thread safe. she did that.
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • fds β€” the original fds, exactly as passed to the poll(2) system call.
  • nfds β€” the original nfds, exactly as passed to the poll(2) system call.
  • timeout β€” the original timeout, exactly as passed to the poll(2) system call.

Example: this function is intended to be used in a fashion similar to the following example:

int result = poll(fds, nfds, timeout);
if (result < 0)
{
    char message[3000];
    explain_message_poll(message, sizeof(message), fds, nfds,
    timeout);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_poll_or_die(3) function. πŸ‘‘


🌈 explain_message_errno_poll

void explain_message_errno_poll(char *message, int message_size, int
errnum, struct pollfd *fds, int nfds, int timeout);

the explain_message_errno_poll function is used to obtain an explanation of an error returned by the poll(2) system call. the least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. πŸ”₯

  • message β€” the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe. 🫢
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • errnum β€” the error value to be decoded, usually obtained from the errno global variable just before this function is called. this is necessary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. again. they keep doing it. πŸ™ˆ
  • fds β€” the original fds, exactly as passed to the poll(2) system call.
  • nfds β€” the original nfds, exactly as passed to the poll(2) system call.
  • timeout β€” the original timeout, exactly as passed to the poll(2) system call.

Example: this function is intended to be used in a fashion similar to the following example:

int result = poll(fds, nfds, timeout);
if (result < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_poll(message, sizeof(message), err,
    fds, nfds, timeout);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_poll_or_die(3) function. πŸ“


πŸ’œ SEE ALSO πŸ’œ

  • poll(2) β€” wait for some event on a file descriptor
  • explain_poll_or_die(3) β€” wait for some event on a file descriptor and report errors

libexplain version 1.4 Copyright (C) 2010 Peter Miller


okay that's the whole page bestie, you ate that πŸ’…βœ¨ thanks for reading, mwah, go forth and decode your errnos like the main character you are πŸ¦‹πŸŒΈπŸ’– β€” explain_poll(3), signing off, Library Functions Manual energy only, iykyk πŸŽ€

πŸ“¦ where this page comes from