cleaned up file names and namespace
diff --git a/aos/common/network/ReceiveSocket.h b/aos/common/network/ReceiveSocket.h
deleted file mode 100644
index 468cb22..0000000
--- a/aos/common/network/ReceiveSocket.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef AOS_NETWORK_RECEIVE_SOCKET_H_
-#define AOS_NETWORK_RECEIVE_SOCKET_H_
-
-#include "Socket.h"
-
-namespace aos {
-
-class ReceiveSocket : public Socket {
- public:
- inline ReceiveSocket(NetworkPort port) { Connect(port); }
- int Connect(NetworkPort port);
-};
-
-} // namespace aos
-
-#endif
diff --git a/aos/common/network/SocketLibraries.h b/aos/common/network/SocketLibraries.h
deleted file mode 100644
index 7e8825a..0000000
--- a/aos/common/network/SocketLibraries.h
+++ /dev/null
@@ -1,16 +0,0 @@
-// Includes the socket libraries under vxworks and linux.
-// Defines a lame_unconst macro for the vxworks functions that need it.
-
-#ifndef __VXWORKS__
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-#define lame_unconst(a) a
-#else
-#include <inetLib.h>
-#include <sockLib.h>
-#include <selectLib.h>
-// Vxworks is missing the const in a couple of its function signatures, so...
-#define lame_unconst(a) const_cast<char *>(a)
-#endif
-
diff --git a/aos/common/network/network.gyp b/aos/common/network/network.gyp
index c254c93..b4c8977 100644
--- a/aos/common/network/network.gyp
+++ b/aos/common/network/network.gyp
@@ -16,9 +16,9 @@
'target_name': 'socket',
'type': 'static_library',
'sources': [
- 'ReceiveSocket.cpp',
- 'SendSocket.cpp',
- 'Socket.cpp',
+ 'receive_socket.cc',
+ 'send_socket.cc',
+ 'socket.cc',
],
'dependencies': [
'<(AOS)/build/aos.gyp:logging',
diff --git a/aos/common/network/ReceiveSocket.cpp b/aos/common/network/receive_socket.cc
similarity index 81%
rename from aos/common/network/ReceiveSocket.cpp
rename to aos/common/network/receive_socket.cc
index d98be54..76a7a80 100644
--- a/aos/common/network/ReceiveSocket.cpp
+++ b/aos/common/network/receive_socket.cc
@@ -1,14 +1,16 @@
-#include "ReceiveSocket.h"
+#include "aos/common/network/receive_socket.h"
+
#include <string.h>
#include <math.h>
#include <errno.h>
#include <stdint.h>
#include <stddef.h>
+#include <sys/socket.h>
-#include "aos/common/network/SocketLibraries.h"
#include "aos/common/logging/logging.h"
namespace aos {
+namespace network {
static const char *localhost = "0.0.0.0";
@@ -28,5 +30,5 @@
return last_ret_ = 0;
}
-} // namespace aos
-
+} // namespace network
+} // namespace aos
diff --git a/aos/common/network/receive_socket.h b/aos/common/network/receive_socket.h
new file mode 100644
index 0000000..afa0726
--- /dev/null
+++ b/aos/common/network/receive_socket.h
@@ -0,0 +1,18 @@
+#ifndef AOS_COMMON_NETWORK_RECEIVE_SOCKET_H_
+#define AOS_COMMON_NETWORK_RECEIVE_SOCKET_H_
+
+#include "aos/common/network/socket.h"
+
+namespace aos {
+namespace network {
+
+class ReceiveSocket : public Socket {
+ public:
+ explicit ReceiveSocket(NetworkPort port) { Connect(port); }
+ int Connect(NetworkPort port);
+};
+
+} // namespace network
+} // namespace aos
+
+#endif // AOS_COMMON_NETWORK_RECEIVE_SOCKET_H_
diff --git a/aos/common/network/SendSocket.cpp b/aos/common/network/send_socket.cc
similarity index 71%
rename from aos/common/network/SendSocket.cpp
rename to aos/common/network/send_socket.cc
index 59fd570..df53c47 100644
--- a/aos/common/network/SendSocket.cpp
+++ b/aos/common/network/send_socket.cc
@@ -1,15 +1,16 @@
-#include "aos/common/network/SendSocket.h"
+#include "aos/common/network/send_socket.h"
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include <stddef.h>
#include <math.h>
+#include <sys/socket.h>
-#include "aos/common/network/SocketLibraries.h"
#include "aos/common/logging/logging.h"
namespace aos {
+namespace network {
int SendSocket::Connect(NetworkPort port, const char *robot_ip, int type) {
Reset();
@@ -18,14 +19,15 @@
return ret;
}
- if (connect(socket_, &addr_.addr,
- sizeof(addr_)) < 0) {
+ if (connect(socket_, &addr_.addr, sizeof(addr_)) < 0) {
LOG(ERROR, "couldn't connect to ip '%s' because of %d: %s\n", robot_ip,
errno, strerror(errno));
last_ret_ = 1;
}
+ // TODO(brians): Is this a bug?
return last_ret_ = 0;
}
+} // namespace network
} // namespace aos
diff --git a/aos/common/network/SendSocket.h b/aos/common/network/send_socket.h
similarity index 71%
rename from aos/common/network/SendSocket.h
rename to aos/common/network/send_socket.h
index 1ca0c4c..77db726 100644
--- a/aos/common/network/SendSocket.h
+++ b/aos/common/network/send_socket.h
@@ -1,13 +1,14 @@
-#ifndef AOS_NETWORK_SEND_SOCKET_H_
-#define AOS_NETWORK_SEND_SOCKET_H_
+#ifndef AOS_COMMON_NETWORK_SEND_SOCKET_H_
+#define AOS_COMMON_NETWORK_SEND_SOCKET_H_
-#include "Socket.h"
+#include "aos/common/network/socket.h"
#include "aos/linux_code/configuration.h"
#include "aos/common/network_port.h"
#include "aos/common/util/inet_addr.h"
namespace aos {
+namespace network {
class SendSocket : public Socket {
public:
@@ -22,7 +23,7 @@
int Connect(NetworkPort port, const char *robot_ip, int type = SOCK_DGRAM);
};
-} // namespace aos
+} // namespace network
+} // namespace aos
-#endif
-
+#endif // AOS_COMMON_NETWORK_SEND_SOCKET_H_
diff --git a/aos/common/network/Socket.cpp b/aos/common/network/socket.cc
similarity index 87%
rename from aos/common/network/Socket.cpp
rename to aos/common/network/socket.cc
index 0366e7c..1448304 100644
--- a/aos/common/network/Socket.cpp
+++ b/aos/common/network/socket.cc
@@ -1,12 +1,13 @@
-#include "aos/common/network/Socket.h"
+#include "aos/common/network/socket.h"
#include <string.h>
#include <errno.h>
+#include <sys/socket.h>
#include "aos/common/logging/logging.h"
-#include "aos/common/network/SocketLibraries.h"
namespace aos {
+namespace network {
int Socket::Connect(NetworkPort port, const char *address, int type) {
last_ret_ = 0;
@@ -24,7 +25,7 @@
#else
const int failure_return = -1;
#endif
- if (inet_aton(lame_unconst(address), &addr_.in.sin_addr) == failure_return) {
+ if (inet_aton(address, &addr_.in.sin_addr) == failure_return) {
LOG(ERROR, "Invalid IP address '%s' because of %d: %s\n", address,
errno, strerror(errno));
return last_ret_ = -1;
@@ -74,9 +75,10 @@
int Socket::Send(const void *buf, int length) {
const int ret = write(socket_,
- lame_unconst(static_cast<const char *>(buf)), length);
+ static_cast<const char *>(buf), length);
last_ret_ = (ret == -1) ? -1 : 0;
return ret;
}
+} // namespace network
} // namespace aos
diff --git a/aos/common/network/Socket.h b/aos/common/network/socket.h
similarity index 85%
rename from aos/common/network/Socket.h
rename to aos/common/network/socket.h
index 7a20d3e..9e8eaf5 100644
--- a/aos/common/network/Socket.h
+++ b/aos/common/network/socket.h
@@ -13,6 +13,7 @@
#include "aos/common/network_port.h"
namespace aos {
+namespace network {
class Socket {
public:
@@ -26,10 +27,6 @@
// valid return value for all overloads.
// No timeout.
int Receive(void *buf, int length);
- // DEPRECATED(brians): use the time::Time overload instead
- int Receive(void *buf, int length, long usec_timeout) {
- return Receive(buf, length, time::Time::InUS(usec_timeout));
- }
// timeout is relative
int Receive(void *buf, int length, time::Time timeout);
@@ -50,6 +47,7 @@
int last_ret_;
};
+} // namespace network
} // namespace aos
#endif // AOS_COMMON_NETWORK_SOCKET_H_