readchannel.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * ssize_t readchannel (struct channel const * channel, void * memory, ssize_t extent);
  11. *
  12. * channel.h
  13. *
  14. * read the next message from channel and return message length on
  15. * success or 0 on timeout or -1 on error;
  16. *
  17. *--------------------------------------------------------------------*/
  18. #ifndef READCHANNEL_SOURCE
  19. #define READCHANNEL_SOURCE
  20. #include <sys/time.h>
  21. #include <memory.h>
  22. #include <errno.h>
  23. #include "../ether/channel.h"
  24. #include "../tools/timer.h"
  25. #include "../tools/error.h"
  26. ssize_t readchannel (struct channel const * channel, void * memory, ssize_t extent)
  27. {
  28. struct timeval ts;
  29. struct timeval tc;
  30. ssize_t length;
  31. if (gettimeofday (& ts, NULL) == - 1)
  32. {
  33. error (1, errno, CANT_START_TIMER);
  34. }
  35. while ((length = readpacket (channel, memory, extent)) == 0)
  36. {
  37. if (gettimeofday (& tc, NULL) == - 1)
  38. {
  39. error (1, errno, CANT_RESET_TIMER);
  40. }
  41. if (channel->timeout < 0)
  42. {
  43. continue;
  44. }
  45. if (channel->timeout > MILLISECONDS (ts, tc))
  46. {
  47. continue;
  48. }
  49. break;
  50. }
  51. return (length);
  52. }
  53. #endif