tool_doswin: avoid Windowsisms in socket code (cont.)

For general readability. Also to match the rest of the source code.

- bump `send()` result type from `int` to `ssize_t`.
- fix an `int` to be `curl_socklen_t`.
- `.S_un.S_addr` -> `.s_addr`.
- `SD_RECEIVE` -> `SHUT_RD`.
- `SD_SEND` -> `SHUT_WR`.

Follow-up to a81ab3e6db #20452
Follow-up to 9a2663322c #17572

Closes #20457
This commit is contained in:
Viktor Szakats 2026-01-28 00:46:37 +01:00
parent fb44e44d92
commit a4e2232c43
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201

View file

@ -708,7 +708,7 @@ static DWORD WINAPI win_stdin_thread_func(void *thread_data)
{
struct win_thread_data *tdata = (struct win_thread_data *)thread_data;
DWORD n;
int nwritten;
ssize_t nwritten;
char buffer[BUFSIZ];
BOOL r;
@ -726,7 +726,7 @@ static DWORD WINAPI win_stdin_thread_func(void *thread_data)
sclose(tdata->socket_l);
tdata->socket_l = CURL_SOCKET_BAD;
if(shutdown(socket_w, SD_RECEIVE)) {
if(shutdown(socket_w, SHUT_RD)) {
errorf("shutdown error: %d", SOCKERRNO);
goto ThreadCleanup;
}
@ -760,7 +760,8 @@ ThreadCleanup:
curl_socket_t win32_stdin_read_thread(void)
{
bool r;
int rc = 0, socksize = 0;
int rc = 0;
curl_socklen_t socksize = 0;
struct win_thread_data *tdata = NULL;
struct sockaddr_in selfaddr;
static HANDLE stdin_thread = NULL;
@ -791,7 +792,7 @@ curl_socket_t win32_stdin_read_thread(void)
socksize = sizeof(selfaddr);
memset(&selfaddr, 0, socksize);
selfaddr.sin_family = AF_INET;
selfaddr.sin_addr.S_un.S_addr = htonl(INADDR_LOOPBACK);
selfaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
/* Bind to any available loopback port */
if(bind(tdata->socket_l, (const struct sockaddr *)&selfaddr, socksize)) {
errorf("bind error: %d", SOCKERRNO);
@ -846,7 +847,7 @@ curl_socket_t win32_stdin_read_thread(void)
break;
}
if(shutdown(socket_r, SD_SEND)) {
if(shutdown(socket_r, SHUT_WR)) {
errorf("shutdown error: %d", SOCKERRNO);
break;
}