cf-socket: avoid broken NetBSD SOCK_NONBLOCK
No binary (build failed)
—
(log yok)
| @@ -1142,7 +1142,7 @@ static int cf_socktype(int x) | |
| #ifdef SOCK_CLOEXEC | |
| x &= ~SOCK_CLOEXEC; | |
| #endif | |
| - | #ifdef SOCK_NONBLOCK |
| + | #ifdef CURL_USE_SOCK_NONBLOCK |
| x &= ~SOCK_NONBLOCK; | |
| #endif | |
| return x; | |
| @@ -1204,7 +1204,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, | |
| DEBUGASSERT(ctx->sock == CURL_SOCKET_BAD); | |
| ctx->started_at = *Curl_pgrs_now(data); | |
| - | #ifdef SOCK_NONBLOCK |
| + | #ifdef CURL_USE_SOCK_NONBLOCK |
| /* Do not tuck SOCK_NONBLOCK into socktype when opensocket callback is set | |
| * because we would not know how socktype is about to be used in the | |
| * callback, SOCK_NONBLOCK might get factored out before calling socket(). | |
| @@ -1213,7 +1213,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, | |
| ctx->addr.socktype |= SOCK_NONBLOCK; | |
| #endif | |
| result = socket_open(data, &ctx->addr, &ctx->sock); | |
| - | #ifdef SOCK_NONBLOCK |
| + | #ifdef CURL_USE_SOCK_NONBLOCK |
| /* Restore the socktype after the socket is created. */ | |
| if(!data->set.fopensocket) | |
| ctx->addr.socktype &= ~SOCK_NONBLOCK; | |
| @@ -1314,7 +1314,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, | |
| } | |
| #endif | |
| - | #ifndef SOCK_NONBLOCK |
| + | #ifndef CURL_USE_SOCK_NONBLOCK |
| /* Set socket non-blocking, must be a non-blocking socket for | |
| * a non-blocking connect. */ | |
| error = curlx_nonblock(ctx->sock, TRUE); | |
| @@ -1621,6 +1621,12 @@ typedef struct sockaddr_un { | |
| __NetBSD_Version__ */ | |
| #endif | |
| + | /* NetBSD before 6.1 did not set SS_NBIO for SOCK_NONBLOCK. */ |
| + | #if defined(SOCK_NONBLOCK) && \ |
| + | (!defined(__NetBSD__) || (__NetBSD_Version__ >= 601000000)) |
| + | #define CURL_USE_SOCK_NONBLOCK |
| + | #endif |
| + | |
| #ifndef _CURL_LOCAL_MEMZERO /* to be removed after a couple of releases */ | |
| #ifdef _WIN32 | |
| #if defined(_MSC_VER) && defined(NTDDI_VERSION) && \ | |
| @@ -96,14 +96,14 @@ static int wakeup_socketpair(curl_socket_t socks[2], bool nonblocking) | |
| #ifdef SOCK_CLOEXEC | |
| type |= SOCK_CLOEXEC; | |
| #endif | |
| - | #ifdef SOCK_NONBLOCK |
| + | #ifdef CURL_USE_SOCK_NONBLOCK |
| if(nonblocking) | |
| type |= SOCK_NONBLOCK; | |
| #endif | |
| if(CURL_SOCKETPAIR(AF_UNIX, type, 0, socks)) | |
| return -1; | |
| - | #ifndef SOCK_NONBLOCK |
| + | #ifndef CURL_USE_SOCK_NONBLOCK |
| if(nonblocking) { | |
| if(curlx_nonblock(socks[0], TRUE) < 0 || | |
| curlx_nonblock(socks[1], TRUE) < 0) { | |
| @@ -34,13 +34,13 @@ static size_t t1662_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) | |
| struct t1662_WriteThis *pooh = (struct t1662_WriteThis *)userp; | |
| - | if(size * nmemb < testdatalen) |
| + | if(size * nmemb < 1) |
| return 0; | |
| if(pooh->sizeleft) { | |
| - | memcpy(ptr, testdata, testdatalen); |
| - | pooh->sizeleft = 0; |
| - | return testdatalen; |
| + | *ptr = testdata[testdatalen - pooh->sizeleft]; |
| + | --pooh->sizeleft; |
| + | return 1; |
| } | |
| return 0; /* no more data left to deliver */ | |
| @@ -52,7 +52,7 @@ static CURLcode test_lib1662(const char *URL) | |
| CURL *curl; | |
| curl_mime *mime1; | |
| curl_mimepart *part1; | |
| - | struct t1662_WriteThis pooh = { 1 }; |
| + | struct t1662_WriteThis pooh = { CURL_CSTRLEN("mooaaa") }; |
| mime1 = NULL; | |