Buffer: Convert API to std::chrono
This commit is contained in:
parent
707975e567
commit
c823b9c00e
|
@ -74,11 +74,13 @@ int Buffer::read_into(int sd, unsigned int bytes) {
|
|||
return bytes_read;
|
||||
}
|
||||
|
||||
int Buffer::read_into(int sd, unsigned int bytes, struct timeval timeout) {
|
||||
int Buffer::read_into(int sd, unsigned int bytes, Microseconds timeout) {
|
||||
fd_set set;
|
||||
FD_ZERO(&set); /* clear the set */
|
||||
FD_SET(sd, &set); /* add our file descriptor to the set */
|
||||
int rv = select(sd + 1, &set, NULL, NULL, &timeout);
|
||||
timeval timeout_tv = zm::chrono::duration_cast<timeval>(timeout);
|
||||
|
||||
int rv = select(sd + 1, &set, nullptr, nullptr, &timeout_tv);
|
||||
if (rv == -1) {
|
||||
Error("Error %d %s from select", errno, strerror(errno));
|
||||
return rv;
|
||||
|
@ -86,5 +88,6 @@ int Buffer::read_into(int sd, unsigned int bytes, struct timeval timeout) {
|
|||
Debug(1, "timeout"); /* a timeout occured */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return read_into(sd, bytes);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define ZM_BUFFER_H
|
||||
|
||||
#include "zm_logger.h"
|
||||
#include "zm_time.h"
|
||||
#include <cstring>
|
||||
|
||||
class Buffer {
|
||||
|
@ -187,7 +188,7 @@ class Buffer {
|
|||
return static_cast<int>(mSize);
|
||||
}
|
||||
int read_into(int sd, unsigned int bytes);
|
||||
int read_into(int sd, unsigned int bytes, struct timeval timeout);
|
||||
int read_into(int sd, unsigned int bytes, Microseconds timeout);
|
||||
};
|
||||
|
||||
#endif // ZM_BUFFER_H
|
||||
|
|
Loading…
Reference in New Issue