From: Stefan Metzmacher Date: Wed, 26 Feb 2020 12:36:05 +0000 (+0100) Subject: s3:lib: avoid calling async_connect_send() again and again in open_socket_out*() X-Git-Tag: ldb-2.2.0~1583 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a26be7eeedc4995ea1a99f4bbb6ce8beaafda012;p=thirdparty%2Fsamba.git s3:lib: avoid calling async_connect_send() again and again in open_socket_out*() There's really no need to do that! Once connect() is called and returned EINPROGRESS, the kernel knowns what to do and reports any state change via TEVENT_FD_READ or TEVENT_FD_WRITE. The actual success or failure is available via getsockopt(.., SOL_SOCKET, SO_ERROR, ...). Before this commit we called connect() (via async_connect_send()) again and again until we reached the final caller provided timeout, even if the kernel already found out that the destination is unreachable. Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 0649873a9f6..e48cdb07ca9 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -417,7 +417,6 @@ struct open_socket_out_state { struct sockaddr_storage ss; socklen_t salen; uint16_t port; - int wait_usec; struct tevent_req *connect_subreq; }; @@ -471,7 +470,6 @@ struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx, state->ev = ev; state->ss = *pss; state->port = port; - state->wait_usec = 10000; state->salen = -1; state->fd = socket(state->ss.ss_family, SOCK_STREAM, 0); @@ -522,12 +520,6 @@ struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx, if (tevent_req_nomem(state->connect_subreq, NULL)) { return tevent_req_post(req, ev); } - if (!tevent_req_set_endtime( - state->connect_subreq, state->ev, - timeval_current_ofs(0, state->wait_usec))) { - tevent_req_oom(req); - return tevent_req_post(req, ev); - } tevent_req_set_callback(state->connect_subreq, open_socket_out_connected, req); return req; @@ -550,46 +542,6 @@ static void open_socket_out_connected(struct tevent_req *subreq) return; } - if ( -#ifdef ETIMEDOUT - (sys_errno == ETIMEDOUT) || -#endif - (sys_errno == EINPROGRESS) || - (sys_errno == EALREADY) || - (sys_errno == EAGAIN)) { - - /* - * retry - */ - - if (state->wait_usec < 250000) { - state->wait_usec *= 1.5; - } - - subreq = async_connect_send(state, state->ev, state->fd, - (struct sockaddr *)&state->ss, - state->salen, NULL, NULL, NULL); - if (tevent_req_nomem(subreq, req)) { - return; - } - if (!tevent_req_set_endtime( - subreq, state->ev, - timeval_current_ofs_usec(state->wait_usec))) { - return; - } - state->connect_subreq = subreq; - tevent_req_set_callback(subreq, open_socket_out_connected, req); - return; - } - -#ifdef EISCONN - if (sys_errno == EISCONN) { - tevent_req_done(req); - return; - } -#endif - - /* real error */ tevent_req_nterror(req, map_nt_error_from_unix(sys_errno)); }