namespace aul {
-Client::Client(std::string path, int timesec) : Socket(std::move(path)) {
+Client::Client(std::string path, int timeout_msec) : Socket(std::move(path)) {
int retry = 2;
do {
int ret = Connect();
if (retry == 0)
THROW(-ECOMM);
- SetTimeout(timesec);
+ SetTimeout(timeout_msec);
}
int Client::Send(const Packet& packet) {
class Client : public Socket {
public:
- Client(std::string path, int timesec = 5);
+ Client(std::string path, int timeout_msec = 5000);
int Send(const Packet& packet);
int Recv(Packet& packet);
};
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <unistd.h>
+#include <algorithm>
+
#include "aul/common/log_private.hh"
#include "aul/socket/socket.hh"
}
}
-void Socket::SetTimeout(int timesec) {
- if (timesec == -1)
+void Socket::SetTimeout(int timeout_msec) {
+ if (timeout_msec == INT_MAX)
return;
- if (timesec < 0) {
- _E("Invalid timesec parameter");
+ if (timeout_msec == -1)
+ timeout_msec = 5000;
+
+ if (timeout_msec < 0) {
+ _E("Invalid timeout_msec parameter");
return;
}
struct timeval timeout = {
- .tv_sec = (time_t)timesec,
- .tv_usec = 0
+ .tv_sec = static_cast<time_t>(timeout_msec / 1000),
+ .tv_usec = static_cast<useconds_t>((timeout_msec % 1000) * 1000)
};
int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
if (ret < 0)