Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

01_rot13_server_select.c fixes #15

Merged
merged 2 commits into from almost 2 years ago

2 participants

Ross Lagerwall Nick Mathewson
Ross Lagerwall

A couple of fixes for 01_rot13_server_select.c.

Ross Lagerwall rosslagerwall Check return value of select for error 3aacef9
Ross Lagerwall 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
Nick Mathewson nmathewson merged commit 86a80f7 into from
Nick Mathewson
Owner

(Thanks, btw!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Sep 05, 2012
Ross Lagerwall rosslagerwall Check return value of select for error 3aacef9
Ross Lagerwall 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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 6 additions and 3 deletions. Show diff stats Hide diff stats

  1. +6 3 examples_01/01_rot13_server_select.c
9 examples_01/01_rot13_server_select.c
@@ -110,7 +110,7 @@ do_write(int fd, struct fd_state *state)
110 110 }
111 111
112 112 if (state->n_written == state->buffer_used)
113   - state->n_written = state->write_upto = state->buffer_used = 1;
  113 + state->n_written = state->write_upto = state->buffer_used = 0;
114 114
115 115 state->writing = 0;
116 116
@@ -123,7 +123,7 @@ run(void)
123 123 int listener;
124 124 struct fd_state *state[FD_SETSIZE];
125 125 struct sockaddr_in sin;
126   - int i, n, maxfd;
  126 + int i, maxfd;
127 127 fd_set readset, writeset, exset;
128 128
129 129 sin.sin_family = AF_INET;
@@ -177,7 +177,10 @@ run(void)
177 177 }
178 178 }
179 179
180   - n = select(maxfd+1, &readset, &writeset, &exset, NULL);
  180 + if (select(maxfd+1, &readset, &writeset, &exset, NULL) < 0) {
  181 + perror("select");
  182 + return;
  183 + }
181 184
182 185 if (FD_ISSET(listener, &readset)) {
183 186 struct sockaddr_storage ss;

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.