fixup: remove win, return ENOSYS

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
This commit is contained in:
Juan José Arboleda 2026-01-30 20:16:38 -05:00
parent 4aba788094
commit 7a6d93159b
3 changed files with 28 additions and 40 deletions

View File

@ -196,8 +196,7 @@ if(WIN32)
ws2_32
dbghelp
ole32
shell32
qwave)
shell32)
list(APPEND uv_sources
src/win/async.c
src/win/core.c

View File

@ -32,8 +32,6 @@
#if defined(_WIN32)
# include <malloc.h> /* malloc */
# include <qos2.h>
# include <winsock.h>
#else
# include <net/if.h> /* if_nametoindex */
# include <sys/un.h> /* AF_UNIX, sockaddr_un */
@ -1075,6 +1073,10 @@ int uv_socket_get_tos(const uv_handle_t* handle, int* tos) {
socklen_t optlen;
struct sockaddr_storage storage;
#if defined(_WIN32)
return UV_ENOSYS;
#endif
addrlen = sizeof(storage);
tos_ = 0;
optlen = sizeof(tos_);
@ -1114,11 +1116,7 @@ int uv_socket_get_tos(const uv_handle_t* handle, int* tos) {
return UV_EAFNOSUPPORT;
}
#if defined(_WIN32)
r = getsockopt(fd, level, option, (char*)&tos_, &optlen);
#else
r = getsockopt(fd, level, option, &tos_, &optlen);
#endif
if (r)
return r;
@ -1135,6 +1133,10 @@ int uv_socket_set_tos(const uv_handle_t* handle, int tos) {
int level;
int option;
#if defined(_WIN32)
return UV_ENOSYS;
#endif
addrlen = sizeof(storage);
if (tos < 0 || tos > 255)
@ -1171,37 +1173,6 @@ int uv_socket_set_tos(const uv_handle_t* handle, int tos) {
return UV_EAFNOSUPPORT;
}
#ifndef _WIN32
r = setsockopt(fd, level, option, &tos, sizeof(tos));
return UV__ERR(r);
#else
HANDLE qosHandle = NULL;
QOS_VERSION version = {1, 0};
QOS_FLOWID flowId = 0;
DWORD dscpValue = (DWORD)tos;
SOCKET socket = (SOCKET)fd;
/* NOTE: I'm using setsockopt here to set the TOS value directly on the socket as UNIX.
* I'm not too worried about this one, let's use the QOS API as a backup plan.
*/
setsockopt(fd, level, option, (char*)&tos, sizeof(tos));
if (storage.ss_family == AF_UNSPEC) {
/* Can't set DSCP on an unspecified address */
return UV_ENOTCONN;
}
/* Do the same thing using QOS APIs just to be sure */
if (QOSCreateHandle(&version, &qosHandle)) {
if(QOSAddSocketToFlow(qosHandle, socket, NULL, QOSTrafficTypeBestEffort, 0, &flowId)) {
QOSSetFlow(qosHandle, flowId, QOSSetOutgoingDSCPValue, sizeof(dscpValue), &dscpValue, 0, NULL);
} else {
int err = WSAGetLastError();
printf("QOSAddSocketToFlow failed with error: %d\n", err);
}
QOSCloseHandle(qosHandle);
return 0;
}
#endif
return 0;
}

View File

@ -19,8 +19,8 @@
* IN THE SOFTWARE.
*/
#include "task.h"
#include "uv.h"
#include "task.h"
static void setup_tcp(uv_loop_t* loop, uv_tcp_t* tcp, const char* ip,
int is_ip6) {
@ -86,6 +86,9 @@ static void check_tos_fail(uv_handle_t* handle, int tos) {
}
TEST_IMPL(tcp_socket_set_get_tos) {
#if defined(_WIN32)
RETURN_SKIP("Windows does not support setting TOS");
#endif
uv_tcp_t tcp;
setup_tcp(uv_default_loop(), &tcp, "0.0.0.0", 0);
@ -106,6 +109,9 @@ TEST_IMPL(tcp_socket_set_get_tos) {
}
TEST_IMPL(tcp6_socket_set_get_tos) {
#if defined(_WIN32)
RETURN_SKIP("Windows does not support setting TOS");
#endif
uv_tcp_t tcp;
setup_tcp(uv_default_loop(), &tcp, "::1", 1);
@ -122,6 +128,9 @@ TEST_IMPL(tcp6_socket_set_get_tos) {
}
TEST_IMPL(udp_socket_set_get_tos) {
#if defined(_WIN32)
RETURN_SKIP("Windows does not support setting TOS");
#endif
uv_udp_t udp;
setup_udp(uv_default_loop(), &udp, "0.0.0.0", 0);
@ -141,6 +150,9 @@ TEST_IMPL(udp_socket_set_get_tos) {
}
TEST_IMPL(udp6_socket_set_get_tos) {
#if defined(_WIN32)
RETURN_SKIP("Windows does not support setting TOS");
#endif
uv_udp_t udp;
setup_udp(uv_default_loop(), &udp, "::1", 1);
@ -157,6 +169,9 @@ TEST_IMPL(udp6_socket_set_get_tos) {
}
TEST_IMPL(socket_tos_invalid_handle) {
#if defined(_WIN32)
RETURN_SKIP("Windows does not support setting TOS");
#endif
uv_timer_t timer;
int r;
int tos;
@ -181,6 +196,9 @@ TEST_IMPL(socket_tos_invalid_handle) {
}
TEST_IMPL(socket_tos_unbound_tcp) {
#if defined(_WIN32)
RETURN_SKIP("Windows does not support setting TOS on UDP sockets");
#endif
uv_tcp_t tcp;
int r;
int tos;