mirror of
https://github.com/open-goal/jak-project
synced 2026-08-20 22:35:07 -04:00
5d5e35fb9b
## Problem Windows builds break with a current local toolchain (Scoop LLVM 22.1.8, CMake 4.4.0, VS 2026), in two independent ways: 1. The build stops at curl's deliberate guard: `#error "no non-blocking method was found/used/set"` in `third-party/curl/lib/nonblock.c`. 2. From the second configure onward, `cmake --build` re-runs CMake in an endless loop (observed 42 consecutive reconfigure cycles in a single build). Likely the same mechanism behind the "endlessly building" VS 2026 note in `docs/setup/dev/vs.md`. ## Root cause 1. `third-party/curl/CMake/CurlTests.c` passes `int *` to `ioctlsocket()`, whose third parameter is `u_long *`. Clang 22 promotes `-Wincompatible-pointer-types` to a hard error in C, so the `HAVE_IOCTLSOCKET_FIONBIO` try_compile silently fails and `curl_config.h` never defines it. Upstream CI does not see this because the windows-2022 runner image ships an older LLVM. GCC 14 promotes the same warning to a hard error, which is very likely the `CurlTests.c.obj` failure reported from MSYS2 in open-goal/jak-project#3551. Upstream curl hit the identical problem with GCC 14 and fixed the probe in curl 8.8.0 (curl/curl#13578). 2. The root CMakeLists copies the build tree's `compile_commands.json` into `<src>/build/` for clangd using `configure_file()`, which registers its input as a configure dependency. CMake rewrites `compile_commands.json` late in every generation, after `CTestTestfile.cmake` and `cmake_install.cmake` (outputs of the same Ninja regen rule), so once the dependency is registered the rule is deterministically dirty and every `ninja` invocation re-runs CMake. A pristine first configure is safe (the file does not exist yet, so the `if(EXISTS ...)` guard skips the copy), which is why the loop looks machine- or IDE-specific. ## Fix 1. Per review, re-vendor `third-party/curl` at the `curl-8_21_0` tag (previously `curl-8_3_0`), which carries the upstream probe fix plus two years of upstream development; `vendor.yaml` updated to match. Adjustments the version jump forced: - curl 8.15 removed the native macOS Secure Transport backend (`CURL_USE_SECTRANSP`), so macOS now builds curl against OpenSSL like Linux. The two macOS workflows install Homebrew `openssl@3` and export `OPENSSL_ROOT_DIR` (keg-only), and the macOS setup docs gained the same two lines. - `CURL_BROTLI` / `CURL_ZSTD` switched to AUTO-detection in curl 8.10; pinned OFF to keep the previous no-compression behavior and avoid silently linking whatever the CI images happen to have. - curl's new top-level `BUILD_EXAMPLES` cache option (default ON) leaked into discord-rpc's identically named option and broke configure at a nonexistent `examples/send-presence` directory; pinned OFF ahead of the third-party subdirectories. The diff is dominated by the mechanical tag-tree swap under `third-party/curl` (linguist-vendored, collapsed in review). The hand-written changes are `CMakeLists.txt`, the two macOS workflows, `docs/setup/system/macos.md`, and `vendor.yaml`. 2. Swap `configure_file()` for `file(COPY ...)`: the same clangd copy with no configure dependency registered. (`file(COPY_FILE ... ONLY_IF_DIFFERENT)` would be cleaner still but requires CMake 3.21, above the declared `cmake_minimum_required(VERSION 3.10)`.) ## Test plan - [x] Fresh `cmake --preset Release-windows-clang` (LLVM 22, no cache seeding) completes and logs `Enabled SSL backends: Schannel`; the FIONBIO probe passes without the previous `#error` - [x] Full Windows Release build from scratch in the branch worktree (all 1422 targets) - [x] goalc-test suite: 1509 passed, 0 failed - [x] Second consecutive configure with `compile_commands.json` present: the regen rule in `build.ninja` has no `compile_commands.json` input; `<src>/build/compile_commands.json` is still refreshed for clangd - [x] Repeated `ninja` invocations after a full build no longer re-run CMake - [x] macOS Intel and ARM CI green (first exercise of the OpenSSL backend switch) --- I work off a self-hosted forge, so this GitHub account is quiet; the configure logs and ninja dirty-node traces from the investigation are available if anyone wants the raw data. (AI-assisted)
413 lines
12 KiB
C
Vendored
Generated
413 lines
12 KiB
C
Vendored
Generated
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
* 'pingpong' is for generic back-and-forth support functions used by FTP,
|
|
* IMAP, POP3, SMTP and whatever more that likes them.
|
|
*
|
|
***************************************************************************/
|
|
#include "curl_setup.h"
|
|
|
|
#include "urldata.h"
|
|
#include "pingpong.h"
|
|
|
|
#ifdef USE_PINGPONG
|
|
|
|
#include "cfilters.h"
|
|
#include "connect.h"
|
|
#include "multiif.h"
|
|
#include "sendf.h"
|
|
#include "curl_trc.h"
|
|
#include "select.h"
|
|
#include "progress.h"
|
|
|
|
timediff_t Curl_pp_state_timeleft_ms(struct Curl_easy *data,
|
|
struct pingpong *pp)
|
|
{
|
|
timediff_t xfer_remain_ms;
|
|
timediff_t remain_ms = data->set.server_response_timeout ?
|
|
data->set.server_response_timeout : PINGPONG_TIMEOUT_MS;
|
|
|
|
/* If the overall transfer has less time remaining than pingpong
|
|
* has otherwise for the state, return that. */
|
|
remain_ms -= curlx_ptimediff_ms(Curl_pgrs_now(data), &pp->response);
|
|
/* transfer remaining time is 0, when it has no timeout. */
|
|
xfer_remain_ms = Curl_timeleft_ms(data);
|
|
if(xfer_remain_ms)
|
|
return CURLMIN(remain_ms, xfer_remain_ms);
|
|
return remain_ms;
|
|
}
|
|
|
|
/*
|
|
* Curl_pp_statemach()
|
|
*/
|
|
CURLcode Curl_pp_statemach(struct Curl_easy *data,
|
|
struct pingpong *pp, bool block,
|
|
bool disconnecting)
|
|
{
|
|
struct connectdata *conn = data->conn;
|
|
curl_socket_t sock = conn->sock[FIRSTSOCKET];
|
|
int rc;
|
|
timediff_t interval_ms;
|
|
timediff_t timeout_ms = Curl_pp_state_timeleft_ms(data, pp);
|
|
CURLcode result = CURLE_OK;
|
|
|
|
if(timeout_ms <= 0) {
|
|
failf(data, "server response timeout");
|
|
return CURLE_OPERATION_TIMEDOUT; /* already too little time */
|
|
}
|
|
|
|
if(block) {
|
|
interval_ms = 1000; /* use 1 second timeout intervals */
|
|
if(timeout_ms < interval_ms)
|
|
interval_ms = timeout_ms;
|
|
}
|
|
else
|
|
interval_ms = 0; /* immediate */
|
|
|
|
if(Curl_conn_data_pending(data, FIRSTSOCKET))
|
|
rc = 1;
|
|
else if(pp->overflow)
|
|
/* We are receiving and there is data in the cache so read it */
|
|
rc = 1;
|
|
else if(!pp->sendleft && Curl_conn_data_pending(data, FIRSTSOCKET))
|
|
/* We are receiving and there is data ready in the SSL library */
|
|
rc = 1;
|
|
else {
|
|
rc = Curl_socket_check(pp->sendleft ? CURL_SOCKET_BAD : sock, /* reading */
|
|
CURL_SOCKET_BAD,
|
|
pp->sendleft ? sock : CURL_SOCKET_BAD, /* writing */
|
|
interval_ms);
|
|
}
|
|
|
|
if(block) {
|
|
/* if we did not wait, we do not have to spend time on this now */
|
|
result = Curl_pgrsCheck(data);
|
|
if(result)
|
|
return result;
|
|
}
|
|
|
|
if(rc == -1) {
|
|
failf(data, "select/poll error");
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
}
|
|
else if(rc)
|
|
result = pp->statemachine(data, data->conn);
|
|
else if(disconnecting)
|
|
return CURLE_OPERATION_TIMEDOUT;
|
|
|
|
return result;
|
|
}
|
|
|
|
/* initialize stuff to prepare for reading a fresh new response */
|
|
void Curl_pp_init(struct pingpong *pp, const struct curltime *pnow)
|
|
{
|
|
DEBUGASSERT(!pp->initialized);
|
|
pp->nread_resp = 0;
|
|
pp->response = *pnow; /* start response time-out */
|
|
pp->pending_resp = TRUE;
|
|
curlx_dyn_init(&pp->sendbuf, DYN_PINGPPONG_CMD);
|
|
curlx_dyn_init(&pp->recvbuf, DYN_PINGPPONG_CMD);
|
|
pp->initialized = TRUE;
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* Curl_pp_vsendf()
|
|
*
|
|
* Send the formatted string as a command to a pingpong server. Note that
|
|
* the string should not have any CRLF appended, as this function will
|
|
* append the necessary things itself.
|
|
*
|
|
* made to never block
|
|
*/
|
|
CURLcode Curl_pp_vsendf(struct Curl_easy *data,
|
|
struct pingpong *pp,
|
|
const char *fmt,
|
|
va_list args)
|
|
{
|
|
size_t bytes_written = 0;
|
|
size_t write_len;
|
|
char *s;
|
|
CURLcode result;
|
|
struct connectdata *conn = data->conn;
|
|
|
|
DEBUGASSERT(pp->sendleft == 0);
|
|
DEBUGASSERT(pp->sendsize == 0);
|
|
DEBUGASSERT(!pp->sendthis);
|
|
|
|
if(!conn)
|
|
/* cannot send without a connection! */
|
|
return CURLE_SEND_ERROR;
|
|
|
|
curlx_dyn_reset(&pp->sendbuf);
|
|
result = curlx_dyn_vaddf(&pp->sendbuf, fmt, args);
|
|
if(result)
|
|
return result;
|
|
|
|
/* append CRLF */
|
|
result = curlx_dyn_addn(&pp->sendbuf, "\r\n", 2);
|
|
if(result)
|
|
return result;
|
|
|
|
pp->pending_resp = TRUE;
|
|
write_len = curlx_dyn_len(&pp->sendbuf);
|
|
s = curlx_dyn_ptr(&pp->sendbuf);
|
|
|
|
result = Curl_conn_send(data, FIRSTSOCKET, s, write_len, FALSE,
|
|
&bytes_written);
|
|
if(result == CURLE_AGAIN) {
|
|
bytes_written = 0;
|
|
}
|
|
else if(result)
|
|
return result;
|
|
|
|
Curl_debug(data, CURLINFO_HEADER_OUT, s, bytes_written);
|
|
|
|
if(bytes_written != write_len) {
|
|
/* the whole chunk was not sent, keep it around and adjust sizes */
|
|
pp->sendthis = s;
|
|
pp->sendsize = write_len;
|
|
pp->sendleft = write_len - bytes_written;
|
|
}
|
|
else {
|
|
pp->sendthis = NULL;
|
|
pp->sendleft = pp->sendsize = 0;
|
|
pp->response = *Curl_pgrs_now(data);
|
|
}
|
|
|
|
return CURLE_OK;
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* Curl_pp_sendf()
|
|
*
|
|
* Send the formatted string as a command to a pingpong server. Note that
|
|
* the string should not have any CRLF appended, as this function will
|
|
* append the necessary things itself.
|
|
*
|
|
* made to never block
|
|
*/
|
|
CURLcode Curl_pp_sendf(struct Curl_easy *data, struct pingpong *pp,
|
|
const char *fmt, ...)
|
|
{
|
|
CURLcode result;
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
|
|
result = Curl_pp_vsendf(data, pp, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return result;
|
|
}
|
|
|
|
static CURLcode pingpong_read(struct Curl_easy *data,
|
|
int sockindex,
|
|
char *buffer,
|
|
size_t buflen,
|
|
size_t *nread)
|
|
{
|
|
return Curl_conn_recv(data, sockindex, buffer, buflen, nread);
|
|
}
|
|
|
|
/*
|
|
* Curl_pp_readresp()
|
|
*
|
|
* Reads a piece of a server response.
|
|
*/
|
|
CURLcode Curl_pp_readresp(struct Curl_easy *data,
|
|
int sockindex,
|
|
struct pingpong *pp,
|
|
int *code, /* return the server code if done */
|
|
size_t *size) /* size of the response */
|
|
{
|
|
struct connectdata *conn = data->conn;
|
|
CURLcode result = CURLE_OK;
|
|
size_t gotbytes;
|
|
char buffer[900];
|
|
|
|
*code = 0; /* 0 for errors or not done */
|
|
*size = 0;
|
|
|
|
do {
|
|
gotbytes = 0;
|
|
if(pp->nfinal) {
|
|
/* a previous call left this many bytes in the beginning of the buffer as
|
|
that was the final line; now ditch that */
|
|
size_t full = curlx_dyn_len(&pp->recvbuf);
|
|
|
|
/* trim off the "final" leading part */
|
|
curlx_dyn_tail(&pp->recvbuf, full - pp->nfinal);
|
|
|
|
pp->nfinal = 0; /* now gone */
|
|
}
|
|
if(!pp->overflow) {
|
|
result = pingpong_read(data, sockindex, buffer, sizeof(buffer),
|
|
&gotbytes);
|
|
if(result == CURLE_AGAIN)
|
|
return CURLE_OK;
|
|
|
|
if(result)
|
|
return result;
|
|
|
|
if(!gotbytes) {
|
|
failf(data, "response reading failed (errno: %d)", SOCKERRNO);
|
|
return CURLE_RECV_ERROR;
|
|
}
|
|
|
|
result = curlx_dyn_addn(&pp->recvbuf, buffer, gotbytes);
|
|
if(result)
|
|
return result;
|
|
|
|
data->req.headerbytecount += (unsigned int)gotbytes;
|
|
|
|
pp->nread_resp += gotbytes;
|
|
}
|
|
|
|
do {
|
|
const char *line = curlx_dyn_ptr(&pp->recvbuf);
|
|
const char *nl = memchr(line, '\n', curlx_dyn_len(&pp->recvbuf));
|
|
if(nl) {
|
|
/* a newline is CRLF in pp-talk, so the CR is ignored as
|
|
the line is not really terminated until the LF comes */
|
|
size_t length = nl - line + 1;
|
|
|
|
if(memchr(line, 0, length)) {
|
|
/* The response line is passed on as a "header" below, so reject an
|
|
embedded nul the same way verify_header() does for HTTP. */
|
|
failf(data, "Nul byte in server response line");
|
|
return CURLE_WEIRD_SERVER_REPLY;
|
|
}
|
|
|
|
/* output debug output if that is requested */
|
|
Curl_debug(data, CURLINFO_HEADER_IN, line, length);
|
|
|
|
/*
|
|
* Pass all response-lines to the callback function registered for
|
|
* "headers". The response lines can be seen as a kind of headers.
|
|
*/
|
|
result = Curl_client_write(data, CLIENTWRITE_INFO, line, length);
|
|
if(result)
|
|
return result;
|
|
|
|
if(pp->endofresp(data, conn, line, length, code)) {
|
|
/* When at "end of response", keep the endofresp line first in the
|
|
buffer since it will be accessed outside (by pingpong
|
|
parsers). Store the overflow counter to inform about additional
|
|
data in this buffer after the endofresp line. */
|
|
pp->nfinal = length;
|
|
if(curlx_dyn_len(&pp->recvbuf) > length)
|
|
pp->overflow = curlx_dyn_len(&pp->recvbuf) - length;
|
|
else
|
|
pp->overflow = 0;
|
|
*size = pp->nread_resp; /* size of the response */
|
|
pp->nread_resp = 0; /* restart */
|
|
gotbytes = 0; /* force break out of outer loop */
|
|
break;
|
|
}
|
|
if(curlx_dyn_len(&pp->recvbuf) > length)
|
|
/* keep the remaining piece */
|
|
curlx_dyn_tail((&pp->recvbuf), curlx_dyn_len(&pp->recvbuf) - length);
|
|
else
|
|
curlx_dyn_reset(&pp->recvbuf);
|
|
}
|
|
else {
|
|
/* without a newline, there is no overflow */
|
|
pp->overflow = 0;
|
|
break;
|
|
}
|
|
|
|
} while(1); /* while there is buffer left to scan */
|
|
|
|
} while(gotbytes == sizeof(buffer));
|
|
|
|
pp->pending_resp = FALSE;
|
|
|
|
return result;
|
|
}
|
|
|
|
CURLcode Curl_pp_pollset(struct Curl_easy *data,
|
|
struct pingpong *pp,
|
|
struct easy_pollset *ps)
|
|
{
|
|
int flags = pp->sendleft ? CURL_POLL_OUT : CURL_POLL_IN;
|
|
return Curl_pollset_change(data, ps, data->conn->sock[FIRSTSOCKET],
|
|
flags, 0);
|
|
}
|
|
|
|
bool Curl_pp_needs_flush(struct Curl_easy *data,
|
|
struct pingpong *pp)
|
|
{
|
|
(void)data;
|
|
return pp->sendleft > 0;
|
|
}
|
|
|
|
CURLcode Curl_pp_flushsend(struct Curl_easy *data,
|
|
struct pingpong *pp)
|
|
{
|
|
/* we have a piece of a command still left to send */
|
|
size_t written;
|
|
CURLcode result;
|
|
|
|
if(!Curl_pp_needs_flush(data, pp))
|
|
return CURLE_OK;
|
|
|
|
result = Curl_conn_send(data, FIRSTSOCKET,
|
|
pp->sendthis + pp->sendsize - pp->sendleft,
|
|
pp->sendleft, FALSE, &written);
|
|
if(result == CURLE_AGAIN) {
|
|
result = CURLE_OK;
|
|
written = 0;
|
|
}
|
|
if(result)
|
|
return result;
|
|
|
|
if(written != pp->sendleft) {
|
|
/* only a fraction was sent */
|
|
pp->sendleft -= written;
|
|
}
|
|
else {
|
|
pp->sendthis = NULL;
|
|
pp->sendleft = pp->sendsize = 0;
|
|
pp->response = *Curl_pgrs_now(data);
|
|
}
|
|
return CURLE_OK;
|
|
}
|
|
|
|
CURLcode Curl_pp_disconnect(struct pingpong *pp)
|
|
{
|
|
if(pp->initialized) {
|
|
curlx_dyn_free(&pp->sendbuf);
|
|
curlx_dyn_free(&pp->recvbuf);
|
|
memset(pp, 0, sizeof(*pp));
|
|
}
|
|
return CURLE_OK;
|
|
}
|
|
|
|
bool Curl_pp_moredata(struct pingpong *pp)
|
|
{
|
|
return !pp->sendleft && curlx_dyn_len(&pp->recvbuf) > pp->nfinal;
|
|
}
|
|
|
|
#endif
|