Reputation: 455
I have two processes with a socket connection. One process is writing one thing to the socket and then close the connection. The other process waits on listen and when the connection accepted, it enters a loop of 'read' so it will get the message from the first process and do whatever it has to do with it, and later waits for other messages from the first process. When the first process is closed, the second process is reading the same message over and over again, and of course, do whatever it has to do with it, again and again.. Whats happened here and how do i pass it?
Upvotes: 0
Views: 523
Reputation: 311039
You must be ignoring the EOS condition, and probably ignoring the value returned by read() altogether. It returns a positive byte count, or zero at EOS, or -1 on an error with an accompanying errno. If you get zero you must close the socket and stop reading; if you get -1 in most cases ditto; if you get a positive byte count you must only process that many bytes in the read buffer.
Upvotes: 2
Reputation: 107002
Hard to say without the code at hand, but I've always written my socket code based on Beej's guide and it's never failed. Perhaps you can find your answer there.
Upvotes: 0