Commit c6fa1952 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

portabilty: use proper variable type to hold sockets

Curl_getconnectinfo() is changed to return a proper curl_socket_t for
the last socket so that it'll work more portably (and cause less
compiler warnings).
parent d47bd396
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -1093,12 +1093,12 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
 * Used to extract socket and connectdata struct for the most recent
 * transfer on the given SessionHandle.
 *
 * The socket 'long' will be -1 in case of failure!
 * The returned socket will be CURL_SOCKET_BAD in case of failure!
 */
CURLcode Curl_getconnectinfo(struct SessionHandle *data,
                             long *param_longp,
curl_socket_t Curl_getconnectinfo(struct SessionHandle *data,
                                  struct connectdata **connp)
{
  curl_socket_t sockfd;
  if((data->state.lastconnect != -1) &&
     (data->state.connc->connects[data->state.lastconnect] != NULL)) {
    struct connectdata *c =
@@ -1106,13 +1106,13 @@ CURLcode Curl_getconnectinfo(struct SessionHandle *data,
    if(connp)
      /* only store this if the caller cares for it */
      *connp = c;
    *param_longp = c->sock[FIRSTSOCKET];
    sockfd = c->sock[FIRSTSOCKET];
    /* we have a socket connected, let's determine if the server shut down */
    /* determine if ssl */
    if(c->ssl[FIRSTSOCKET].use) {
      /* use the SSL context */
      if(!Curl_ssl_check_cxn(c))
        *param_longp = -1;   /* FIN received */
        return CURL_SOCKET_BAD;   /* FIN received */
    }
/* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */
#ifdef MSG_PEEK
@@ -1121,13 +1121,13 @@ CURLcode Curl_getconnectinfo(struct SessionHandle *data,
      char buf;
      if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
              (RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) {
        *param_longp = -1;   /* FIN received */
        return CURL_SOCKET_BAD;   /* FIN received */
      }
    }
#endif
  }
  else
    *param_longp = -1;
    return CURL_SOCKET_BAD;

  return CURLE_OK;
  return sockfd;
}
+3 −4
Original line number Diff line number Diff line
@@ -47,10 +47,9 @@ long Curl_timeleft(struct connectdata *conn,
 * Used to extract socket and connectdata struct for the most recent
 * transfer on the given SessionHandle.
 *
 * The socket 'long' will be -1 in case of failure!
 * The returned socket will be CURL_SOCKET_BAD in case of failure!
 */
CURLcode Curl_getconnectinfo(struct SessionHandle *data,
                             long *param_longp,
curl_socket_t Curl_getconnectinfo(struct SessionHandle *data,
                                  struct connectdata **connp);

#ifdef WIN32
+2 −10
Original line number Diff line number Diff line
@@ -1072,9 +1072,6 @@ static CURLcode easy_connection(struct SessionHandle *data,
                                curl_socket_t *sfd,
                                struct connectdata **connp)
{
  CURLcode ret;
  long sockfd;

  if(data == NULL)
    return CURLE_BAD_FUNCTION_ARGUMENT;

@@ -1084,18 +1081,13 @@ static CURLcode easy_connection(struct SessionHandle *data,
    return CURLE_UNSUPPORTED_PROTOCOL;
  }

  ret = Curl_getconnectinfo(data, &sockfd, connp);
  if(ret != CURLE_OK)
    return ret;
  *sfd = Curl_getconnectinfo(data, connp);

  if(sockfd == -1) {
  if(*sfd == CURL_SOCKET_BAD) {
    failf(data, "Failed to get recent socket");
    return CURLE_UNSUPPORTED_PROTOCOL;
  }

  *sfd = (curl_socket_t)sockfd; /* we know that this is actually a socket
                                   descriptor so the typecast is fine here */

  return CURLE_OK;
}

+11 −1
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
  char **param_charp=NULL;
  struct curl_slist **param_slistp=NULL;
  int type;
  curl_socket_t sockfd;

  union {
    struct curl_certinfo * to_certinfo;
@@ -219,7 +220,16 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
    *param_charp = data->state.most_recent_ftp_entrypath;
    break;
  case CURLINFO_LASTSOCKET:
    (void)Curl_getconnectinfo(data, param_longp, NULL);
    sockfd = Curl_getconnectinfo(data, NULL);

    /* note: this is not a good conversion for systems with 64 bit sockets and
       32 bit longs */
    if(sockfd != CURL_SOCKET_BAD)
      *param_longp = (long)sockfd;
    else
      /* this interface is documented to return -1 in case of badness, which
         may not be the same as the CURL_SOCKET_BAD value */
      *param_longp = -1;
    break;
  case CURLINFO_REDIRECT_URL:
    /* Return the URL this request would have been redirected to if that
+3 −4
Original line number Diff line number Diff line
@@ -2698,12 +2698,11 @@ static bool RTSPConnIsDead(struct connectdata *check)
  }
  else if (sval & CURL_CSELECT_IN) {
    /* readable with no error. could be closed or could be alive */
    long connectinfo = 0;
    Curl_getconnectinfo(check->data, &connectinfo, &check);
    if(connectinfo != -1) {
    curl_socket_t connectinfo =
      Curl_getconnectinfo(check->data, &check);
    if(connectinfo != CURL_SOCKET_BAD)
      ret_val = FALSE;
  }
  }

  return ret_val;
}