xref: /netbsd-src/share/man/man9/select.9 (revision 05859157e6397edc63b68f9cbff294ac7b3790e4)
1*05859157Swiz.\"     $NetBSD: select.9,v 1.5 2010/12/02 12:54:13 wiz Exp $
22fd89ef8Srmind.\"
32fd89ef8Srmind.\" Copyright (C) 2002 Chad David <davidc@acns.ab.ca>. All rights reserved.
42fd89ef8Srmind.\"
52fd89ef8Srmind.\" Redistribution and use in source and binary forms, with or without
62fd89ef8Srmind.\" modification, are permitted provided that the following conditions
72fd89ef8Srmind.\" are met:
82fd89ef8Srmind.\" 1. Redistributions of source code must retain the above copyright
92fd89ef8Srmind.\"    notice(s), this list of conditions and the following disclaimer as
102fd89ef8Srmind.\"    the first lines of this file unmodified other than the possible
112fd89ef8Srmind.\"    addition of one or more copyright notices.
122fd89ef8Srmind.\" 2. Redistributions in binary form must reproduce the above copyright
132fd89ef8Srmind.\"    notice(s), this list of conditions and the following disclaimer in the
142fd89ef8Srmind.\"    documentation and/or other materials provided with the distribution.
152fd89ef8Srmind.\"
162fd89ef8Srmind.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
172fd89ef8Srmind.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
182fd89ef8Srmind.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
192fd89ef8Srmind.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
202fd89ef8Srmind.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
212fd89ef8Srmind.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
222fd89ef8Srmind.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
232fd89ef8Srmind.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242fd89ef8Srmind.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252fd89ef8Srmind.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
262fd89ef8Srmind.\" DAMAGE.
272fd89ef8Srmind.\"
282fd89ef8Srmind.\" $FreeBSD: src/share/man/man9/selrecord.9,v 1.2 2002/05/30 13:29:17 ru Exp $
292fd89ef8Srmind.\"
302fd89ef8Srmind.\" FreeBSD: .Dd March 20, 2002
3188a92b67Stnn.Dd May 13, 2008
322fd89ef8Srmind.Dt SELECT 9
332fd89ef8Srmind.Os
342fd89ef8Srmind.Sh NAME
352fd89ef8Srmind.Nm seldestroy ,
362fd89ef8Srmind.Nm selinit ,
372fd89ef8Srmind.Nm selrecord ,
382fd89ef8Srmind.Nm selnotify
392fd89ef8Srmind.Nd select and poll subsystem
402fd89ef8Srmind.Sh SYNOPSIS
412fd89ef8Srmind.In sys/param.h
422fd89ef8Srmind.In sys/select.h
432fd89ef8Srmind.Ft void
442fd89ef8Srmind.Fn seldestroy "struct selinfo *sip"
452fd89ef8Srmind.Ft void
462fd89ef8Srmind.Fn selinit "struct selinfo *sip"
472fd89ef8Srmind.Ft void
482fd89ef8Srmind.Fn selrecord "struct lwp *selector" "struct selinfo *sip"
492fd89ef8Srmind.Ft void
502fd89ef8Srmind.Fn selnotify "struct selinfo *sip" "int events" "long knhint"
512fd89ef8Srmind.Sh DESCRIPTION
522fd89ef8Srmind.Fn selinit
532fd89ef8Srmindand
542fd89ef8Srmind.Fn seldestroy
552fd89ef8Srmindfunctions must be used to initialize and destroy the
562fd89ef8Srmind.Va struct selinfo .
572fd89ef8SrmindThe
582fd89ef8Srmind.Fn seldestroy
592fd89ef8Srmindfunction may block.
602fd89ef8Srmind.Pp
612fd89ef8Srmind.Fn selrecord
622fd89ef8Srmindand
6388a92b67Stnn.Fn selnotify
642fd89ef8Srmindare used by device drivers to coordinate
652fd89ef8Srmindwith the kernel implementation of
662fd89ef8Srmind.Xr select 2
672fd89ef8Srmindand
682fd89ef8Srmind.Xr poll 2 .
692fd89ef8SrmindEach object that can be polled contains a
702fd89ef8Srmind.Dv selinfo
712fd89ef8Srmindrecord.
722fd89ef8SrmindDevice drivers provide locking for the
732fd89ef8Srmind.Dv selinfo
742fd89ef8Srmindrecord.
752fd89ef8Srmind.Pp
762fd89ef8Srmind.Fn selrecord
772fd89ef8Srmindrecords that the calling thread is interested in events related to a given
782fd89ef8Srmindobject.
792fd89ef8Srmind.Fn selrecord
802fd89ef8Srmindshould only be called when the poll routine determines that the object
812fd89ef8Srmindis not ready for I/O: there are no events of interest pending.
822fd89ef8SrmindThe check for pending I/O and call to
832fd89ef8Srmind.Fn selrecord
842fd89ef8Srmindmust be atomic.
852fd89ef8SrmindAtomicity can be provided by holding the object's lock across the test
862fd89ef8Srmindand call to
872fd89ef8Srmind.Fn selrecord .
882fd89ef8SrmindFor non-MPSAFE drivers, the global
892fd89ef8Srmind.Dv kernel_lock
902fd89ef8Srmindis enough to provide atomicity.
912fd89ef8Srmind.Pp
922fd89ef8Srmind.Fn selnotify
932fd89ef8Srmindis called by the underlying object handling code in order to notify any waiting
942fd89ef8Srmindthreads that an event of interest has occurred.
952fd89ef8SrmindThe same lock held across the poll method and call to
962fd89ef8Srmind.Fn selrecord
972fd89ef8Srmindmust be held across the call to
9888a92b67Stnn.Fn selnotify .
992fd89ef8SrmindThe lock prevents an event of interest being signalled while a thread is
1002fd89ef8Srmindin the process of recording its interest.
1012fd89ef8Srmind.Pp
1022fd89ef8SrmindThe
1032fd89ef8Srmind.Fa events
1042fd89ef8Srmindindicates which event happen.
10588a92b67StnnZero may be used if unknown.
1062fd89ef8Srmind.Pp
1072fd89ef8Srmind.Fn selnotify
1082fd89ef8Srmindalso calls
1092fd89ef8Srmind.Fn KNOTE
1102fd89ef8Srmindpassing
1112fd89ef8Srmind.Va knhint
1122fd89ef8Srmindas an argument.
1132fd89ef8Srmind.Sh CODE REFERENCES
1142fd89ef8SrmindThe core of the select and poll subsystem implementation is in
11587e2fc09Sxtraeme.Pa sys/kern/sys_select.c .
1162fd89ef8SrmindData structures and function prototypes are located in
1172fd89ef8Srmind.Pa sys/sys/select.h ,
1182fd89ef8Srmind.Pa sys/sys/poll.h
1192fd89ef8Srmindand
1202fd89ef8Srmind.Pa sys/sys/selinfo.h .
1212fd89ef8Srmind.Sh SEE ALSO
1222fd89ef8Srmind.Xr poll 2 ,
1232fd89ef8Srmind.Xr select 2 ,
1242fd89ef8Srmind.Xr knote 9
125