<P>
<BR>
On Wed, 24 Aug 2005 Lars Eggert wrote :<BR>
>On Aug 24, 2005, at 0:21, Alex Krivonosov (alexkr) wrote:<BR>
>>I have a TCP connection handled by the completion port IO model. What is happening is in case I specify a large buffer for receiving (WSARecv), the operation completes only after the buffer is full, not after receiving about 500 bytes (a packet), so a significant delay is introduced. In case of small buffers, performance degrades. Any advice on this? Completion port model is a must.<BR>
><BR>
>Please understand that TCP doesn't deliver "packets" to the application, it provides a byte stream. You may want to look into using non-blocking I/O for the receive call. (I don't know what you mean by "completion port model.")<BR>
><BR>
>Lars<BR>
<BR>
What Lars said is right, TCP doen't deliver "packets" to the application. Now in your case I think it is going into the blocking mode.<BR>
One way to verify is, check the return value, <BR>
Result = WSARecv(....)<BR>
<BR>
If the socket is non blocking , it would return WSAEWOULDBLOCK.<BR>
You have to handle this case using WSAAsyncSelect(SOCKET id , HWND , uint msg,combination of events(like FD_READ,FD_WRITE , etc)<BR>
Now handle these messages(FD_READ for reading,....) in ur WindowProc of the window specified.<BR>
You have to go through the MSDN document to get a clear picture...<BR>
<BR>
u can use the chunk of code illustarted below:<BR>
Result = WSARecv(....)<BR>
<BR>
if (Result == SOCKET_ERROR) { <BR>
<BR>
Error = WSAGetLastError(); <BR>
<BR>
switch (Error) { <BR>
<BR>
case WSAENETRESET: // flow through <BR>
case WSAECONNRESET: <BR>
return FALSE;<BR>
case WSAEWOULDBLOCK:<BR>
WSAAsyncSelect (SOCKID, HWND, WM_TCP_NET_MESSAGE(uint), FD_CONNECT | FD_READ | FD_WRITE | FD_CLOSE);<BR>
<BR>
return FALSE;<BR>
default:<BR>
return FALSE;<BR>
<BR>
}<BR>
<BR>
Well I'm not sure whether this is what u wanted nevertheless this might still help.<BR>
<BR>
Regards,<BR>
Sampad Mishra.<BR>
</P>
<br><br>
<a href="http://adworks.rediff.com/cgi-bin/AdWorks/sigclick.cgi/www.rediff.com/signature-home.htm/1507191490@Middle5?PARTNER=3"><IMG SRC="http://adworks.rediff.com/cgi-bin/AdWorks/sigimpress.cgi/www.rediff.com/signature-home.htm/1963059423@Middle5?OAS_query=null&PARTNER=3" BORDER=0 VSPACE=0 HSPACE=0></a>