Skip to content

Instantly share code, notes, and snippets.

@rudimeier
Created March 9, 2012 18:48
Show Gist options
  • Save rudimeier/2008021 to your computer and use it in GitHub Desktop.
Save rudimeier/2008021 to your computer and use it in GitHub Desktop.
simple code for testing select behaviour on MacOSX
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/select.h>
int main(int argc, char *argv[])
{
int nfds = (argc > 1) ? atoi(argv[1]) : 0;
struct timeval tval;
tval.tv_usec = 100 * 1000;
tval.tv_sec = 0;
if( select(nfds, NULL, NULL, NULL, &tval) < 0 ) {
printf("select NULL failed: %s.\n", strerror(errno));
}
fd_set readSet, writeSet;
FD_ZERO( &readSet);
FD_ZERO( &writeSet);
if( select(nfds, &readSet, &writeSet, NULL, &tval) < 0 ) {
printf("select ZERO failed: %s.\n", strerror(errno));
}
printf("finito\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment