| 193 | } // namespace |
| 194 | |
| 195 | void SocketCore::create(int family, int protocol) |
| 196 | { |
| 197 | int errNum; |
| 198 | closeConnection(); |
| 199 | sock_t fd = socket(family, sockType_, protocol); |
| 200 | errNum = SOCKET_ERRNO; |
| 201 | if (fd == (sock_t)-1) { |
| 202 | throw DL_ABORT_EX( |
| 203 | fmt("Failed to create socket. Cause:%s", errorMsg(errNum).c_str())); |
| 204 | } |
| 205 | util::make_fd_cloexec(fd); |
| 206 | int sockopt = 1; |
| 207 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (a2_sockopt_t)&sockopt, |
| 208 | sizeof(sockopt)) < 0) { |
| 209 | errNum = SOCKET_ERRNO; |
| 210 | CLOSE(fd); |
| 211 | throw DL_ABORT_EX( |
| 212 | fmt("Failed to create socket. Cause:%s", errorMsg(errNum).c_str())); |
| 213 | } |
| 214 | |
| 215 | applySocketBufferSize(fd); |
| 216 | |
| 217 | sockfd_ = fd; |
| 218 | } |
| 219 | |
| 220 | static sock_t bindInternal(int family, int socktype, int protocol, |
| 221 | const struct sockaddr* addr, socklen_t addrlen, |
nothing calls this directly
no test coverage detected