socket_timer.c 1.8 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. socket_timer->socket = socket;
  10. OPENER_TRACE_INFO("Adds socket %d to socket timers\n", socket);
  11. }
  12. void SocketTimerSetLastUpdate(SocketTimer *const socket_timer,
  13. const MilliSeconds actual_time) {
  14. if (NULL != socket_timer) {
  15. socket_timer->last_update = actual_time;
  16. OPENER_TRACE_INFO("Sets time stamp for socket %d\n", socket_timer->socket);
  17. }
  18. }
  19. MilliSeconds SocketTimerGetLastUpdate(SocketTimer *const socket_timer) {
  20. return socket_timer->last_update;
  21. }
  22. void SocketTimerClear(SocketTimer *const socket_timer) {
  23. socket_timer->socket = kEipInvalidSocket;
  24. socket_timer->last_update = 0;
  25. }
  26. void SocketTimerArrayInitialize(SocketTimer *const array_of_socket_timers,
  27. const size_t array_length) {
  28. for (size_t i = 0; i < array_length; ++i) {
  29. SocketTimerClear(&array_of_socket_timers[i]);
  30. }
  31. }
  32. SocketTimer *SocketTimerArrayGetSocketTimer(
  33. SocketTimer *const array_of_socket_timers,
  34. const size_t array_length,
  35. const int socket) {
  36. for (size_t i = 0; i < array_length; ++i) {
  37. if (socket == array_of_socket_timers[i].socket) {
  38. return &array_of_socket_timers[i];
  39. }
  40. }
  41. return NULL;
  42. }
  43. SocketTimer *SocketTimerArrayGetEmptySocketTimer(
  44. SocketTimer *const array_of_socket_timers,const size_t array_length) {
  45. return SocketTimerArrayGetSocketTimer(array_of_socket_timers, array_length,
  46. kEipInvalidSocket);
  47. }