The MSVC UWP job in CI did not actually enable UWP. Fix this and
the fallouts discovered after enabling it.
- GHA/windows: make sure to enable UWP in MSVC vcpkg UWP job.
Use the CMake options and C flags already used for mingw-w64, but use
`WINAPI_FAMILY_PC_APP` instead of the deprecated `WINAPI_FAMILY_APP`.
(The former is not supported by mingw-w64, so leave it there as-is.)
Follow-up to cb22cfca69 #14077
- GHA/windows: by default the MSVC UWP job became 2x-3x slower than
others after actually enabling UWP. Most of it is caused by
CMake/MSBuild automatically building full APPX containers for each
`.exe` target. This includes 21 CMake feature detections. Each
detection app is built into a 15MB APPX project, with code signing,
logos, etc. Example:
https://github.com/curl/curl/actions/runs/12056968170/job/33620610958
Disable this overhead for curl build targets via custom
`CMAKE_VS_GLOBALS` options. I've found no way to apply them to feature
detection targets, so those remain slow.
- cmake: automatically enable Unicode for UWP builds. It's required.
Also stop enabling it manually in the existing CI job.
- tests: fix `getpid()` use for Windows UWP:
```
tests\server\util.c(281,21): warning C4013: 'getpid' undefined; assuming extern returning int
```
Ref: https://github.com/curl/curl/actions/runs/12061215311/job/33632904249#step:11:38
- src/tool_doswin: disable `GetLoadedModulePaths()` for UWP.
mingw-w64 UWP was okay with this, but MS SDK headers are not.
This makes `--dump-module-paths` return empty for UWP builds.
```
src\tool_doswin.c(620,3): error C2065: 'MODULEENTRY32': undeclared identifier
src\tool_doswin.c(626,11): warning C4013: 'CreateToolhelp32Snapshot' undefined; assuming extern returning int
src\tool_doswin.c(626,36): error C2065: 'TH32CS_SNAPMODULE': undeclared identifier
src\tool_doswin.c(632,7): warning C4013: 'Module32First' undefined; assuming extern returning int
```
Ref: https://github.com/curl/curl/actions/runs/12055081933/job/33614629930#step:9:35
- examples: fix `websocket.c` to include `winsock2.h` before `windows.h`
to make it build with MSVC UWP:
```
include\curl\curl.h(143,16): error C2061: syntax error: identifier 'curl_socket_t'
include\curl\curl.h(143,16): error C2059: syntax error: ';'
include\curl\curl.h(417,52): error C2146: syntax error: missing ')' before identifier 'curlfd'
include\curl\curl.h(417,38): error C2081: 'curl_socket_t': name in formal parameter list illegal
```
Ref: https://github.com/curl/curl/actions/runs/12055317910/job/33615644427#step:14:126
- GHA/windows: silence linker warning with MSVC UWP builds:
```
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification
```
Ref: https://github.com/curl/curl/actions/runs/12055696808/job/33616629610#step:11:38
- GHA/windows: set `/INCREMENTAL:NO` for all MSVC jobs to improve
performance a little.
- cmake: show `UWP` platform flag.
Ref: #15652
Closes #15657
136 lines
3.5 KiB
C
136 lines
3.5 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* 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
|
|
*
|
|
***************************************************************************/
|
|
/* <DESC>
|
|
* WebSocket using CONNECT_ONLY
|
|
* </DESC>
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#ifdef _WIN32
|
|
#include <winsock2.h>
|
|
#include <windows.h>
|
|
#define sleep(s) Sleep((DWORD)(s))
|
|
#else
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include <curl/curl.h>
|
|
|
|
static int ping(CURL *curl, const char *send_payload)
|
|
{
|
|
size_t sent;
|
|
CURLcode result =
|
|
curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0,
|
|
CURLWS_PING);
|
|
return (int)result;
|
|
}
|
|
|
|
static int recv_pong(CURL *curl, const char *expected_payload)
|
|
{
|
|
size_t rlen;
|
|
const struct curl_ws_frame *meta;
|
|
char buffer[256];
|
|
CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
|
|
if(!result) {
|
|
if(meta->flags & CURLWS_PONG) {
|
|
int same = 0;
|
|
fprintf(stderr, "ws: got PONG back\n");
|
|
if(rlen == strlen(expected_payload)) {
|
|
if(!memcmp(expected_payload, buffer, rlen)) {
|
|
fprintf(stderr, "ws: got the same payload back\n");
|
|
same = 1;
|
|
}
|
|
}
|
|
if(!same)
|
|
fprintf(stderr, "ws: did NOT get the same payload back\n");
|
|
}
|
|
else {
|
|
fprintf(stderr, "recv_pong: got %u bytes rflags %x\n", (int)rlen,
|
|
meta->flags);
|
|
}
|
|
}
|
|
fprintf(stderr, "ws: curl_ws_recv returned %u, received %u\n",
|
|
(unsigned int)result, (unsigned int)rlen);
|
|
return (int)result;
|
|
}
|
|
|
|
static CURLcode recv_any(CURL *curl)
|
|
{
|
|
size_t rlen;
|
|
const struct curl_ws_frame *meta;
|
|
char buffer[256];
|
|
|
|
return curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
|
|
}
|
|
|
|
/* close the connection */
|
|
static void websocket_close(CURL *curl)
|
|
{
|
|
size_t sent;
|
|
(void)curl_ws_send(curl, "", 0, &sent, 0, CURLWS_CLOSE);
|
|
}
|
|
|
|
static void websocket(CURL *curl)
|
|
{
|
|
int i = 0;
|
|
do {
|
|
recv_any(curl);
|
|
if(ping(curl, "foobar"))
|
|
return;
|
|
if(recv_pong(curl, "foobar")) {
|
|
return;
|
|
}
|
|
sleep(2);
|
|
} while(i++ < 10);
|
|
websocket_close(curl);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
CURL *curl;
|
|
CURLcode res;
|
|
|
|
curl = curl_easy_init();
|
|
if(curl) {
|
|
curl_easy_setopt(curl, CURLOPT_URL, "wss://example.com");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */
|
|
|
|
/* Perform the request, res gets the return code */
|
|
res = curl_easy_perform(curl);
|
|
/* Check for errors */
|
|
if(res != CURLE_OK)
|
|
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
|
curl_easy_strerror(res));
|
|
else {
|
|
/* connected and ready */
|
|
websocket(curl);
|
|
}
|
|
|
|
/* always cleanup */
|
|
curl_easy_cleanup(curl);
|
|
}
|
|
return 0;
|
|
}
|