.NET Forum / .NET Framework / Performance / June 2008
Sockets Winsock Winsock2 - win 2000 versus 2003, 2008 recv
|
|
Thread rating:  |
kk - 10 Jun 2008 22:48 GMT I have stream_socket
...following information incoming to the buffer:
a,b,c,\r,\n,z which means -> 6 bytes
i am reading as from Microsoft example:
// Receive until the peer closes the connection do {
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0); if ( iResult > 0 ) printf("Bytes received: %d\n", iResult); else if ( iResult == 0 ) printf("Connection closed\n"); else printf("recv failed: %d\n", WSAGetLastError());
} while( iResult > 0 );
I set recvbuflen = 2 ( so i am reading in 2 bytes sets)
On Win 2003 and beyond (including 2008)
i will always get iResult = 2
resulting in \n,z (2) read
Whereas win 2000 will give me iResult = 1
reading only \n - in the last cycle, not reading "z"
I do not have MSG_OOB set - i do not intend to (it is 0 - zero)
Any comments please....
KK
Goran Sliskovic - 13 Jun 2008 11:37 GMT > I have stream_socket > [quoted text clipped - 34 lines] > > KK Well, this looks like Win32 API call, not .NET framework (wrong newsgroup). However, setting the recv buffer to 2 does not mean you'll always receive exactly 2 bytes in recv, but rather that you'll receive *up to 2* bytes. So behaviour is correct. Also, setting the recv buffer so low can lead to performance degradation (serious if your program communicates a lot). Generally, you should always try to read as much data as possible (available) in one system call.
Regards, Goran
kk - 13 Jun 2008 16:33 GMT Goran
thank you for interest,
I was looking for un-Net groups, but there was other questions about 2003 TCPIP performance here, so I did put it here in this group -
Exactly as you said, I am expecting in win >2003 to get less than 2 (or 1000 etc..) but the api returns all - not marking \r\n break with returned count 1 - iResult = 1 - (what 2000 does)
So why behavior changed - it is like that on UNIX (like 2000 not 2003)
 Signature kk
> > I have stream_socket > > [quoted text clipped - 45 lines] > Regards, > Goran Goran Sliskovic - 13 Jun 2008 16:54 GMT > Goran > [quoted text clipped - 10 lines] > > So why behavior changed - it is like that on UNIX (like 2000 not 2003) ...
So, in 2003 you get 2 by 2 bytes:
a,b c,\r \n,z
while in 2000 you get: a b c \r \n z
?
The number of returned bytes is only guaranteed to return <= buflen bytes, nothing more. So both options are ok, however it's unlikly to see second option if bytes are buffered by the OS. Which should be buffered, unless you send slow on the other side. How do you send data? Whole line at once (6 bytes)?
Regards, Goran
kk - 16 Jun 2008 21:46 GMT Goran
I am glad that you are interested...
Let me rephrase my question: Looks like 2000 was recognizing CRLF sequence in the buffer \r,\n (or rather \n LF only) ; but 2003 and 2008 does not recognize it....
I was asking Microsoft :-) if it is by design (UNIX recognize LF)
It means that if I read c,\r,\n, a, b ... sequence reading by two characters on win 2000 i will read c,\r then \n,a (but the system will return only one char read \n so on the next read from the buffer I am starting with the new line a,b...
whereas 2003 will read \n,a .... and return 2 char read
if I read 100 2000 will read c,\r\n (3) whereas 2003 and 2008 will read c,\r,\n\,a,b...
Just the question of why did they changed , are they aware of the change , why then return number of character read?
What will stop it - NULL 0x0000?
 Signature kk
> > Goran > > [quoted text clipped - 37 lines] > Regards, > Goran Goran Sliskovic - 19 Jun 2008 11:18 GMT > Goran > [quoted text clipped - 22 lines] > > What will stop it - NULL 0x0000? ...
Hm, I don't think any windows version would do anything about CR/LF, as socket functions are working with binary data. However, the behaviour you see is still technicly correct on both 2000 and 2003. How are you sending data? Maybe there is some timing issue with sends?
Regards, Goran
kk - 19 Jun 2008 17:20 GMT The difference is between 2000 and 2003 (2008)
I gave up - and did it right way by PEEK ing - on cr/lf
on 2084 buffer to suite your case :-) (not 2 bytes)
anyway great talking to you Goran, thank you for your interest
one day I will double check rfc..s to see if LF is treated with honours
in the meantime back to work ....
 Signature kk
> > Goran > > [quoted text clipped - 33 lines] > Regards, > Goran
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|