mirror of
https://github.com/curl/curl.git
synced 2026-07-23 11:57:18 +03:00
cf-socket: ignore SOCK_CLOEXEC etc for socktype equality checks
As the SOCK_CLOEXEC and SOCK_NONBLOCK get ORed to the socktype, this
introduces the cf_socktype() function to use when checking for the
specific socket type: DGRAM or STREAM. The function filters off the
non-type related bits to enable the comparison.
Follow-up to 05367694ec
Closes #20808
This commit is contained in:
parent
e3d7401a32
commit
08d6497005
1 changed files with 16 additions and 3 deletions
|
|
@ -1040,6 +1040,19 @@ static CURLcode set_remote_ip(struct Curl_cfilter *cf,
|
|||
return CURLE_OK;
|
||||
}
|
||||
|
||||
/* to figure out the type of the socket safely, remove the possibly ORed
|
||||
bits before comparing */
|
||||
static int cf_socktype(int x)
|
||||
{
|
||||
#ifdef SOCK_CLOEXEC
|
||||
x &= ~SOCK_CLOEXEC;
|
||||
#endif
|
||||
#ifdef SOCK_NONBLOCK
|
||||
x &= ~SOCK_NONBLOCK;
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
|
||||
static CURLcode cf_socket_open(struct Curl_cfilter *cf,
|
||||
struct Curl_easy *data)
|
||||
{
|
||||
|
|
@ -1095,10 +1108,10 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf,
|
|||
#ifdef USE_IPV6
|
||||
is_tcp = (ctx->addr.family == AF_INET ||
|
||||
ctx->addr.family == AF_INET6) &&
|
||||
ctx->addr.socktype == SOCK_STREAM;
|
||||
cf_socktype(ctx->addr.socktype) == SOCK_STREAM;
|
||||
#else
|
||||
is_tcp = (ctx->addr.family == AF_INET) &&
|
||||
ctx->addr.socktype == SOCK_STREAM;
|
||||
cf_socktype(ctx->addr.socktype) == SOCK_STREAM;
|
||||
#endif
|
||||
if(is_tcp && data->set.tcp_nodelay)
|
||||
tcpnodelay(cf, data, ctx->sock);
|
||||
|
|
@ -1163,7 +1176,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf,
|
|||
}
|
||||
}
|
||||
#endif
|
||||
ctx->sock_connected = (ctx->addr.socktype != SOCK_DGRAM);
|
||||
ctx->sock_connected = (cf_socktype(ctx->addr.socktype) != SOCK_DGRAM);
|
||||
out:
|
||||
if(result) {
|
||||
if(ctx->sock != CURL_SOCKET_BAD) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue