Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: kevent and wait time?



kqueue is not select/poll.

To better understand what I mean by that, consider calling kevent() once per FD you allocate and only use kevent() to add to the kqueue.

Then, as a part of your event loop, only fetch one event with kevent() and process it.

davez

On Apr 2, 2006, at 9:42 PM, email@hidden wrote:


Hello, all ...

I seem to have found my problem with my kqueue / kevent code, but it ends up perplexing me even more. The context is this: i'm seeing how far kqueues can scale in comparison to select() regarding # of active, simultaneous connections to a server -- C10K stuff, basically. I've written some C++ code that tests the kqueue by adding a specified number of descriptors to it, waiting for events from those descriptors, and seeing how many events from how many descriptors I can process in some configurable amount of time.

The thing is, my code only seems to work if I specify NULL for the timeout to kevent() -- kevent() comes back when one of the descriptors i've added to it indeed has something to tell me. However, if I specify a timeout of 0 (as a timeval), then kevent() comes back right away, telling me about some event on some descriptor i've never heard of (and didn't add to the queue) -- the descriptor is a really big number, which initially made me think "pointer bug", but simply changing the timeout to NULL (indefinite), makes everything work, which makes me thinkg "ok, so it's not a pointer bug."

The relevant piece of code follows -- it's really short :-)

// Test() tesks the kqueue by processing any notifications we get ...

        int Test( int iLimit )
        {
            int iReturn = 0;

for ( int iIndex = 0; iIndex < iLimit; iIndex ++ )
{
struct kevent kLEvent;
struct timespec timeToWait = { 0 };
int iNev = kevent( iKQ, pkEvents, iNumberOfConnectionsCreated, &kLEvent, 1, NULL /*&timeToWait*/ );


                testModule.Process( kLEvent, iNev );
            }

            testModule.ReportTestResults();
            return iReturn;
        }

I don't get it. The man page for kevent doesn't say anything about a non-NULL timeout (well, it's 0, but it's not NULL) affecting how kevent() works ... what am I doing wrong?

Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.com











_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >kevent and wait time? (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.