spmlingam's answer does address your problem. When B is about to write, use select to check if there's anything to read. If there's is, read until there isn't. Then proceed to write.
sathiya.sw's shutdown solution sounds more promising, though.
| [reply] [d/l] [select] |
As I already said in my earlier post, I did the select and read already.
I predicted that the read side of the socket is full in B side, so I started to read the data from B's side also apart from writing, the problem got solved.
The shutdown method worked. Thanks for that solution.
One more question
Even after shutting down the read side of the B socket, the B's socket->can_read is saying that some data is available for reading(but doing a <Bsocket> returns undef), why it is like this?.
| [reply] |
This allows errors and eof to be handled.
| [reply] |
this is how the select(2) works. From man select:
select() and pselect() allow a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready" for some class of I/O operation (e.g., input possible). A file descriptor is considered ready if it is possible to perform the corresponding I/O operation (e.g., read(2)) without blocking.
So can_read returns true if you can read without blocking, and you can.
| [reply] |