<P>
<BR>
On Wed, 24 Aug 2005 Lars Eggert wrote :<BR>
&gt;On Aug 24, 2005, at 0:21, Alex Krivonosov (alexkr) wrote:<BR>
&gt;&gt;I have a TCP connection handled by the completion port IO model.&nbsp; What is happening is in case I specify a large buffer for receiving&nbsp; (WSARecv), the operation completes only after the buffer is full,&nbsp; not after receiving about 500 bytes (a packet), so a significant&nbsp; delay is introduced. In case of small buffers, performance&nbsp; degrades. Any advice on this? Completion port model is a must.<BR>
&gt;<BR>
&gt;Please understand that TCP doesn't deliver &quot;packets&quot; to the&nbsp; application, it provides a byte stream. You may want to look into&nbsp; using non-blocking I/O for the receive call. (I don't know what you&nbsp; mean by &quot;completion port model.&quot;)<BR>
&gt;<BR>
&gt;Lars<BR>
<BR>
What Lars said is right, TCP doen't deliver &quot;packets&quot; 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&nbsp; 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>
&nbsp; &nbsp; &nbsp; &nbsp; Error = WSAGetLastError(); <BR>
 <BR>
&nbsp; &nbsp; &nbsp; &nbsp; switch (Error) { <BR>
 <BR>
&nbsp; &nbsp; &nbsp; &nbsp; case WSAENETRESET:&nbsp; // flow through <BR>
&nbsp; &nbsp; &nbsp; &nbsp; case WSAECONNRESET: <BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;return FALSE;<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;case WSAEWOULDBLOCK:<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; WSAAsyncSelect (SOCKID, HWND, WM_TCP_NET_MESSAGE(uint), FD_CONNECT | FD_READ | FD_WRITE | FD_CLOSE);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; <BR>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return FALSE;<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;default:<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;return FALSE;<BR>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;}<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>