123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #ifndef READMESSAGE_SOURCE
- #define READMESSAGE_SOURCE
- #include <sys/time.h>
- #include <memory.h>
- #include <errno.h>
- #include "../tools/error.h"
- #include "../tools/timer.h"
- #include "../plc/plc.h"
- ssize_t readmessage (struct channel const * channel, struct message * message, uint8_t MMV, uint16_t MMTYPE)
- {
- struct timeval ts;
- struct timeval tc;
- ssize_t length;
- if (gettimeofday (& ts, NULL) == - 1)
- {
- error (1, errno, CANT_START_TIMER);
- }
- while ((length = readpacket (channel, message, sizeof (* message))) >= 0)
- {
- if (! UnwantedMessage (message, length, MMV, MMTYPE))
- {
- return (length);
- }
- if (gettimeofday (& tc, NULL) == - 1)
- {
- error (1, errno, CANT_RESET_TIMER);
- }
- if (channel->timeout < 0)
- {
- continue;
- }
- if (channel->timeout > MILLISECONDS (ts, tc))
- {
- continue;
- }
- return (0);
- }
- return (- 1);
- }
- #endif
|