1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
2<HTML
3><HEAD
4><TITLE
5>V4L2 select()</TITLE
6><META
7NAME="GENERATOR"
8CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
9REL="HOME"
10TITLE="Video for Linux Two API Specification"
11HREF="book1.htm"><LINK
12REL="UP"
13TITLE="Function Reference"
14HREF="r7624.htm"><LINK
15REL="PREVIOUS"
16TITLE="V4L2 read()"
17HREF="r14264.htm"><LINK
18REL="NEXT"
19TITLE="V4L2 write()"
20HREF="r14496.htm"></HEAD
21><BODY
22CLASS="REFENTRY"
23BGCOLOR="#FFFFFF"
24TEXT="#000000"
25LINK="#0000FF"
26VLINK="#840084"
27ALINK="#0000FF"
28><DIV
29CLASS="NAVHEADER"
30><TABLE
31SUMMARY="Header navigation table"
32WIDTH="100%"
33BORDER="0"
34CELLPADDING="0"
35CELLSPACING="0"
36><TR
37><TH
38COLSPAN="3"
39ALIGN="center"
40>Video for Linux Two API Specification: Revision 0.24</TH
41></TR
42><TR
43><TD
44WIDTH="10%"
45ALIGN="left"
46VALIGN="bottom"
47><A
48HREF="r14264.htm"
49ACCESSKEY="P"
50>Prev</A
51></TD
52><TD
53WIDTH="80%"
54ALIGN="center"
55VALIGN="bottom"
56></TD
57><TD
58WIDTH="10%"
59ALIGN="right"
60VALIGN="bottom"
61><A
62HREF="r14496.htm"
63ACCESSKEY="N"
64>Next</A
65></TD
66></TR
67></TABLE
68><HR
69ALIGN="LEFT"
70WIDTH="100%"></DIV
71><H1
72><A
73NAME="FUNC-SELECT"
74></A
75>V4L2 select()</H1
76><DIV
77CLASS="REFNAMEDIV"
78><A
79NAME="AEN14394"
80></A
81><H2
82>Name</H2
83>v4l2-select&nbsp;--&nbsp;Synchronous I/O multiplexing</DIV
84><DIV
85CLASS="REFSYNOPSISDIV"
86><A
87NAME="AEN14397"
88></A
89><H2
90>Synopsis</H2
91><DIV
92CLASS="FUNCSYNOPSIS"
93><P
94></P
95><A
96NAME="AEN14398"
97></A
98><PRE
99CLASS="FUNCSYNOPSISINFO"
100>#include &lt;sys/time.h&gt;
101#include &lt;sys/types.h&gt;
102#include &lt;unistd.h&gt;</PRE
103><P
104><CODE
105><CODE
106CLASS="FUNCDEF"
107>int select</CODE
108>(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);</CODE
109></P
110><P
111></P
112></DIV
113></DIV
114><DIV
115CLASS="REFSECT1"
116><A
117NAME="AEN14413"
118></A
119><H2
120>Description</H2
121><P
122>With the <CODE
123CLASS="FUNCTION"
124>select()</CODE
125> function applications
126can suspend execution until the driver has captured data or is ready
127to accept data for output.</P
128><P
129>When streaming I/O has been negotiated this function waits
130until a buffer has been filled or displayed and can be dequeued with
131the <A
132HREF="r12878.htm"
133><CODE
134CLASS="CONSTANT"
135>VIDIOC_DQBUF</CODE
136></A
137> ioctl. When buffers are already in the outgoing
138queue of the driver the function returns immediately.</P
139><P
140>On success <CODE
141CLASS="FUNCTION"
142>select()</CODE
143> returns the total
144number of bits set in the <CODE
145CLASS="STRUCTNAME"
146>fd_set</CODE
147>s. When the
148function timed out it returns a value of zero. On failure it returns
149<SPAN
150CLASS="RETURNVALUE"
151>-1</SPAN
152> and the <CODE
153CLASS="VARNAME"
154>errno</CODE
155>
156variable is set appropriately. When the application did not call
157<A
158HREF="r12878.htm"
159><CODE
160CLASS="CONSTANT"
161>VIDIOC_QBUF</CODE
162></A
163> or <A
164HREF="r13817.htm"
165><CODE
166CLASS="CONSTANT"
167>VIDIOC_STREAMON</CODE
168></A
169> yet the
170<CODE
171CLASS="FUNCTION"
172>select()</CODE
173> function succeeds, setting the bit of
174the file descriptor in <CODE
175CLASS="PARAMETER"
176>readfds</CODE
177> or
178<CODE
179CLASS="PARAMETER"
180>writefds</CODE
181>, but subsequent <A
182HREF="r12878.htm"
183><CODE
184CLASS="CONSTANT"
185>VIDIOC_DQBUF</CODE
186></A
187> calls
188will fail.<A
189NAME="AEN14434"
190HREF="r14390.htm#FTN.AEN14434"
191><SPAN
192CLASS="footnote"
193>[1]</SPAN
194></A
195></P
196><P
197>When use of the <CODE
198CLASS="FUNCTION"
199>read()</CODE
200> function has
201been negotiated and the driver does not capture yet, the
202<CODE
203CLASS="FUNCTION"
204>select()</CODE
205> function starts capturing. When that
206fails, <CODE
207CLASS="FUNCTION"
208>select()</CODE
209> returns successful and a
210subsequent <CODE
211CLASS="FUNCTION"
212>read()</CODE
213> call, which also attempts to
214start capturing, will return an appropriate error code. When the
215driver captures continuously (as opposed to, for example, still
216images) and data is already available the
217<CODE
218CLASS="FUNCTION"
219>select()</CODE
220> function returns immediately.</P
221><P
222>When use of the <CODE
223CLASS="FUNCTION"
224>write()</CODE
225> function has
226been negotiated the <CODE
227CLASS="FUNCTION"
228>select()</CODE
229> function just waits
230until the driver is ready for a non-blocking
231<CODE
232CLASS="FUNCTION"
233>write()</CODE
234> call.</P
235><P
236>All drivers implementing the <CODE
237CLASS="FUNCTION"
238>read()</CODE
239> or
240<CODE
241CLASS="FUNCTION"
242>write()</CODE
243> function or streaming I/O must also
244support the <CODE
245CLASS="FUNCTION"
246>select()</CODE
247> function.</P
248><P
249>For more details see the <CODE
250CLASS="FUNCTION"
251>select()</CODE
252>
253manual page.</P
254></DIV
255><DIV
256CLASS="REFSECT1"
257><A
258NAME="AEN14457"
259></A
260><H2
261>Return Value</H2
262><P
263>On success, <CODE
264CLASS="FUNCTION"
265>select()</CODE
266> returns the number
267of descriptors contained in the three returned descriptor sets, which
268will be zero if the timeout expired. On error
269<SPAN
270CLASS="RETURNVALUE"
271>-1</SPAN
272> is returned, and the
273<CODE
274CLASS="VARNAME"
275>errno</CODE
276> variable is set appropriately; the sets and
277<CODE
278CLASS="PARAMETER"
279>timeout</CODE
280> are undefined. Possible error codes
281are:</P
282><P
283></P
284><DIV
285CLASS="VARIABLELIST"
286><DL
287><DT
288><SPAN
289CLASS="ERRORCODE"
290>EBADF</SPAN
291></DT
292><DD
293><P
294>One or more of the file descriptor sets specified a
295file descriptor that is not open.</P
296></DD
297><DT
298><SPAN
299CLASS="ERRORCODE"
300>EBUSY</SPAN
301></DT
302><DD
303><P
304>The driver does not support multiple read or write
305streams and the device is already in use.</P
306></DD
307><DT
308><SPAN
309CLASS="ERRORCODE"
310>EFAULT</SPAN
311></DT
312><DD
313><P
314>The <CODE
315CLASS="PARAMETER"
316>readfds</CODE
317>,
318<CODE
319CLASS="PARAMETER"
320>writefds</CODE
321>, <CODE
322CLASS="PARAMETER"
323>exceptfds</CODE
324> or
325<CODE
326CLASS="PARAMETER"
327>timeout</CODE
328> pointer references an inaccessible memory
329area.</P
330></DD
331><DT
332><SPAN
333CLASS="ERRORCODE"
334>EINTR</SPAN
335></DT
336><DD
337><P
338>The call was interrupted by a signal.</P
339></DD
340><DT
341><SPAN
342CLASS="ERRORCODE"
343>EINVAL</SPAN
344></DT
345><DD
346><P
347>The <CODE
348CLASS="PARAMETER"
349>nfds</CODE
350> argument is less than
351zero or greater than <CODE
352CLASS="CONSTANT"
353>FD_SETSIZE</CODE
354>.</P
355></DD
356></DL
357></DIV
358></DIV
359><H2
360CLASS="FOOTNOTES"
361>Notes</H2
362><TABLE
363BORDER="0"
364CLASS="FOOTNOTES"
365WIDTH="100%"
366><TR
367><TD
368ALIGN="LEFT"
369VALIGN="TOP"
370WIDTH="5%"
371><A
372NAME="FTN.AEN14434"
373HREF="r14390.htm#AEN14434"
374><SPAN
375CLASS="footnote"
376>[1]</SPAN
377></A
378></TD
379><TD
380ALIGN="LEFT"
381VALIGN="TOP"
382WIDTH="95%"
383><P
384>The Linux kernel implements
385<CODE
386CLASS="FUNCTION"
387>select()</CODE
388> like the <A
389HREF="r14169.htm"
390><CODE
391CLASS="FUNCTION"
392>poll()</CODE
393></A
394> function, but
395<CODE
396CLASS="FUNCTION"
397>select()</CODE
398> cannot return a
399<CODE
400CLASS="CONSTANT"
401>POLLERR</CODE
402>.</P
403></TD
404></TR
405></TABLE
406><DIV
407CLASS="NAVFOOTER"
408><HR
409ALIGN="LEFT"
410WIDTH="100%"><TABLE
411SUMMARY="Footer navigation table"
412WIDTH="100%"
413BORDER="0"
414CELLPADDING="0"
415CELLSPACING="0"
416><TR
417><TD
418WIDTH="33%"
419ALIGN="left"
420VALIGN="top"
421><A
422HREF="r14264.htm"
423ACCESSKEY="P"
424>Prev</A
425></TD
426><TD
427WIDTH="34%"
428ALIGN="center"
429VALIGN="top"
430><A
431HREF="book1.htm"
432ACCESSKEY="H"
433>Home</A
434></TD
435><TD
436WIDTH="33%"
437ALIGN="right"
438VALIGN="top"
439><A
440HREF="r14496.htm"
441ACCESSKEY="N"
442>Next</A
443></TD
444></TR
445><TR
446><TD
447WIDTH="33%"
448ALIGN="left"
449VALIGN="top"
450>V4L2 read()</TD
451><TD
452WIDTH="34%"
453ALIGN="center"
454VALIGN="top"
455><A
456HREF="r7624.htm"
457ACCESSKEY="U"
458>Up</A
459></TD
460><TD
461WIDTH="33%"
462ALIGN="right"
463VALIGN="top"
464>V4L2 write()</TD
465></TR
466></TABLE
467></DIV
468></BODY
469></HTML
470>
471