Problem about kqueue.

Neelkanth Natu neelnatu at yahoo.com
Wed May 7 22:21:03 PDT 2003


--- Snofe Deng <dsnofe at hotmail.com> wrote:
> If I register:
> {ident, EVFILT_READ}
> {ident, EVFILT_WRITE}
> {ident, EVFILT_TIMER} 
> pairs to kq;and all the piar with same ident which is a socket descriptor.
> then I close(2) ident. Does this mean that all these three 
> {ident, filter} pairs will be removed just after the descriptor isclosed?

No. The EVFILT_TIMER ident has a different namespace than the
file descriptor namespace. The fact that the ident value for TIMER
is the same as the socket fd is of no significance.

> or should I use:
> EV_SET(&evs, ident, EVFILT_READ, EV_DELETE, 0, 0, NULL)
> EV_SET(&evs, ident, EVFILT_WRITE, EV_DELETE, 0, 0, NULL)
> EV_SET(&evs, ident, EVFILT_TIMER, EV_DELETE, 0, 0, NULL)
> to delete these three pairs?
> 
> when I just closed the socket descriptor, the {ident,
> EVFILT_READ/EVFILT_WRITE} are removed. but {ident, EVFILT_TIMER}
> is still returned at next kevent(2) loop. Is it a bug? or why should
> this happend?

It is not a bug. Calling a close on a file descriptor will remove
all kevents associated with that fd. So you don't have to explicitly
delete them.

However if you want to remove the EVFILT_TIMER event too, you have 
two choices:
- Use EV_ONESHOT to automatically delete the kevent once it is
  delivered.
- Explicitly delete it as you are doing above.

best
Neel

> 
> when I use the second way, things worked ok.
> Any one can help me?
> thanks a lot!
> 
> -- 
> Snofe Deng <dsnofe at hotmail.com>
> 
> 
> _______________________________________________
> freebsd-net at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-net
> To unsubscribe, send any mail to "freebsd-net-unsubscribe at freebsd.org"


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


More information about the freebsd-net mailing list