mbed_poll.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2017 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MBED_POLL_H
  17. #define MBED_POLL_H
  18. #define POLLIN 0x0001 ///< Data may be read without blocking
  19. #define POLLOUT 0x0010 ///< Data may be written without blocking
  20. #define POLLERR 0x1000 ///< An error has occurred on the device or stream
  21. #define POLLHUP 0x2000 ///< The device has been disconnected
  22. #define POLLNVAL 0x4000 ///< The specified file handle value is invalid
  23. namespace mbed {
  24. class FileHandle;
  25. /** \addtogroup platform */
  26. /** @{*/
  27. /**
  28. * \defgroup platform_poll poll functions
  29. * @{
  30. */
  31. struct pollfh {
  32. FileHandle *fh;
  33. short events;
  34. short revents;
  35. };
  36. /** A mechanism to multiplex input/output over a set of file handles(file descriptors).
  37. * For every file handle provided, poll() examines it for any events registered for that particular
  38. * file handle.
  39. *
  40. * @param fhs an array of PollFh struct carrying a FileHandle and bitmasks of events
  41. * @param nfhs number of file handles
  42. * @param timeout timer value to timeout or -1 for loop forever
  43. *
  44. * @return number of file handles selected (for which revents is non-zero). 0 if timed out with nothing selected. -1 for error.
  45. */
  46. int poll(pollfh fhs[], unsigned nfhs, int timeout);
  47. /**@}*/
  48. /**@}*/
  49. } // namespace mbed
  50. #endif //MBED_POLL_H