Commit 23ef5e4b authored by Gokhan Sengun's avatar Gokhan Sengun Committed by Daniel Stenberg
Browse files

ftp: active conn, allow application to set sockopt after accept() call

For active FTP connections, applications may need setting the sockopt after accept() call returns successful. This fix gives a call to the callback registered with CURL_SOCKOPTFUNCTION option. Also a new sock type - CURLSOCKTYPE_ACCEPT - is added. This type is to be passed to application callbacks with - purpose - parameter. Applications may use this parameter to distinguish between socket types.
parent 44154e07
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -310,6 +310,7 @@ typedef size_t (*curl_read_callback)(char *buffer,

typedef enum  {
  CURLSOCKTYPE_IPCXN,  /* socket created for a specific IP connection */
  CURLSOCKTYPE_ACCEPT, /* socket created by accept() call */
  CURLSOCKTYPE_LAST    /* never use */
} curlsocktype;

+14 −0
Original line number Diff line number Diff line
@@ -348,6 +348,20 @@ static CURLcode AcceptServerConnect(struct connectdata *conn)
  }
  infof(data, "Connection accepted from server\n");

  if(data->set.fsockopt) {
    int error = 0;

    /* activate callback for setting socket options */
    error = data->set.fsockopt(data->set.sockopt_client,
                               s,
                               CURLSOCKTYPE_ACCEPT);

    if(error) {
      Curl_closesocket(conn, s); /* close the socket and bail out */
      return CURLE_ABORTED_BY_CALLBACK;
    }
  }

  conn->sock[SECONDARYSOCKET] = s;
  curlx_nonblock(s, TRUE); /* enable non-blocking */
  conn->sock_accepted[SECONDARYSOCKET] = TRUE;