Commit ec3db75b authored by Robert Ricci's avatar Robert Ricci

Fix two bugs -

First, treat the return from read() as an int instead of an ssize_t.
The latter is the official return type of read, but it's unsigned,
so when read() returns a -1 on error, it looks like a huge positive
number. Stupid. Whose fault is this? POSIX's?

Second, make sure we never try to read on the listen socket.

The result of these two bugs was that I was reading from the listen
socket, and it was failing and returning -1, but that looked like
a successful read.
parent 2352ba10
......@@ -102,18 +102,18 @@ int main() {
/*
* Now, check to see if any clients have sent us any data
*/
for (i = sockfd; i <= max_clientfd; i++) {
for (i = sockfd + 1; i <= max_clientfd; i++) {
if (FD_ISSET(i,&returned_fdset)) {
char *buf[1024];
size_t bufsize = 1024;
size_t read_bytes;
int read_bytes;
read_bytes = read(i,buf,bufsize);
if (read_bytes >= 1) {
/*
* Okay, this client had data for us, let's copy that back out
* to stdout
* Okay, this client had data for us, let's copy that back
* out to stdout
*/
write(1,buf,read_bytes);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment