socket_timer.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*******************************************************************************
  2. * Copyright (c) 2016, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #include "socket_timer.h"
  7. #include "trace.h"
  8. void SocketTimerSetSocket(SocketTimer *const socket_timer,
  9. const int socket) {
  10. socket_timer->socket = socket;
  11. OPENER_TRACE_INFO("Adds socket %d to socket timers\n", socket);
  12. }
  13. void SocketTimerSetLastUpdate(SocketTimer *const socket_timer,
  14. const MilliSeconds actual_time) {
  15. if (NULL != socket_timer) {
  16. socket_timer->last_update = actual_time;
  17. OPENER_TRACE_INFO("Sets time stamp for socket %d\n", socket_timer->socket);
  18. }
  19. }
  20. MilliSeconds SocketTimerGetLastUpdate(SocketTimer *const socket_timer) {
  21. return socket_timer->last_update;
  22. }
  23. void SocketTimerClear(SocketTimer *const socket_timer) {
  24. socket_timer->socket = kEipInvalidSocket;
  25. socket_timer->last_update = 0;
  26. }
  27. void SocketTimerArrayInitialize(SocketTimer *const array_of_socket_timers,
  28. const size_t array_length) {
  29. for (size_t i = 0; i < array_length; ++i) {
  30. SocketTimerClear(&array_of_socket_timers[i]);
  31. }
  32. }
  33. SocketTimer *SocketTimerArrayGetSocketTimer(
  34. SocketTimer *const array_of_socket_timers,
  35. const size_t array_length,
  36. const int socket) {
  37. for (size_t i = 0; i < array_length; ++i) {
  38. if (socket == array_of_socket_timers[i].socket) {
  39. return &array_of_socket_timers[i];
  40. }
  41. }
  42. return NULL;
  43. }
  44. SocketTimer *SocketTimerArrayGetEmptySocketTimer(
  45. SocketTimer *const array_of_socket_timers,
  46. const size_t array_length) {
  47. return SocketTimerArrayGetSocketTimer(array_of_socket_timers, array_length,
  48. kEipInvalidSocket);
  49. }