• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Listening, accepting, kqueue, WFT?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Listening, accepting, kqueue, WFT?


  • Subject: Listening, accepting, kqueue, WFT?
  • From: Scott Ribe <email@hidden>
  • Date: Sat, 19 Nov 2005 08:12:53 -0700
  • Thread-topic: Listening, accepting, kqueue, WFT?

OK, I do the normal set up on a socket for a server, then use this code to
listen for new connections:

        struct kevent kev, kevs[maxevts];
        EV_SET( &kev, sock, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0 );

        while( !err )
        {
            int evtcnt = kevent( kq, &kev, 1, kevs, maxevts, NULL );
            if( evtcnt == -1 )
                err = errno;
            else
            {
                for( int i = 0; i < evtcnt; ++i )
                {
                    if( kevs[i].flags & EV_ERROR )
                        LogInfoG( "error (", kevs[i].data, ") listening for
a connection." );
                    else
                    {
                        sockaddr_in sin;
                        socklen_t sinsiz = sizeof sin;
                        int csock = accept( sock, (sockaddr *) &sin, &sinsiz
);
                        if( csock == -1 )
                            LogInfoG( "error (", errno, ") accepting a
connection." );
                        else
                            new DbApp::Network::Server:: Connection( csock,
sin );
                    }
                }
            }
        }

This works properly for days and hundreds of connections, then stops
handling new connections. I caught it in the act yesterday, and saw from
tail -f on the log file that it was continuously writing "error (24)
accepting a connection". I used netstat and lsof to poke around, and there
were only a handful (~10?) of files open and the 20-30 connected sockets
that I expected, plus a half-dozen or so in close wait state (sudo lsof | wc
gave me about 3000 total for the server).

The rest of my app was functioning, and people were busy using it, so I
decided not to restart it. I went away for maybe an hour, came back, and
found that it had written >2.5GB into the log file, and subsequently exited
the loop and started accepting connections again. (It is highly likely that
during the time I was gone there were some normal disconnections.)

What could be happening???


--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 665-7007 voice


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Listening, accepting, kqueue, WFT?
      • From: Daniel Jalkut <email@hidden>
  • Prev by Date: Web Services Core: any way to use SSL?
  • Next by Date: Re: Listening, accepting, kqueue, WFT?
  • Previous by thread: Re: Web Services Core: any way to use SSL?
  • Next by thread: Re: Listening, accepting, kqueue, WFT?
  • Index(es):
    • Date
    • Thread