Delete receive_socket, send_socket, and socket

Change-Id: I1008d951ace4c91e1667ae42606408fb45749a4d
diff --git a/aos/common/network/BUILD b/aos/common/network/BUILD
index 470969f..9484bc5 100644
--- a/aos/common/network/BUILD
+++ b/aos/common/network/BUILD
@@ -19,26 +19,6 @@
     ],
 )
 
-cc_library(
-    name = "socket",
-    srcs = [
-        "receive_socket.cc",
-        "send_socket.cc",
-        "socket.cc",
-    ],
-    hdrs = [
-        "receive_socket.h",
-        "send_socket.h",
-        "socket.h",
-    ],
-    deps = [
-        "//aos/common:time",
-        "//aos/common/logging",
-        "//aos/common/util:inet_addr",
-        "//aos/linux_code:configuration",
-    ],
-)
-
 cc_test(
     name = "team_number_test",
     srcs = [
diff --git a/aos/common/network/receive_socket.cc b/aos/common/network/receive_socket.cc
deleted file mode 100644
index c3a7710..0000000
--- a/aos/common/network/receive_socket.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-#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/logging/logging.h"
-
-namespace aos {
-namespace network {
-
-static const char *localhost = "0.0.0.0";
-
-int ReceiveSocket::Connect(NetworkPort port) {
-  Reset();
-  const int ret = Socket::Connect(port, localhost);
-  if (ret != 0) {
-    return ret;
-  }
-
-  if (bind(socket_, &addr_.addr,
-           sizeof(addr_)) == -1) {
-    PLOG(ERROR, "failed to bind to address '%s'", localhost);
-    return last_ret_ = -1;
-  }
-  return last_ret_ = 0;
-}
-
-}  // namespace network
-}  // namespace aos
diff --git a/aos/common/network/receive_socket.h b/aos/common/network/receive_socket.h
deleted file mode 100644
index afa0726..0000000
--- a/aos/common/network/receive_socket.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#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/send_socket.cc b/aos/common/network/send_socket.cc
deleted file mode 100644
index 9886893..0000000
--- a/aos/common/network/send_socket.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-#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/logging/logging.h"
-
-namespace aos {
-namespace network {
-
-int SendSocket::Connect(NetworkPort port, const char *robot_ip, int type) {
-  Reset();
-  const int ret = Socket::Connect(port, robot_ip, type);
-  if (ret != 0) {
-    return ret;
-  }
-
-  if (connect(socket_, &addr_.addr, sizeof(addr_)) < 0) {
-    PLOG(ERROR, "couldn't connect to ip '%s'", robot_ip);
-    return last_ret_ = 1;
-  }
-
-  return last_ret_ = 0;
-}
-
-}  // namespace network
-}  // namespace aos
diff --git a/aos/common/network/send_socket.h b/aos/common/network/send_socket.h
deleted file mode 100644
index 77db726..0000000
--- a/aos/common/network/send_socket.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef AOS_COMMON_NETWORK_SEND_SOCKET_H_
-#define AOS_COMMON_NETWORK_SEND_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:
-  // Connect must be called before use.
-  SendSocket() {}
-  // Calls Connect automatically.
-  SendSocket(NetworkPort port, ::aos::NetworkAddress address) {
-    Connect(port,
-            ::aos::util::MakeIPAddress(::aos::configuration::GetOwnIPAddress(),
-                                       address));
-  }
-  int Connect(NetworkPort port, const char *robot_ip, int type = SOCK_DGRAM);
-};
-
-}  // namespace network
-}  // namespace aos
-
-#endif  // AOS_COMMON_NETWORK_SEND_SOCKET_H_
diff --git a/aos/common/network/socket.cc b/aos/common/network/socket.cc
deleted file mode 100644
index 80eca70..0000000
--- a/aos/common/network/socket.cc
+++ /dev/null
@@ -1,91 +0,0 @@
-#include "aos/common/network/socket.h"
-
-#include <errno.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <chrono>
-
-#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) {
-    PLOG(ERROR, "failed to create socket");
-    return last_ret_ = 1;
-  }
-
-  memset(&addr_, 0, sizeof(addr_));
-  addr_.in.sin_family = AF_INET;
-  addr_.in.sin_port = hton<uint16_t>(static_cast<uint16_t>(port));
-#ifndef __VXWORKS__
-  const int failure_return = 0;
-#else
-  const int failure_return = -1;
-#endif
-  if (inet_aton(address, &addr_.in.sin_addr) == failure_return) {
-    PLOG(ERROR, "invalid IP address '%s'", address);
-    return last_ret_ = -1;
-  }
-
-  return last_ret_ = 0;
-}
-
-Socket::Socket() : socket_(-1), last_ret_(2) {}
-
-Socket::~Socket() {
-  close(socket_);
-}
-
-void Socket::Reset() {
-  if (socket_ != -1) {
-    close(socket_);
-    socket_ = -1;
-  }
-  last_ret_ = 0;
-}
-
-int Socket::Receive(void *buf, int length) {
-  const int ret = recv(socket_, static_cast<char *>(buf), length, 0);
-  last_ret_ = (ret == -1) ? -1 : 0;
-  return ret;
-}
-
-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);
-  switch (select(FD_SETSIZE, &fds, NULL, NULL, &timeout_timeval)) {
-    case 1:
-      return Receive(buf, length);
-    case 0:
-      return last_ret_ = 0;
-    default:
-      if (errno == EINTR) {
-        return last_ret_ = 0;
-      }
-      PLOG(FATAL, "select(FD_SETSIZE, %p, NULL, NULL, %p) failed",
-          &fds, &timeout_timeval);
-  }
-}
-
-int Socket::Send(const void *buf, int length) {
-  const int ret = write(socket_,
-                        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
deleted file mode 100644
index 9bda8aa..0000000
--- a/aos/common/network/socket.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#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 <unistd.h>
-#include <chrono>
-
-#include "aos/common/network_port.h"
-
-namespace aos {
-namespace network {
-
-class Socket {
- public:
-  int LastStatus() const { return last_ret_; }
-
-  int Send(const void *buf, int length);
-
-  // buf is where to put the data and length is the maximum amount of data to
-  // put in for all overloads.
-  // All overloads return how many bytes were received or -1 for error. 0 is a
-  // valid return value for all overloads.
-  // No timeout.
-  int Receive(void *buf, int length);
-  // timeout is relative
-  int Receive(void *buf, int length, ::std::chrono::microseconds timeout);
-
- protected:
-  int Connect(NetworkPort port, const char *address, int type = SOCK_DGRAM);
-  Socket();
-  ~Socket();
-
-  // Resets socket_ and last_ret_.
-  void Reset();
-
-  union {
-    sockaddr_in in;
-    sockaddr addr;
-  } addr_; // filled in by Connect
-
-  int socket_;
-  int last_ret_;
-};
-
-}  // namespace network
-}  // namespace aos
-
-#endif  // AOS_COMMON_NETWORK_SOCKET_H_
diff --git a/aos/input/BUILD b/aos/input/BUILD
index ad1915b..b3c5b53 100644
--- a/aos/input/BUILD
+++ b/aos/input/BUILD
@@ -11,7 +11,6 @@
   deps = [
     '//aos/common/input:driver_station_data',
     '//aos/common/messages:robot_state',
-    '//aos/common/network:socket',
     '//aos/common/logging',
     '//aos/common/logging:queue_logging',
   ],
@@ -30,7 +29,6 @@
     '//aos/common/logging',
     '//aos/common/logging:queue_logging',
     '//aos/common/messages:robot_state',
-    '//aos/common/network:socket',
     '//aos/common:math',
     '//frc971/control_loops/drivetrain:drivetrain_queue',
     '//frc971/control_loops/drivetrain:drivetrain_config',