brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame^] | 1 | #include "aos/common/network/SendSocket.h" |
| 2 | |
| 3 | #include <string.h> |
| 4 | #include <errno.h> |
| 5 | #include <stdint.h> |
| 6 | #include <stddef.h> |
| 7 | #include <math.h> |
| 8 | |
| 9 | #include "aos/aos_core.h" |
| 10 | #include "aos/common/network/SocketLibraries.h" |
| 11 | |
| 12 | namespace aos { |
| 13 | |
| 14 | int SendSocket::Connect(NetworkPort port, const char *robot_ip, int type) { |
| 15 | Reset(); |
| 16 | const int ret = Socket::Connect(port, robot_ip, type); |
| 17 | if (ret != 0) { |
| 18 | return ret; |
| 19 | } |
| 20 | |
| 21 | if (connect(socket_, &addr_.addr, |
| 22 | sizeof(addr_)) < 0) { |
| 23 | LOG(ERROR, "couldn't connect to ip '%s' because of %d: %s\n", robot_ip, |
| 24 | errno, strerror(errno)); |
| 25 | last_ret_ = 1; |
| 26 | } |
| 27 | |
| 28 | hold_msg_len_ = 0; |
| 29 | return last_ret_ = 0; |
| 30 | } |
| 31 | |
| 32 | int SendSocket::SendHoldMsg() { |
| 33 | if (hold_msg_len_ > 0) { |
| 34 | int val = Send(hold_msg_, hold_msg_len_); |
| 35 | hold_msg_len_ = 0; |
| 36 | return val; |
| 37 | } |
| 38 | return -1; |
| 39 | } |
| 40 | |
| 41 | } // namespace aos |
| 42 | |