summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_socket.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2019-11-14 16:39:48 +0300
committerIgor Sysoev <igor@sysoev.ru>2019-11-14 16:39:48 +0300
commit96cd6558ce35216fe8cfd7663c7af3345e64c8a8 (patch)
tree2aa7f05b01f344d59900083910952d41bfa3bc82 /src/nxt_socket.c
parent5452ee458d2c764569213266362fb636114adbc2 (diff)
downloadunit-96cd6558ce35216fe8cfd7663c7af3345e64c8a8.tar.gz
unit-96cd6558ce35216fe8cfd7663c7af3345e64c8a8.tar.bz2
Fixed connect(2) errors processing on old Linuxes.
While connect(2) states that non-blocking connect should use EPOLLOUT: EINPROGRESS The socket is non-blocking and the connection cannot be completed immediately. It is possible to select(2) or poll(2) for completion by selecting the socket for writing. After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure). On connect error, Linux 2.6.32 (CentOS 6) may return EPOLLRDHUP, EPOLLERR, EPOLLHUP, EPOLLIN, but not EPOLLOUT.
Diffstat (limited to 'src/nxt_socket.c')
-rw-r--r--src/nxt_socket.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/nxt_socket.c b/src/nxt_socket.c
index 95a298d8..a89663b1 100644
--- a/src/nxt_socket.c
+++ b/src/nxt_socket.c
@@ -300,6 +300,28 @@ nxt_socket_shutdown(nxt_task_t *task, nxt_socket_t s, nxt_uint_t how)
}
+nxt_err_t
+nxt_socket_error(nxt_socket_t s)
+{
+ int ret, err;
+ socklen_t len;
+
+ err = 0;
+ len = sizeof(int);
+ /*
+ * Linux and BSDs return 0 and store a pending error in the err argument;
+ * Solaris returns -1 and sets the errno.
+ */
+ ret = getsockopt(s, SOL_SOCKET, SO_ERROR, (void *) &err, &len);
+
+ if (nxt_slow_path(ret == -1)) {
+ err = nxt_errno;
+ }
+
+ return err;
+}
+
+
nxt_uint_t
nxt_socket_error_level(nxt_err_t err)
{