William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 1 | #include "net_sockio.h" |
| 2 | |
| 3 | #include <sys/socket.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | namespace net |
| 7 | { |
| 8 | |
| 9 | int SockIO::close() |
| 10 | { |
| 11 | int ret = 0; |
| 12 | if (sockfd_ >= 0) |
| 13 | { |
| 14 | ret = ::close(sockfd_); |
| 15 | sockfd_ = -1; |
| 16 | } |
| 17 | |
| 18 | return ret; |
| 19 | } |
| 20 | |
| 21 | int SockIO::write(const void* buf, size_t len) |
| 22 | { |
| 23 | return ::write(sockfd_, buf, len); |
| 24 | } |
| 25 | |
| 26 | int SockIO::recv(void* buf, size_t maxlen) |
| 27 | { |
| 28 | return ::recv(sockfd_, buf, maxlen, 0); |
| 29 | } |
| 30 | |
| 31 | SockIO::~SockIO() |
| 32 | { |
| 33 | SockIO::close(); |
| 34 | } |
| 35 | |
| 36 | } // namespace net |