[cs631apue] why does fd 4 get re-used?

jphillip jphillip at stevens.edu
Sat Dec 8 15:03:03 EST 2012


Nevermind, I was closing the file descriptor.  Makes sense :)

On Sat, 08 Dec 2012 14:50:17 -0500, jphillip wrote:
> Accept returns me a fd of 4.  I fork a child to handle the connection
> and in that child I call the open command to read from the requested
> file.  Open also returns a fd of 4 and I can no longer send a reply 
> to
> the socket which had fd 4.  Any ideas why?  here is some debug from 
> my
> program:
>
> [file request.c, line 238]: Reading request from socket 4
> [file request.c, line 295]: Received GET request
> [file request.c, line 308]: DECODED URI=t1/xyz
> [file request.c, line 352]: Got full request version 1.0
> [file response.c, line 101]: REQUEST FOR HTTP FILE:
> /home/jphillip/Final/sws/t1/xyz
> [file response.c, line 35]: Open resource for read-only, open 
> returned fd=4
> [file response.c, line 41]: allocated read buf of size 1048576 bytes
> [file response.c, line 47]: read 27 bytes from file: THIS IS THE FILE
> CONTENTS
>
>
> [file response.c, line 70]: failed to write 27 bytes of file data to
> socket fd 4: Bad file descriptor
>
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/cgi-bin/mailman/listinfo/cs631apue



More information about the cs631apue mailing list