Re: why a non-blocking socket will block when call connect functio

From: Alun Jones [MSFT] (alunj_at_online.microsoft.com)
Date: 12/29/04


Date: Wed, 29 Dec 2004 09:17:54 -0800

I don't think Arkady's saying that this _is_ the cause of your problem, just
that it's a very strange thing to do, and that removing strangeness has all
kinds of benefits, including that it tends to fix strange behaviour.

In this case, however, I think we need to see more of your code.

Try creating a small sample client that demonstrates the problem - creates a
socket, calls ioctlsocket to set it non-blocking, and then calls connect.
If your small sample does demonstrate the problem, then post it here; if it
doesn't show the problem, start adding some of the extra parts from your
failing program into the sample until it either reproduces the problem, or
you find out what is wrong in your main program.

Whatever the result, post it back here, so we can all learn.

Alun.
~~~~

-- 
Software Design Engineer, Internet Information Server (FTP)
This posting is provided "AS IS" with no warranties, and confers no rights.
"WHY non-blocking socket doesn't work!!!!" 
<WHYnonblockingsocketdoesntwork@discussions.microsoft.com> wrote in message 
news:ED1280EA-52BF-4E1C-8090-4EDAD9208991@microsoft.com...
> thanks for Arkady Frenkel's reply.
>  There is a writing mistake: I REALLY USE "&non_block" in that client
> program, not "non_block".
>  And, do you mean "set SO_REUSEADDR in client" cause this problem? but 
> this
> program has  run for about 3 years in many computers, and this is the 
> first
> time that find this problem.
>
> "Arkady Frenkel"??:
>
>> You need to change non_block to &non_block in ioctlsocket call.
>> And don't set SO_REUSEADDR in client , that for server only BTW,
>> unless you have multihomed computer.
>> Arkady
>>
>> "WHY non-blocking socket doesn't work!!!!" <WHY non-blocking socket 
>> doesn't
>> work!!!!@discussions.microsoft.com> wrote in message
>> news:7DB65951-8325-4789-ADAA-E696699A92B1@microsoft.com...
>> >   i'm encountering a strange problem:
>> >   a client program allocate a socket and call ioctlsocket to set it
>> > non-blocking(resource code as following),then call connect for 
>> > connecting
>> > server. but if there is not a computer has the ip "192.1.9.18" in 
>> > network,
>> > the connect call will block for about 25 seconds.
>> >    BUT THERE IS JUST ONE client program running on ONE computer has 
>> > this
>> > problem. is this caused by virus? or firewall software? this computer 
>> > had
>> > installed a firewall software and it is uninstalled  now. but still has
>> this
>> > problem.
>> >
>> > //-----------------------------------------------------------
>> >   struct sockaddr_in addr;
>> >   addr.sin_family = AF_INET;
>> >   addr.sin_addr.s_addr = inet_addr("192.1.9.18");
>> >   addr.sin_port = htons((9050);
>> >
>> >   SOCKET sock = socket(AF_INET,SOCK_STREAM,0);
>> >   if(sock == INVALID_SOCKET)
>> >   {
>> >       return -1;
>> >   }
>> >
>> >   int reuse = 1;
>> >   if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char*)&reuse,
>> >       sizeof(int)) != 0)
>> >   {
>> >       closesocket(sock);
>> >       return -1;
>> >   }
>> >
>> >   unsigned long non_block = 1;
>> >   if(ioctlsocket(pCommNe->ConnectSocket, FIONBIO,
>> >     non_block) != 0)
>> >   {
>> >       closesocket(sock);
>> >       return -1;
>> >   }
>> > //-----------------------------------------------------------
>>
>>
>> 


Relevant Pages

  • Re: .NET Remoting performance problems
    ... that's very strange behavior indeed. ... consisting of a server application and a client application. ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Strange DNS server change on a client.
    ... I was able to trace the problem, but still the behaviour looks strange. ... Changed it to local names server and all is OK. ... in Domain Group policy I had temporarily set DNS server to ISP's ... gpupdate the client gp also gets updated or not. ...
    (microsoft.public.windows.server.dns)
  • Re: ssh X11forwarding wont work, please help
    ... that's strange enough that I can't think of anything to suggest. ... >>It does this by the ssh server process operating as a local X process ... >>on the same machine as the X clients, and the ssh client process operating ...
    (comp.os.linux.x)
  • strange save-delay (btrieve 8.x)
    ... today we observe a very strange behavior at a PSQL 8.x server running on Win2000: ... on client A there where updated some data, but this change of data was on client ... that the server does someting like write-chaching. ...
    (comp.databases.btrieve)
  • Win2k Pro + Internet Connection Sharing Problem
    ... I've got something of a strange and rather annoying situation here. ... which is configured for internet connection sharing. ... network to try and use the ICS to get to the internet, ... host, not the client, as the client works fine on other networks. ...
    (microsoft.public.win2000.general)

Quantcast