func-poll.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <refentry id="func-poll">
  2. <refmeta>
  3. <refentrytitle>V4L2 poll()</refentrytitle>
  4. &manvol;
  5. </refmeta>
  6. <refnamediv>
  7. <refname>v4l2-poll</refname>
  8. <refpurpose>Wait for some event on a file descriptor</refpurpose>
  9. </refnamediv>
  10. <refsynopsisdiv>
  11. <funcsynopsis>
  12. <funcsynopsisinfo>#include &lt;sys/poll.h&gt;</funcsynopsisinfo>
  13. <funcprototype>
  14. <funcdef>int <function>poll</function></funcdef>
  15. <paramdef>struct pollfd *<parameter>ufds</parameter></paramdef>
  16. <paramdef>unsigned int <parameter>nfds</parameter></paramdef>
  17. <paramdef>int <parameter>timeout</parameter></paramdef>
  18. </funcprototype>
  19. </funcsynopsis>
  20. </refsynopsisdiv>
  21. <refsect1>
  22. <title>Description</title>
  23. <para>With the <function>poll()</function> function applications
  24. can suspend execution until the driver has captured data or is ready
  25. to accept data for output.</para>
  26. <para>When streaming I/O has been negotiated this function waits
  27. until a buffer has been filled by the capture device and can be dequeued
  28. with the &VIDIOC-DQBUF; ioctl. For output devices this function waits
  29. until the device is ready to accept a new buffer to be queued up with
  30. the &VIDIOC-QBUF; ioctl for display. When buffers are already in the outgoing
  31. queue of the driver (capture) or the incoming queue isn't full (display)
  32. the function returns immediately.</para>
  33. <para>On success <function>poll()</function> returns the number of
  34. file descriptors that have been selected (that is, file descriptors
  35. for which the <structfield>revents</structfield> field of the
  36. respective <structname>pollfd</structname> structure is non-zero).
  37. Capture devices set the <constant>POLLIN</constant> and
  38. <constant>POLLRDNORM</constant> flags in the
  39. <structfield>revents</structfield> field, output devices the
  40. <constant>POLLOUT</constant> and <constant>POLLWRNORM</constant>
  41. flags. When the function timed out it returns a value of zero, on
  42. failure it returns <returnvalue>-1</returnvalue> and the
  43. <varname>errno</varname> variable is set appropriately. When the
  44. application did not call &VIDIOC-STREAMON; the
  45. <function>poll()</function> function succeeds, but sets the
  46. <constant>POLLERR</constant> flag in the
  47. <structfield>revents</structfield> field. When the
  48. application has called &VIDIOC-STREAMON; for a capture device but hasn't
  49. yet called &VIDIOC-QBUF;, the <function>poll()</function> function
  50. succeeds and sets the <constant>POLLERR</constant> flag in the
  51. <structfield>revents</structfield> field. For output devices this
  52. same situation will cause <function>poll()</function> to succeed
  53. as well, but it sets the <constant>POLLOUT</constant> and
  54. <constant>POLLWRNORM</constant> flags in the <structfield>revents</structfield>
  55. field.</para>
  56. <para>If an event occurred (see &VIDIOC-DQEVENT;) then
  57. <constant>POLLPRI</constant> will be set in the <structfield>revents</structfield>
  58. field and <function>poll()</function> will return.</para>
  59. <para>When use of the <function>read()</function> function has
  60. been negotiated and the driver does not capture yet, the
  61. <function>poll</function> function starts capturing. When that fails
  62. it returns a <constant>POLLERR</constant> as above. Otherwise it waits
  63. until data has been captured and can be read. When the driver captures
  64. continuously (as opposed to, for example, still images) the function
  65. may return immediately.</para>
  66. <para>When use of the <function>write()</function> function has
  67. been negotiated and the driver does not stream yet, the
  68. <function>poll</function> function starts streaming. When that fails
  69. it returns a <constant>POLLERR</constant> as above. Otherwise it waits
  70. until the driver is ready for a non-blocking
  71. <function>write()</function> call.</para>
  72. <para>If the caller is only interested in events (just
  73. <constant>POLLPRI</constant> is set in the <structfield>events</structfield>
  74. field), then <function>poll()</function> will <emphasis>not</emphasis>
  75. start streaming if the driver does not stream yet. This makes it
  76. possible to just poll for events and not for buffers.</para>
  77. <para>All drivers implementing the <function>read()</function> or
  78. <function>write()</function> function or streaming I/O must also
  79. support the <function>poll()</function> function.</para>
  80. <para>For more details see the
  81. <function>poll()</function> manual page.</para>
  82. </refsect1>
  83. <refsect1>
  84. <title>Return Value</title>
  85. <para>On success, <function>poll()</function> returns the number
  86. structures which have non-zero <structfield>revents</structfield>
  87. fields, or zero if the call timed out. On error
  88. <returnvalue>-1</returnvalue> is returned, and the
  89. <varname>errno</varname> variable is set appropriately:</para>
  90. <variablelist>
  91. <varlistentry>
  92. <term><errorcode>EBADF</errorcode></term>
  93. <listitem>
  94. <para>One or more of the <parameter>ufds</parameter> members
  95. specify an invalid file descriptor.</para>
  96. </listitem>
  97. </varlistentry>
  98. <varlistentry>
  99. <term><errorcode>EBUSY</errorcode></term>
  100. <listitem>
  101. <para>The driver does not support multiple read or write
  102. streams and the device is already in use.</para>
  103. </listitem>
  104. </varlistentry>
  105. <varlistentry>
  106. <term><errorcode>EFAULT</errorcode></term>
  107. <listitem>
  108. <para><parameter>ufds</parameter> references an inaccessible
  109. memory area.</para>
  110. </listitem>
  111. </varlistentry>
  112. <varlistentry>
  113. <term><errorcode>EINTR</errorcode></term>
  114. <listitem>
  115. <para>The call was interrupted by a signal.</para>
  116. </listitem>
  117. </varlistentry>
  118. <varlistentry>
  119. <term><errorcode>EINVAL</errorcode></term>
  120. <listitem>
  121. <para>The <parameter>nfds</parameter> argument is greater
  122. than <constant>OPEN_MAX</constant>.</para>
  123. </listitem>
  124. </varlistentry>
  125. </variablelist>
  126. </refsect1>
  127. </refentry>