diff options
| author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-06-13 05:08:30 +0200 |
|---|---|---|
| committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-06-14 06:23:37 +0200 |
| commit | 27fd6f9615f36aec71877e2b99aa3655e22da75d (patch) | |
| tree | 61fad1a87ed71a594a12682e2bf50801c27c8460 /src/net.c | |
| parent | cmake: fix grammar in option description (diff) | |
| download | cimple-27fd6f9615f36aec71877e2b99aa3655e22da75d.tar.gz cimple-27fd6f9615f36aec71877e2b99aa3655e22da75d.zip | |
minor refactoring
Diffstat (limited to 'src/net.c')
| -rw-r--r-- | src/net.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -21,6 +21,7 @@ int net_bind(const char *port) { + static const int flags = SOCK_CLOEXEC; struct addrinfo *result = NULL, *it = NULL; struct addrinfo hints; int socket_fd = -1, ret = 0; @@ -37,7 +38,7 @@ int net_bind(const char *port) } for (it = result; it; it = it->ai_next) { - socket_fd = socket(it->ai_family, it->ai_socktype | SOCK_CLOEXEC, it->ai_protocol); + socket_fd = socket(it->ai_family, it->ai_socktype | flags, it->ai_protocol); if (socket_fd < 0) { log_errno("socket"); continue; @@ -92,9 +93,10 @@ fail: int net_accept(int fd) { + static const int flags = SOCK_CLOEXEC; int ret = 0; - ret = accept4(fd, NULL, NULL, SOCK_CLOEXEC); + ret = accept4(fd, NULL, NULL, flags); if (ret < 0) { log_errno("accept"); return ret; @@ -105,6 +107,7 @@ int net_accept(int fd) int net_connect(const char *host, const char *port) { + static const int flags = SOCK_CLOEXEC; struct addrinfo *result = NULL, *it = NULL; struct addrinfo hints; int socket_fd = -1, ret = 0; @@ -120,7 +123,7 @@ int net_connect(const char *host, const char *port) } for (it = result; it; it = it->ai_next) { - socket_fd = socket(it->ai_family, it->ai_socktype | SOCK_CLOEXEC, it->ai_protocol); + socket_fd = socket(it->ai_family, it->ai_socktype | flags, it->ai_protocol); if (socket_fd < 0) { log_errno("socket"); continue; |
