Upgraded the rest of Time.
Change-Id: I0ee083837e51d8f74a798b7ba14a3b6bb3859f35
diff --git a/aos/common/network/socket.cc b/aos/common/network/socket.cc
index b674ff1..80eca70 100644
--- a/aos/common/network/socket.cc
+++ b/aos/common/network/socket.cc
@@ -1,15 +1,18 @@
#include "aos/common/network/socket.h"
-#include <string.h>
#include <errno.h>
+#include <string.h>
#include <sys/socket.h>
+#include <chrono>
-#include "aos/common/logging/logging.h"
#include "aos/common/byteorder.h"
+#include "aos/common/logging/logging.h"
namespace aos {
namespace network {
+namespace chrono = ::std::chrono;
+
int Socket::Connect(NetworkPort port, const char *address, int type) {
last_ret_ = 0;
if ((socket_ = socket(AF_INET, type, 0)) < 0) {
@@ -53,8 +56,13 @@
return ret;
}
-int Socket::Receive(void *buf, int length, time::Time timeout) {
- timeval timeout_timeval = timeout.ToTimeval();
+int Socket::Receive(void *buf, int length, chrono::microseconds timeout) {
+ timeval timeout_timeval;
+ timeout_timeval.tv_sec = chrono::duration_cast<chrono::seconds>(timeout).count();
+ timeout_timeval.tv_usec =
+ chrono::duration_cast<chrono::microseconds>(
+ timeout - chrono::seconds(timeout_timeval.tv_sec))
+ .count();
fd_set fds;
FD_ZERO(&fds);
FD_SET(socket_, &fds);
diff --git a/aos/common/network/socket.h b/aos/common/network/socket.h
index 9e8eaf5..9bda8aa 100644
--- a/aos/common/network/socket.h
+++ b/aos/common/network/socket.h
@@ -1,15 +1,15 @@
#ifndef AOS_COMMON_NETWORK_SOCKET_H_
#define AOS_COMMON_NETWORK_SOCKET_H_
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
#include <unistd.h>
-#include <stdio.h>
+#include <chrono>
-#include "aos/common/time.h"
#include "aos/common/network_port.h"
namespace aos {
@@ -28,7 +28,7 @@
// No timeout.
int Receive(void *buf, int length);
// timeout is relative
- int Receive(void *buf, int length, time::Time timeout);
+ int Receive(void *buf, int length, ::std::chrono::microseconds timeout);
protected:
int Connect(NetworkPort port, const char *address, int type = SOCK_DGRAM);