Jump to content
  • Advertisement
Sign in to follow this  
NekoCode

"socket" takes too much time to initialize

This topic is 1522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by NekoCode

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Edited by Erik Rufelt

Share this post


Link to post
Share on other sites

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 ???

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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? Edited by hplus0603

Share this post


Link to post
Share on other sites

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.

Edited by NekoCode

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!