socket_timer.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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, const int socket)
  9. {
  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, const MilliSeconds actual_time)
  14. {
  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. {
  22. return socket_timer->last_update;
  23. }
  24. void SocketTimerClear(SocketTimer *const socket_timer)
  25. {
  26. socket_timer->socket = kEipInvalidSocket;
  27. socket_timer->last_update = 0;
  28. }
  29. void SocketTimerArrayInitialize(SocketTimer *const array_of_socket_timers, const size_t array_length)
  30. {
  31. for (size_t i = 0; i < array_length; ++i) {
  32. SocketTimerClear(&array_of_socket_timers[i]);
  33. }
  34. }
  35. SocketTimer *SocketTimerArrayGetSocketTimer(SocketTimer *const array_of_socket_timers, const size_t array_length, const int socket)
  36. {
  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(SocketTimer *const array_of_socket_timers, const size_t array_length)
  45. {
  46. return SocketTimerArrayGetSocketTimer(array_of_socket_timers, array_length, kEipInvalidSocket);
  47. }