Advertisement

"socket" takes too much time to initialize

Started by October 11, 2014 05:57 PM
6 comments, last by NekoCode 10 years, 1 month ago

Hey guys & girls,

I have noticed one thing on iOS/Mac systems ( Unix-wide, I think ): When I try to initialize network socket, it takes 10-20 seconds to create. Here's code:


    
   _core.Print( LOG_INFO, "Creating network socket using udp protocol..\n" );
    if( ( NetworkSocket = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP )) == - 1 ) {
        return;
    }

On application quit I do this:


    shutdown( NetworkSocket, 2 );
    close( NetworkSocket );

On Windows it's okay, takes some milliseconds.

What may be a problem? I already tried to null the NetworkSocket. No results.

That should not be a problem. Calling socket() takes a very small amount of time on my machine.
Perhaps you have some scary firewall, or some on-demand network configuration, set up?
enum Bool { True, False, FileNotFound };
Advertisement
Are you 100% sure it's the call to socket() and not bind() or connect()? It seems really weird for socket() to take much time.

I can find literally zero other people having this problem on the Internet.

Sean Middleditch – Game Systems Engineer – Join my team!

Add log-messages before and after every call on the socket and see which one takes time. (Or just add break-points in the debugger and step over the calls).

Since you show your shutdown code I assume the time is including this.. in which case I would guess that shutdown() blocks and the remote end doesn't acknowledge which causes it to wait for timeout.

Some horribly long timeout ....

Smacks of an oldie security method of stalling a access attempt before returning the request to magnitudily slow down a brute force attempt to grab a socket (to something that isnt normally authorized that resource, but isnt outright blocked/disabled)

OS Security level/ Resource authorization for the process attempting to run this ???

--------------------------------------------[size="1"]Ratings are Opinion, not Fact

I do "bind" after the socket creation. It's UDP, so I don't need to "connect".

That's strange thing, I don't think that it should take that much time.

Advertisement
By the way, you don't really need to shutdown UDP sockets.
(Actually, you don't need to shutdown TCP sockets, either, but it's slightly better form to do it than not to.)

If really the call to socket is taking more than a few milliseconds, something's wrong or special with your system.
Is it virtualized?
What kind of networking hardware are you using?
If you run "top" or "vmstat -n" or whatever while this is going on (waiting in socket()), are you seeing CPU, I/O, or other problems?
Are there known problems with the particular network adapter/driver you're using?
What if you use a USB network adapter instead, or an add-in card?
enum Bool { True, False, FileNotFound };

No, it's not virtualized. My current "hardware" is MacBook. ( built-in wifi card, I don't have any adapter ) and iPhone 5s ( the same prob here ).

Aaaand I have noticed one thing: when there is no access to internet, socket freezes, but when internet connection is available, it's fast. But on i5s it's always freezes.

This topic is closed to new replies.

Advertisement