I'm implementing a simple connection between a client and a server in C. In client side, I'm in a loop, reading from a file; every time BUFFER_SIZE bytes and sending it to the server side (didn't upload error handling).
//client side
bytesNumInput = read(inputFileFD,bufInput,BUFFER_SIZE)
bytesSend = write(sockfd,bufInput,bytesNumInput)
Of course the server is also in a loop.
//server side
bytesRecv = read(sockfd,bufOutput,bytesNumInput)
Now, my questions are:
- Can I get EOF in the middle of the connection if the server reads faster than the client?
- Does the read function wait to get all the data or is it the same as reading from a file?
- Is it possible the server will handle 2 read iteration in 1 write iteration?
read()
returnEOF
in the middle ..."? – Sidingread(inputFileFD,bufInput,BUFFER_SIZE)
is expectingBUFFER_SIZE
bytes, the end-of-file condition can occur in the middle of of that.read()
can return -1 for a variety of conditions after partially receiving some of theBUFFER_SIZE
bytes. – Sidingread()
returns, see my answer. The question is about sockets, not files, and it is about the middle of the connection, not the middle of the read. -1 is not an EOF when returned byread()
. Your question makes a distinction without a difference. – Tensile