D
David J. Marcus
Hi
The platform: XP/pro on a dual Xeon 3GH processors
I am using TcpClient class to communicate with a POP3 server.
Short problem synopsis: a 'read' hangs even though there is data in the
buffer (as evidenced by a network sniffer trace).
Elaboration:
I/O is done by getting the NetworkStream and doing a read for a whole
buffer's worth (typically 1024) of bytes.
The code looks for the NL (new-line char, '\n'), as a delimiter. If found,
the text up to and including the NL is returned to the caller. Otherwise
another read is performed and concatenated to the previous read's output,
and the check for the delimiter repeats. On subsequent reads, if there was
data left over from the previous read, it is processed for NL before any
other reads are issued.
I have used a network sniffer to determine that all the data is coming in.
I have put a trace in my program to output to a file (serialized with a
'lock') all the output form all the read requests.
I consistently find that one of the reads is able to get all but the last 3
bytes of a response from a server. The code dutifully returns all the text
received and tries to do another read since the caller is looking for a
'.\r\n' sequence (end-of-message). This read hangs (I use the debugger).
When I change the buffer size the problem happens in a different message. If
I make the buffer large enough, the problem goes away.
The buffering code described above is working for thousands of messages that
have split across multiple buffers or for short messages where multiple fit
in the same buffer, so I'm pretty confident that it is splitting messages
correctly and gluing together segments across network messages.
My only conclusion is that something in the TcpClient (or deeper) is
checking the socket and waiting for more data in a non-atomic manner. The
problem shows up on my system because it is a fast dual processor system
that can obviously do concurrent processing by multiple threads/processes.
Has any one seen this kind of problem before?
Any work-around?
-TIA
David
The platform: XP/pro on a dual Xeon 3GH processors
I am using TcpClient class to communicate with a POP3 server.
Short problem synopsis: a 'read' hangs even though there is data in the
buffer (as evidenced by a network sniffer trace).
Elaboration:
I/O is done by getting the NetworkStream and doing a read for a whole
buffer's worth (typically 1024) of bytes.
The code looks for the NL (new-line char, '\n'), as a delimiter. If found,
the text up to and including the NL is returned to the caller. Otherwise
another read is performed and concatenated to the previous read's output,
and the check for the delimiter repeats. On subsequent reads, if there was
data left over from the previous read, it is processed for NL before any
other reads are issued.
I have used a network sniffer to determine that all the data is coming in.
I have put a trace in my program to output to a file (serialized with a
'lock') all the output form all the read requests.
I consistently find that one of the reads is able to get all but the last 3
bytes of a response from a server. The code dutifully returns all the text
received and tries to do another read since the caller is looking for a
'.\r\n' sequence (end-of-message). This read hangs (I use the debugger).
When I change the buffer size the problem happens in a different message. If
I make the buffer large enough, the problem goes away.
The buffering code described above is working for thousands of messages that
have split across multiple buffers or for short messages where multiple fit
in the same buffer, so I'm pretty confident that it is splitting messages
correctly and gluing together segments across network messages.
My only conclusion is that something in the TcpClient (or deeper) is
checking the socket and waiting for more data in a non-atomic manner. The
problem shows up on my system because it is a fast dual processor system
that can obviously do concurrent processing by multiple threads/processes.
Has any one seen this kind of problem before?
Any work-around?
-TIA
David