Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created April 9, 2013 08:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizzy/5343931 to your computer and use it in GitHub Desktop.
Save mizzy/5343931 to your computer and use it in GitHub Desktop.
int sock = socket(PF_INET, SOCK_STREAM);
bind(sock, addr);
listen(sock);
allsock.add(sock);
while ( 1 ) {
result = select(sock);
if ( result > 0 ) {
int new_sock = accept(sock, &addr);
allsock.add(new_sock);
}
foreach ( sock = allsock ) {
result = select(sock);
if ( result > 0 ) {
char buf[100];
size_t size = read(new_sock, buf, 100);
if ( size == 0 ) {
close(new_sock);
}
else {
write(new_sock, buf, size);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment