Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io_poller docs, and features. #45

Merged
merged 5 commits into from
Mar 13, 2022
Merged

io_poller docs, and features. #45

merged 5 commits into from
Mar 13, 2022

Conversation

Anotra
Copy link
Contributor

@Anotra Anotra commented Mar 13, 2022

What?

Changes all relate to io_poller
Added documentation, extra param struct io_poller *io to io_poller_callbacks and a new function discord_get_io_poller()

Why?

Eliminate the requirement for the user to have a separate thread when they want to poll their own file descriptors

simple example using stdin

static void
on_stdin(struct io_poller *io, enum io_poller_events events, void *data) {
  struct discord *client = data;
  char buf[4096];
  int n = read(STDIN_FILENO, buf, sizeof buf);
  write(STDOUT_FILENO, buf, n);
}

int
main(void) {
  struct discord *client = discord_config_init("config.json");
  struct io_poller *io = discord_get_io_poller(client);
  io_poller_socket_add(io, STDIN_FILENO, IO_POLLER_IN, on_stdin, client);
  discord_run(client);
}

@lcsmuller lcsmuller merged commit aa40e93 into Cogmasters:dev Mar 13, 2022
@Anotra Anotra deleted the io_poller branch April 3, 2022 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants