|
@@ -1555,14 +1555,14 @@ ioa_socket_handle detach_ioa_socket(ioa_socket_handle s) {
|
|
|
|
|
|
if (addr_bind(udp_fd, &(s->local_addr), 1, 1, UDP_SOCKET) < 0) {
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot bind new detached udp server socket to local addr\n");
|
|
|
- close(udp_fd);
|
|
|
+ socket_closesocket(udp_fd);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
int connect_err = 0;
|
|
|
if (addr_connect(udp_fd, &(s->remote_addr), &connect_err) < 0) {
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot connect new detached udp server socket to remote addr\n");
|
|
|
- close(udp_fd);
|
|
|
+ socket_closesocket(udp_fd);
|
|
|
return ret;
|
|
|
}
|
|
|
set_raw_socket_ttl_options(udp_fd, s->local_addr.ss.sa_family);
|
|
@@ -1580,7 +1580,7 @@ ioa_socket_handle detach_ioa_socket(ioa_socket_handle s) {
|
|
|
if (!ret) {
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "%s: Cannot allocate new socket structure\n", __FUNCTION__);
|
|
|
if (udp_fd >= 0)
|
|
|
- close(udp_fd);
|
|
|
+ socket_closesocket(udp_fd);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -1787,7 +1787,7 @@ int ssl_read(evutil_socket_t fd, SSL *ssl, ioa_network_buffer_handle nbh, int ve
|
|
|
|
|
|
do {
|
|
|
len = SSL_read(ssl, new_buffer, buf_size);
|
|
|
- } while (len < 0 && (errno == EINTR));
|
|
|
+ } while (len < 0 && socket_eintr());
|
|
|
|
|
|
int if2 = SSL_is_init_finished(ssl);
|
|
|
|
|
@@ -1814,7 +1814,7 @@ int ssl_read(evutil_socket_t fd, SSL *ssl, ioa_network_buffer_handle nbh, int ve
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
- } else if (len < 0 && ((errno == ENOBUFS) || (errno == EAGAIN))) {
|
|
|
+ } else if (len < 0 && (socket_enobufs() || socket_eagain())) {
|
|
|
if (eve(verbose)) {
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: ENOBUFS/EAGAIN\n", __FUNCTION__);
|
|
|
}
|
|
@@ -1843,7 +1843,7 @@ int ssl_read(evutil_socket_t fd, SSL *ssl, ioa_network_buffer_handle nbh, int ve
|
|
|
ret = 0;
|
|
|
break;
|
|
|
case SSL_ERROR_SYSCALL: {
|
|
|
- int err = errno;
|
|
|
+ int err = socket_errno();
|
|
|
if (handle_socket_error()) {
|
|
|
ret = 0;
|
|
|
} else {
|
|
@@ -1922,7 +1922,7 @@ static int socket_readerr(evutil_socket_t fd, ioa_addr *orig_addr) {
|
|
|
|
|
|
do {
|
|
|
len = recvmsg(fd, &msg, flags);
|
|
|
- } while (len < 0 && (errno == EINTR));
|
|
|
+ } while (len < 0 && socket_eintr());
|
|
|
|
|
|
} while ((len > 0) && (try_cycle++ < MAX_ERRORS_IN_UDP_BATCH));
|
|
|
|
|
@@ -1952,9 +1952,9 @@ int udp_recvfrom(evutil_socket_t fd, ioa_addr *orig_addr, const ioa_addr *like_a
|
|
|
#if defined(_MSC_VER) || !defined(CMSG_SPACE)
|
|
|
do {
|
|
|
len = recvfrom(fd, buffer, buf_size, flags, (struct sockaddr *)orig_addr, (socklen_t *)&slen);
|
|
|
- } while (len < 0 && (errno == EINTR));
|
|
|
+ } while (len < 0 && socket_eintr());
|
|
|
if (len < 0 && errcode)
|
|
|
- *errcode = (uint32_t)errno;
|
|
|
+ *errcode = (uint32_t)socket_errno();
|
|
|
#else
|
|
|
struct msghdr msg;
|
|
|
struct iovec iov;
|
|
@@ -1980,7 +1980,7 @@ try_again:
|
|
|
|
|
|
do {
|
|
|
len = recvmsg(fd, &msg, flags);
|
|
|
- } while (len < 0 && (errno == EINTR));
|
|
|
+ } while (len < 0 && socket_eintr());
|
|
|
|
|
|
#if defined(MSG_ERRQUEUE)
|
|
|
|
|
@@ -1997,7 +1997,7 @@ try_again:
|
|
|
// try again...
|
|
|
do {
|
|
|
len = recvmsg(fd, &msg, flags);
|
|
|
- } while (len < 0 && (errno == EINTR));
|
|
|
+ } while (len < 0 && socket_eintr());
|
|
|
}
|
|
|
#endif
|
|
|
|
|
@@ -2090,7 +2090,7 @@ static TURN_TLS_TYPE check_tentative_tls(ioa_socket_raw fd) {
|
|
|
|
|
|
do {
|
|
|
len = (int)recv(fd, s, sizeof(s), MSG_PEEK);
|
|
|
- } while (len < 0 && (errno == EINTR));
|
|
|
+ } while (len < 0 && socket_eintr());
|
|
|
|
|
|
if (len > 0 && ((size_t)len == sizeof(s))) {
|
|
|
if ((s[0] == 22) && (s[1] == 3) && (s[5] == 1) && (s[9] == 3)) {
|
|
@@ -2932,13 +2932,13 @@ try_start:
|
|
|
|
|
|
do {
|
|
|
rc = SSL_write(ssl, buffer, len);
|
|
|
- } while (rc < 0 && errno == EINTR);
|
|
|
+ } while (rc < 0 && socket_eintr());
|
|
|
|
|
|
if (eve(verbose)) {
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: after write: %d\n", __FUNCTION__, rc);
|
|
|
}
|
|
|
|
|
|
- if (rc < 0 && ((errno == ENOBUFS) || (errno == EAGAIN))) {
|
|
|
+ if (rc < 0 && (socket_enobufs() || socket_eagain())) {
|
|
|
if (eve(verbose)) {
|
|
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: ENOBUFS/EAGAIN\n", __FUNCTION__);
|
|
|
}
|
|
@@ -2972,7 +2972,7 @@ try_start:
|
|
|
case SSL_ERROR_WANT_READ:
|
|
|
return 0;
|
|
|
case SSL_ERROR_SYSCALL: {
|
|
|
- int err = errno;
|
|
|
+ int err = socket_errno();
|
|
|
if (!handle_socket_error()) {
|
|
|
if (s->st == DTLS_SOCKET) {
|
|
|
if (is_connreset()) {
|
|
@@ -3036,22 +3036,13 @@ static int send_ssl_backlog_buffers(ioa_socket_handle s) {
|
|
|
}
|
|
|
|
|
|
int is_connreset(void) {
|
|
|
- switch (errno) {
|
|
|
- case ECONNRESET:
|
|
|
- case ECONNREFUSED:
|
|
|
+ if (socket_econnreset() || socket_econnrefused()) {
|
|
|
return 1;
|
|
|
- default:;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int would_block(void) {
|
|
|
-#if defined(EWOULDBLOCK)
|
|
|
- if (errno == EWOULDBLOCK)
|
|
|
- return 1;
|
|
|
-#endif
|
|
|
- return (errno == EAGAIN);
|
|
|
-}
|
|
|
+int would_block(void) { return socket_ewouldblock(); }
|
|
|
|
|
|
int udp_send(ioa_socket_handle s, const ioa_addr *dest_addr, const char *buffer, int len) {
|
|
|
int rc = 0;
|
|
@@ -3085,16 +3076,16 @@ int udp_send(ioa_socket_handle s, const ioa_addr *dest_addr, const char *buffer,
|
|
|
|
|
|
do {
|
|
|
rc = sendto(fd, buffer, len, 0, (const struct sockaddr *)dest_addr, (socklen_t)slen);
|
|
|
- } while (((rc < 0) && (errno == EINTR)) || ((rc < 0) && is_connreset() && (++cycle < TRIAL_EFFORTS_TO_SEND)));
|
|
|
+ } while (((rc < 0) && socket_eintr()) || ((rc < 0) && is_connreset() && (++cycle < TRIAL_EFFORTS_TO_SEND)));
|
|
|
|
|
|
} else {
|
|
|
do {
|
|
|
rc = send(fd, buffer, len, 0);
|
|
|
- } while (((rc < 0) && (errno == EINTR)) || ((rc < 0) && is_connreset() && (++cycle < TRIAL_EFFORTS_TO_SEND)));
|
|
|
+ } while (((rc < 0) && socket_eintr()) || ((rc < 0) && is_connreset() && (++cycle < TRIAL_EFFORTS_TO_SEND)));
|
|
|
}
|
|
|
|
|
|
if (rc < 0) {
|
|
|
- if ((errno == ENOBUFS) || (errno == EAGAIN)) {
|
|
|
+ if (socket_enobufs() || socket_eagain()) {
|
|
|
// Lost packet due to overload ... fine.
|
|
|
rc = len;
|
|
|
} else if (is_connreset()) {
|
|
@@ -3197,7 +3188,7 @@ int send_data_from_ioa_socket_nbh(ioa_socket_handle s, ioa_addr *dest_addr, ioa_
|
|
|
if (ret < 0) {
|
|
|
s->tobeclosed = 1;
|
|
|
#if defined(EADDRNOTAVAIL)
|
|
|
- int perr = errno;
|
|
|
+ int perr = socket_errno();
|
|
|
#endif
|
|
|
perror("udp send");
|
|
|
#if defined(EADDRNOTAVAIL)
|