635
639
if(conn->bits.tcpconnect) {
636
640
/* we are connected already! */
637
long allow_total = 0;
639
/* subtract the most strict timeout of the ones */
640
if(data->set.timeout)
641
allow_total = data->set.timeout;
643
Curl_expire(data, allow_total);
644
641
*connected = TRUE;
654
651
return CURLE_OPERATION_TIMEDOUT;
657
Curl_expire(data, allow);
659
654
/* check for connect without timeout as we want to return immediately */
660
655
rc = waitconnect(conn, sockfd, 0);
656
if(WAITCONN_TIMEOUT == rc)
657
/* not an error, but also no connection yet */
662
660
if(WAITCONN_CONNECTED == rc) {
664
661
if(verifyconnect(sockfd, &error)) {
665
662
/* we are connected, awesome! */
666
663
conn->bits.tcpconnect = TRUE;
674
671
/* nope, not connected for real */
675
data->state.os_errno = error;
676
infof(data, "Connection failed\n");
677
code = trynextip(conn, sockindex, connected);
679
failf(data, "Failed connect to %s:%ld; %s",
680
conn->host.name, conn->port, Curl_strerror(conn, error));
682
else if(WAITCONN_TIMEOUT != rc) {
685
674
/* nope, not connected */
686
675
if(WAITCONN_FDSET_ERROR == rc) {
687
676
(void)verifyconnect(sockfd, &error);
688
data->state.os_errno = error;
689
infof(data, "%s\n",Curl_strerror(conn,error));
677
infof(data, "%s\n",Curl_strerror(conn, error));
692
680
infof(data, "Connection failed\n");
694
code = trynextip(conn, sockindex, connected);
698
data->state.os_errno = error;
699
failf(data, "Failed connect to %s:%ld; %s",
700
conn->host.name, conn->port, Curl_strerror(conn, error));
704
* If the connection failed here, we should attempt to connect to the "next
705
* address" for the given host.
684
* The connection failed here, we should attempt to connect to the "next
685
* address" for the given host. But first remember the latest error.
688
data->state.os_errno = error;
689
SET_SOCKERRNO(error);
692
code = trynextip(conn, sockindex, connected);
696
data->state.os_errno = error;
697
failf(data, "Failed connect to %s:%ld; %s",
698
conn->host.name, conn->port, Curl_strerror(conn, error));
1029
1022
failf(data, "Connection time-out");
1030
1023
return CURLE_OPERATION_TIMEDOUT;
1032
Curl_expire(data, timeout_ms);
1034
1026
/* Max time for each address */
1035
1027
num_addr = Curl_num_addresses(remotehost->addr);
1094
1086
* Used to extract socket and connectdata struct for the most recent
1095
1087
* transfer on the given SessionHandle.
1097
* The socket 'long' will be -1 in case of failure!
1089
* The returned socket will be CURL_SOCKET_BAD in case of failure!
1099
CURLcode Curl_getconnectinfo(struct SessionHandle *data,
1101
struct connectdata **connp)
1091
curl_socket_t Curl_getconnectinfo(struct SessionHandle *data,
1092
struct connectdata **connp)
1094
curl_socket_t sockfd;
1103
1095
if((data->state.lastconnect != -1) &&
1104
1096
(data->state.connc->connects[data->state.lastconnect] != NULL)) {
1105
1097
struct connectdata *c =
1108
1100
/* only store this if the caller cares for it */
1110
*param_longp = c->sock[FIRSTSOCKET];
1102
sockfd = c->sock[FIRSTSOCKET];
1111
1103
/* we have a socket connected, let's determine if the server shut down */
1112
1104
/* determine if ssl */
1113
1105
if(c->ssl[FIRSTSOCKET].use) {
1114
1106
/* use the SSL context */
1115
1107
if(!Curl_ssl_check_cxn(c))
1116
*param_longp = -1; /* FIN received */
1108
return CURL_SOCKET_BAD; /* FIN received */
1118
1110
/* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */
1119
1111
#ifdef MSG_PEEK
1123
1115
if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
1124
1116
(RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) {
1125
*param_longp = -1; /* FIN received */
1117
return CURL_SOCKET_BAD; /* FIN received */
1123
return CURL_SOCKET_BAD;