lib/connect: restrict IP/TCP options to said sockets
This patch prepares for adding UNIX domain sockets support. TCP_NODELAY and TCP_KEEPALIVE are specific to TCP/IP sockets, so do not apply these to other socket types. bindlocal only works for IP sockets (independent of TCP/UDP), so filter that out too for other types. Signed-off-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
parent
397a634ebd
commit
aba5888f6b
@ -991,6 +991,7 @@ static CURLcode singleipconnect(struct connectdata *conn,
|
|||||||
CURLcode result;
|
CURLcode result;
|
||||||
char ipaddress[MAX_IPADR_LEN];
|
char ipaddress[MAX_IPADR_LEN];
|
||||||
long port;
|
long port;
|
||||||
|
bool is_tcp;
|
||||||
|
|
||||||
*sockp = CURL_SOCKET_BAD;
|
*sockp = CURL_SOCKET_BAD;
|
||||||
|
|
||||||
@ -1013,14 +1014,16 @@ static CURLcode singleipconnect(struct connectdata *conn,
|
|||||||
}
|
}
|
||||||
infof(data, " Trying %s...\n", ipaddress);
|
infof(data, " Trying %s...\n", ipaddress);
|
||||||
|
|
||||||
if(data->set.tcp_nodelay)
|
is_tcp = (addr.family == AF_INET || addr.family == AF_INET6) &&
|
||||||
|
addr.socktype == SOCK_STREAM;
|
||||||
|
if(is_tcp && data->set.tcp_nodelay)
|
||||||
tcpnodelay(conn, sockfd);
|
tcpnodelay(conn, sockfd);
|
||||||
|
|
||||||
nosigpipe(conn, sockfd);
|
nosigpipe(conn, sockfd);
|
||||||
|
|
||||||
Curl_sndbufset(sockfd);
|
Curl_sndbufset(sockfd);
|
||||||
|
|
||||||
if(data->set.tcp_keepalive)
|
if(is_tcp && data->set.tcp_keepalive)
|
||||||
tcpkeepalive(data, sockfd);
|
tcpkeepalive(data, sockfd);
|
||||||
|
|
||||||
if(data->set.fsockopt) {
|
if(data->set.fsockopt) {
|
||||||
@ -1038,16 +1041,17 @@ static CURLcode singleipconnect(struct connectdata *conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* possibly bind the local end to an IP, interface or port */
|
/* possibly bind the local end to an IP, interface or port */
|
||||||
result = bindlocal(conn, sockfd, addr.family);
|
if(addr.family == AF_INET || addr.family == AF_INET6) {
|
||||||
if(result) {
|
result = bindlocal(conn, sockfd, addr.family);
|
||||||
Curl_closesocket(conn, sockfd); /* close socket and bail out */
|
if(result) {
|
||||||
if(result == CURLE_UNSUPPORTED_PROTOCOL) {
|
Curl_closesocket(conn, sockfd); /* close socket and bail out */
|
||||||
/* The address family is not supported on this interface.
|
if(result == CURLE_UNSUPPORTED_PROTOCOL) {
|
||||||
We can continue trying addresses */
|
/* The address family is not supported on this interface.
|
||||||
return CURLE_OK;
|
We can continue trying addresses */
|
||||||
|
return CURLE_OK;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set socket non-blocking */
|
/* set socket non-blocking */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user