brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame^] | 1 | #ifndef AOS_NETWORK_SOCKET_H_ |
| 2 | #define AOS_NETWORK_SOCKET_H_ |
| 3 | |
| 4 | #include <sys/socket.h> |
| 5 | #include <sys/types.h> |
| 6 | #include <netinet/in.h> |
| 7 | #include <arpa/inet.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <unistd.h> |
| 10 | #include <stdio.h> |
| 11 | #include "aos/common/Configuration.h" |
| 12 | |
| 13 | namespace aos { |
| 14 | |
| 15 | class Socket { |
| 16 | public: |
| 17 | int LastStatus() const { return last_ret_; } |
| 18 | |
| 19 | int Send(const void *buf, int length); |
| 20 | int Recv(void *buf, int length); |
| 21 | int Recv(void *buf, int length, long usec); // returns 0 if timed out |
| 22 | protected: |
| 23 | int Connect(NetworkPort port, const char *address, int type = SOCK_DGRAM); |
| 24 | Socket(); |
| 25 | ~Socket(); |
| 26 | |
| 27 | // Resets socket_ and last_ret_. |
| 28 | void Reset(); |
| 29 | |
| 30 | union { |
| 31 | sockaddr_in in; |
| 32 | sockaddr addr; |
| 33 | } addr_; // filled in by Connect |
| 34 | |
| 35 | int socket_; |
| 36 | int last_ret_; |
| 37 | }; |
| 38 | |
| 39 | } // namespace aos |
| 40 | |
| 41 | #endif |
| 42 | |