Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

01_rot13_server_select.c fixes #15

Merged
merged 2 commits into from

2 participants

@rosslagerwall

A couple of fixes for 01_rot13_server_select.c.

rosslagerwall added some commits
@rosslagerwall rosslagerwall Check return value of select for error 3aacef9
@rosslagerwall rosslagerwall Fix typo in 01_rot13_server_select.c
Erroneously resetting n_written and buffer_used back to 1 would
leave a gap at the beginning of the buffer, filled with the very
first character that was received.
8005f74
@nmathewson nmathewson merged commit 86a80f7 into from
@nmathewson
Owner

(Thanks, btw!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 5, 2012
  1. @rosslagerwall
  2. @rosslagerwall

    Fix typo in 01_rot13_server_select.c

    rosslagerwall authored
    Erroneously resetting n_written and buffer_used back to 1 would
    leave a gap at the beginning of the buffer, filled with the very
    first character that was received.
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 3 deletions.
  1. +6 −3 examples_01/01_rot13_server_select.c
View
9 examples_01/01_rot13_server_select.c
@@ -110,7 +110,7 @@ do_write(int fd, struct fd_state *state)
}
if (state->n_written == state->buffer_used)
- state->n_written = state->write_upto = state->buffer_used = 1;
+ state->n_written = state->write_upto = state->buffer_used = 0;
state->writing = 0;
@@ -123,7 +123,7 @@ run(void)
int listener;
struct fd_state *state[FD_SETSIZE];
struct sockaddr_in sin;
- int i, n, maxfd;
+ int i, maxfd;
fd_set readset, writeset, exset;
sin.sin_family = AF_INET;
@@ -177,7 +177,10 @@ run(void)
}
}
- n = select(maxfd+1, &readset, &writeset, &exset, NULL);
+ if (select(maxfd+1, &readset, &writeset, &exset, NULL) < 0) {
+ perror("select");
+ return;
+ }
if (FD_ISSET(listener, &readset)) {
struct sockaddr_storage ss;
Something went wrong with that request. Please try again.