c5c8e590   
   From: barmar@alum.mit.edu   
      
   In article   
   <1536874d-dacd-4f1c-b4c1-070b2419c1d6@j9g2000prh.googlegroups.com>,   
    "zhangyefei.yefei@gmail.com" wrote:   
      
   > hi,all:   
   > i have a problem when using socket send function on windows.   
   > whether in the blocking or non-blocking mode,the following 'send'   
   > return immediately without error.and i found the receiver will   
   > receive data for a long time (because the data sent is large).it seems   
   > that windows os will send the data instead of my process after calling   
   > send function.   
   >   
   > in my opinion,when in blocking mode ,'send' should return   
   > error ,because the send buffer is small so that it can not hold all   
   > the 'size' data;   
   > when in non-blocking mode,'send' shoud return after sending some data   
   > less than 'size';   
   > can anyone tell me why so?   
   > is window socket very different of linux socket ?   
   > thanks.   
      
   That's not how Unix/Linux works.   
      
   In either mode, send() starts by buffering as much as it's able and   
   scheduling transmission. If it was able to buffer everything, it then   
   return success immediately.   
      
   If there wasn't enough room to buffer everything, that's when blocking   
   vs non-blocking matters.   
      
   In blocking mode, it blocks the process, waits for the buffer to be   
   transmitted, then buffers some more and schedules transmission. It   
   repeats this until it buffers the last chunk, then it returns.   
      
   In non-blocking mode, it depends on whether the buffer has some or no   
   space when you call. If there's no buffer space available, it returns   
   an EWOULDBLOCK error. If there's *some* buffer space available, it   
   buffers what it can, schedules transmission, and returns the amount that   
   it buffered. You can detect this latter case when iResult is >0 and   
      
   > the codes is(the result is same whether in blocking or non-bocking):   
   >   
   > u_long iMode = 1;//the same as iMode=0   
   > int il=ioctlsocket(ConnectSocket, FIONBIO, &iMode);   
   > int size=1024*1024*100;   
   > char *p= new char[size];   
   > memset(p,'a',size);   
   > iResult = send( ConnectSocket, p, size, 0 );   
   > if (iResult == SOCKET_ERROR && WSAGetLastError() !=   
   > WSAEWOULDBLOCK) {   
   > printf("send() failed with error: %d\n", WSAGetLastError());   
   > closesocket(ConnectSocket);   
   > WSACleanup();   
   > return 1;   
   > }   
      
   --   
   Barry Margolin, barmar@alum.mit.edu   
   Arlington, MA   
   *** PLEASE don't copy me on replies, I'll read them in the group ***   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|