ssh: dedupe `ssh_pollset()` functions
No binary (build failed)
—
(log yok)
| @@ -2448,36 +2448,6 @@ static CURLcode myssh_statemachine(struct Curl_easy *data, | |
| return result; | |
| } | |
| - | /* called by the multi interface to figure out what socket(s) to wait for and |
| - | for what actions in the DO_DONE, PERFORM and WAITPERFORM states */ |
| - | static CURLcode myssh_pollset(struct Curl_easy *data, |
| - | struct easy_pollset *ps) |
| - | { |
| - | struct connectdata *conn = data->conn; |
| - | struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); |
| - | curl_socket_t sock = conn->sock[FIRSTSOCKET]; |
| - | int waitfor; |
| - | |
| - | if(!sshc || (sock == CURL_SOCKET_BAD)) |
| - | return CURLE_FAILED_INIT; |
| - | |
| - | waitfor = sshc->waitfor ? sshc->waitfor : data->req.io_flags; |
| - | if(waitfor) { |
| - | int flags = 0; |
| - | if(waitfor & REQ_IO_RECV) |
| - | flags |= CURL_POLL_IN; |
| - | if(waitfor & REQ_IO_SEND) |
| - | flags |= CURL_POLL_OUT; |
| - | DEBUGASSERT(flags); |
| - | CURL_TRC_SSH(data, "pollset, flags=%x", (unsigned int)flags); |
| - | return Curl_pollset_change(data, ps, sock, flags, 0); |
| - | } |
| - | /* While we still have a session, we listen incoming data. */ |
| - | if(sshc->ssh_session) |
| - | return Curl_pollset_change(data, ps, sock, CURL_POLL_IN, 0); |
| - | return CURLE_OK; |
| - | } |
| - | |
| /* called repeatedly until done from multi.c */ | |
| static CURLcode myssh_multi_statemach(struct Curl_easy *data, | |
| bool *done) | |
| @@ -2485,8 +2455,8 @@ static CURLcode myssh_multi_statemach(struct Curl_easy *data, | |
| struct connectdata *conn = data->conn; | |
| struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); | |
| struct SSHPROTO *sshp = Curl_meta_get(data, CURL_META_SSH_EASY); | |
| - | bool block; /* we store the status and use that to provide a ssh_pollset() |
| - | implementation */ |
| + | bool block; /* we store the status and use that to provide |
| + | a Curl_ssh_pollset() implementation */ |
| CURLcode result; | |
| if(!sshc || !sshp) | |
| @@ -3168,10 +3138,10 @@ const struct Curl_protocol Curl_protocol_scp = { | |
| myssh_connect, /* connect_it */ | |
| myssh_multi_statemach, /* connecting */ | |
| scp_doing, /* doing */ | |
| - | myssh_pollset, /* proto_pollset */ |
| - | myssh_pollset, /* doing_pollset */ |
| + | Curl_ssh_pollset, /* proto_pollset */ |
| + | Curl_ssh_pollset, /* doing_pollset */ |
| ZERO_NULL, /* domore_pollset */ | |
| - | myssh_pollset, /* perform_pollset */ |
| + | Curl_ssh_pollset, /* perform_pollset */ |
| scp_disconnect, /* disconnect */ | |
| ZERO_NULL, /* write_resp */ | |
| ZERO_NULL, /* write_resp_hd */ | |
| @@ -3191,10 +3161,10 @@ const struct Curl_protocol Curl_protocol_sftp = { | |
| myssh_connect, /* connect_it */ | |
| myssh_multi_statemach, /* connecting */ | |
| sftp_doing, /* doing */ | |
| - | myssh_pollset, /* proto_pollset */ |
| - | myssh_pollset, /* doing_pollset */ |
| + | Curl_ssh_pollset, /* proto_pollset */ |
| + | Curl_ssh_pollset, /* doing_pollset */ |
| ZERO_NULL, /* domore_pollset */ | |
| - | myssh_pollset, /* perform_pollset */ |
| + | Curl_ssh_pollset, /* perform_pollset */ |
| sftp_disconnect, /* disconnect */ | |
| ZERO_NULL, /* write_resp */ | |
| ZERO_NULL, /* write_resp_hd */ | |
| @@ -3196,36 +3196,6 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, | |
| return result; | |
| } | |
| - | /* called by the multi interface to figure out what socket(s) to wait for and |
| - | for what actions in the DO_DONE, PERFORM and WAITPERFORM states */ |
| - | static CURLcode ssh_pollset(struct Curl_easy *data, |
| - | struct easy_pollset *ps) |
| - | { |
| - | struct connectdata *conn = data->conn; |
| - | struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); |
| - | curl_socket_t sock = conn->sock[FIRSTSOCKET]; |
| - | int waitfor; |
| - | |
| - | if(!sshc || (sock == CURL_SOCKET_BAD)) |
| - | return CURLE_FAILED_INIT; |
| - | |
| - | waitfor = sshc->waitfor ? sshc->waitfor : data->req.io_flags; |
| - | if(waitfor) { |
| - | int flags = 0; |
| - | if(waitfor & REQ_IO_RECV) |
| - | flags |= CURL_POLL_IN; |
| - | if(waitfor & REQ_IO_SEND) |
| - | flags |= CURL_POLL_OUT; |
| - | DEBUGASSERT(flags); |
| - | CURL_TRC_SSH(data, "pollset, flags=%x", (unsigned int)flags); |
| - | return Curl_pollset_change(data, ps, sock, flags, 0); |
| - | } |
| - | /* While we still have a session, we listen incoming data. */ |
| - | if(sshc->ssh_session) |
| - | return Curl_pollset_change(data, ps, sock, CURL_POLL_IN, 0); |
| - | return CURLE_OK; |
| - | } |
| - | |
| /* | |
| * When one of the libssh2 functions has returned LIBSSH2_ERROR_EAGAIN this | |
| * function is used to figure out in what direction and stores this info so | |
| @@ -3259,8 +3229,8 @@ static CURLcode ssh_multi_statemach(struct Curl_easy *data, bool *done) | |
| struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); | |
| struct SSHPROTO *sshp = Curl_meta_get(data, CURL_META_SSH_EASY); | |
| CURLcode result = CURLE_OK; | |
| - | bool block; /* we store the status and use that to provide a ssh_pollset() |
| - | implementation */ |
| + | bool block; /* we store the status and use that to provide |
| + | a Curl_ssh_pollset() implementation */ |
| if(!sshc || !sshp) | |
| return CURLE_FAILED_INIT; | |
| @@ -4014,10 +3984,10 @@ const struct Curl_protocol Curl_protocol_scp = { | |
| ssh_connect, /* connect_it */ | |
| ssh_multi_statemach, /* connecting */ | |
| scp_doing, /* doing */ | |
| - | ssh_pollset, /* proto_pollset */ |
| - | ssh_pollset, /* doing_pollset */ |
| + | Curl_ssh_pollset, /* proto_pollset */ |
| + | Curl_ssh_pollset, /* doing_pollset */ |
| ZERO_NULL, /* domore_pollset */ | |
| - | ssh_pollset, /* perform_pollset */ |
| + | Curl_ssh_pollset, /* perform_pollset */ |
| scp_disconnect, /* disconnect */ | |
| ZERO_NULL, /* write_resp */ | |
| ZERO_NULL, /* write_resp_hd */ | |
| @@ -4037,10 +4007,10 @@ const struct Curl_protocol Curl_protocol_sftp = { | |
| ssh_connect, /* connect_it */ | |
| ssh_multi_statemach, /* connecting */ | |
| sftp_doing, /* doing */ | |
| - | ssh_pollset, /* proto_pollset */ |
| - | ssh_pollset, /* doing_pollset */ |
| + | Curl_ssh_pollset, /* proto_pollset */ |
| + | Curl_ssh_pollset, /* doing_pollset */ |
| ZERO_NULL, /* domore_pollset */ | |
| - | ssh_pollset, /* perform_pollset */ |
| + | Curl_ssh_pollset, /* perform_pollset */ |
| sftp_disconnect, /* disconnect */ | |
| ZERO_NULL, /* write_resp */ | |
| ZERO_NULL, /* write_resp_hd */ | |
| @@ -30,6 +30,8 @@ | |
| #include "curlx/strparse.h" | |
| #include "curl_trc.h" | |
| #include "escape.h" | |
| + | #include "select.h" /* for Curl_pollset_change() */ |
| + | #include "url.h" /* for Curl_conn_meta_get() */ |
| #ifdef CURLVERBOSE | |
| const char *Curl_ssh_statename(sshstate state) | |
| @@ -330,4 +332,33 @@ CURLcode Curl_ssh_range(struct Curl_easy *data, | |
| return CURLE_OK; | |
| } | |
| + | /* called by the multi interface to figure out what socket(s) to wait for and |
| + | for what actions in the DO_DONE, PERFORM and WAITPERFORM states */ |
| + | CURLcode Curl_ssh_pollset(struct Curl_easy *data, struct easy_pollset *ps) |
| + | { |
| + | struct connectdata *conn = data->conn; |
| + | struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); |
| + | curl_socket_t sock = conn->sock[FIRSTSOCKET]; |
| + | int waitfor; |
| + | |
| + | if(!sshc || (sock == CURL_SOCKET_BAD)) |
| + | return CURLE_FAILED_INIT; |
| + | |
| + | waitfor = sshc->waitfor ? sshc->waitfor : data->req.io_flags; |
| + | if(waitfor) { |
| + | int flags = 0; |
| + | if(waitfor & REQ_IO_RECV) |
| + | flags |= CURL_POLL_IN; |
| + | if(waitfor & REQ_IO_SEND) |
| + | flags |= CURL_POLL_OUT; |
| + | DEBUGASSERT(flags); |
| + | CURL_TRC_SSH(data, "pollset, flags=%x", (unsigned int)flags); |
| + | return Curl_pollset_change(data, ps, sock, flags, 0); |
| + | } |
| + | /* While we still have a session, we listen incoming data. */ |
| + | if(sshc->ssh_session) |
| + | return Curl_pollset_change(data, ps, sock, CURL_POLL_IN, 0); |
| + | return CURLE_OK; |
| + | } |
| + | |
| #endif /* USE_SSH */ | |
| @@ -38,5 +38,7 @@ CURLcode Curl_get_pathname(const char **cpp, char **path, const char *homedir); | |
| CURLcode Curl_ssh_range(struct Curl_easy *data, | |
| const char *range, curl_off_t filesize, | |
| curl_off_t *startp, curl_off_t *sizep); | |
| + | |
| + | CURLcode Curl_ssh_pollset(struct Curl_easy *data, struct easy_pollset *ps); |
| #endif /* USE_SSH */ | |
| #endif /* HEADER_CURL_VSSH_VSSH_H */ | |