| 64 | namespace net { |
| 65 | |
| 66 | static int socket(int family, int protocol = 0, |
| 67 | bool nonblocking = true, bool nodelay = true) { |
| 68 | int fd = ::socket(family, SOCK_STREAM, protocol); |
| 69 | if (fd < 0) |
| 70 | LOG_ERRNO_RETURN(0, -1, "failed to create socket fd"); |
| 71 | if (nonblocking) |
| 72 | set_fd_nonblocking(fd); |
| 73 | if (nodelay) { |
| 74 | int v = 1; |
| 75 | if (::setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v)) < 0) |
| 76 | LOG_WARN("failed to set TCP_NODELAY ", ERRNO()); |
| 77 | } |
| 78 | return fd; |
| 79 | } |
| 80 | |
| 81 | template<typename Stream> inline |
| 82 | Stream* new_stream(int family, int protocol = 0, bool nonblocking = true) { |
no test coverage detected