Chris
Fri Nov 24 14:35:56 CST 2006
The .Net Async socket stuff is very, very, very solid. We transfer... well,
wel transfer alot of data under very high load conditions with extreme
reliabiilty and don't see the errors your describing.
There are some potential issues that you may be running into:
- reusing the buffer from another thread by mistake.
- calling read again with the same buffer prior to parsing it
- calling write somewhere using that same buffer prior to parsing it
I see also that you're expecting your data to be UTF-8 encoded. If you get a
partial read of data, and that data happens to end with an incomplete UTF-8
sequence then your "GetString" call will thow an exception. Keep in mind
here that while a UTF-8 character is typically just 1 byte, it can be as
many as 4.
> So I added a special case in my code if it finds XXXX I treat it like
> hello, but that is a hack.
Seeing as what you've described is 95%+ a thread bug, I think this hack is
likley to lead to signifigant trouble down the line.
Can you post the relevant code snippets? The pieces I would need to see are:
- the buffer allocation
- the initial call into BeginRead
- the BeginRead callback function and it's call to EndRead
- the subsiquest call into BeginRead (usually inside the callback, but not
always)
- the set of BeginWrite/Callback/Endwrite method. Especially their buffer
allocations.
--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
"EmeraldShield" <emeraldshield@noemail.noemail> wrote in message
news:u$N%23gntDHHA.4992@TK2MSFTNGP03.phx.gbl...
>I have been fighting a problem for about two weeks and I can't seem to find
>any info on it. Any help is greatly appreciated.
>
> We have an ASYNC I/O system for email receptions (in bound email).
> This service has been working very well for years. I upgraded it to Dot
> Net 2 / VS 2005 and moved over to the Async I/O model for better
> performance. It works great.
>
> BUT, every now and then I will get a corrupt buffer. The first 4 bytes of
> a connection will be XXXX instead of HELO or EHLO (Even though they sent
> one of those two commands). It is ALWAYS XXXX.
>
> This is the call inside the AsyncCallback for the read operation:
> mystring = Encoding.UTF8.GetString(sp.ReadInBuffer, 0,
> sp.ReadInBufferSize);
>
> I cannot get it to repeat in a pattern that I could actually sit in a
> debugger and watch it.
>
> So I added a special case in my code if it finds XXXX I treat it like
> hello, but that is a hack.
>
> Very odd.
>
>