socket_timer.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*******************************************************************************
  2. * Copyright (c) 2016, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #ifndef SRC_PORTS_SOCKET_TIMER_H_
  7. #define SRC_PORTS_SOCKET_TIMER_H_
  8. #include "typedefs.h"
  9. /** @brief Data structure to store last usage times for sockets
  10. *
  11. */
  12. typedef struct socket_timer {
  13. int socket; /**< key */
  14. MilliSeconds last_update; /**< time stop of last update */
  15. } SocketTimer;
  16. /** @brief
  17. * Sets socket of a Socket Timer
  18. *
  19. * @param socket_timer Socket Timer to be set
  20. * @param socket Socket handle
  21. */
  22. void SocketTimerSetSocket(SocketTimer *const socket_timer, const int socket);
  23. /** @brief
  24. * Sets time stamp entry of the Socket Timer
  25. *
  26. * @param socket_timer Socket Timer to be set
  27. * @param actual_time Time stamp
  28. */
  29. void SocketTimerSetLastUpdate(SocketTimer *const socket_timer, const MilliSeconds actual_time);
  30. /** @brief
  31. * Gets time stamp of the last update
  32. *
  33. * @param socket_timer Socket Timer to be set
  34. * @return Last update field value
  35. */
  36. MilliSeconds SocketTimerGetLastUpdate(SocketTimer *const socket_timer);
  37. /** @brief
  38. * Clears a Socket Timer entry
  39. *
  40. * @param socket_timer Socket Timer to be cleared
  41. */
  42. void SocketTimerClear(SocketTimer *const socket_timer);
  43. /** @brief
  44. * Initializes an array of Socket Timer entries
  45. *
  46. * @param array_of_socket_timers The array of Socket Timer entries to be initialized
  47. * @param array_length the length of the array
  48. */
  49. void SocketTimerArrayInitialize(SocketTimer *const array_of_socket_timers, const size_t array_length);
  50. /** @brief
  51. * Get the Socket Timer entry with the spezified socket value
  52. *
  53. * @param array_of_socket_timers The Socket Timer array
  54. * @param array_length The Socket Timer array length
  55. * @param socket The socket value to be searched for
  56. *
  57. * @return The Socket Timer of found, otherwise NULL
  58. */
  59. SocketTimer *SocketTimerArrayGetSocketTimer(SocketTimer *const array_of_socket_timers, const size_t array_length, const int socket);
  60. /** @brief
  61. * Get an empty Socket Timer entry
  62. *
  63. * @param array_of_socket_timers The Socket Timer array
  64. * @param array_length The Socket Timer array length
  65. *
  66. * @return An empty Socket Timer entry, or NULL if non is available
  67. */
  68. SocketTimer *SocketTimerArrayGetEmptySocketTimer(SocketTimer *const array_of_socket_timers, const size_t array_length);
  69. #endif /* SRC_PORTS_SOCKET_TIMER_H_ */