`<system_error>`: `system_category()` maps `WSAECONNREFUSED` etc. onto `errc`, but not their `winerror.h` equivalents (`ERROR_CONNECTION_REFUSED`, `ERROR_NETNAME_DELETED`, ...)
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- cpp
调研方向
从 stl/src/syserror.cpp 开始,检查将 Winsock 代码映射到可移植 errc 条件的 _Win_errtab 条目。为列出的七个 winerror.h 代码添加覆盖,然后运行 repro.cpp 检查或相关的 STL 错误系统测试,并验证全部 13 个比较都报告 true。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
system_category().default_error_condition() maps the Winsock network error codes onto the portable errc
conditions, but not the winerror.h codes that Windows reports for the same failures. So whether
ec == errc::connection_refused holds for a refused connection depends on which API reported it.
The winerror.h codes are what overlapped I/O completions report: GetOverlappedResult /
GetQueuedCompletionStatus translate the NTSTATUS with the usual NTSTATUS-to-Win32 mapping, so a
ConnectEx to a closed port completes with ERROR_CONNECTION_REFUSED (not WSAECONNREFUSED), and a
reset connection completes a WSARecv with ERROR_NETNAME_DELETED (not WSAECONNRESET).
Missing from _Win_errtab (checked against main, stl/src/syserror.cpp):
winerror.h code |
Winsock equivalent, already mapped | condition |
|---|---|---|
ERROR_CONNECTION_REFUSED (1225) |
WSAECONNREFUSED |
connection_refused |
ERROR_PORT_UNREACHABLE (1234) |
WSAECONNREFUSED |
connection_refused |
ERROR_NETWORK_UNREACHABLE (1231) |
WSAENETUNREACH |
network_unreachable |
ERROR_HOST_UNREACHABLE (1232) |
WSAEHOSTUNREACH |
host_unreachable |
ERROR_CONNECTION_ABORTED (1236) |
WSAECONNABORTED |
connection_aborted |
ERROR_NETNAME_DELETED (64) |
WSAECONNRESET |
connection_reset |
ERROR_CANCELLED (1223) |
(ERROR_OPERATION_ABORTED) |
operation_canceled |
Command-line test case
C:\Temp>type repro.cpp
#include <winsock2.h>
#include <windows.h>
#include <cstdio>
#include <system_error>
using namespace std;
void check(const char* name, int ev, const char* condName, errc cond) {
printf("%-25s (%5d) == errc::%-19s : %s\n", name, ev, condName,
error_code{ev, system_category()} == cond ? "true" : "false");
}
#define CHECK(ev, cond) check(#ev, ev, #cond, errc::cond)
int main() {
CHECK(WSAECONNREFUSED, connection_refused);
CHECK(ERROR_CONNECTION_REFUSED, connection_refused);
CHECK(ERROR_PORT_UNREACHABLE, connection_refused);
CHECK(WSAENETUNREACH, network_unreachable);
CHECK(ERROR_NETWORK_UNREACHABLE, network_unreachable);
CHECK(WSAEHOSTUNREACH, host_unreachable);
CHECK(ERROR_HOST_UNREACHABLE, host_unreachable);
CHECK(WSAECONNABORTED, connection_aborted);
CHECK(ERROR_CONNECTION_ABORTED, connection_aborted);
CHECK(WSAECONNRESET, connection_reset);
CHECK(ERROR_NETNAME_DELETED, connection_reset);
CHECK(ERROR_OPERATION_ABORTED, operation_canceled);
CHECK(ERROR_CANCELLED, operation_canceled);
}
C:\Temp>cl /EHsc /W4 /WX /std:c++latest repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36260 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.
repro.cpp
Microsoft (R) Incremental Linker Version 14.51.36260.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
C:\Temp>repro.exe
WSAECONNREFUSED (10061) == errc::connection_refused : true
ERROR_CONNECTION_REFUSED ( 1225) == errc::connection_refused : false
ERROR_PORT_UNREACHABLE ( 1234) == errc::connection_refused : false
WSAENETUNREACH (10051) == errc::network_unreachable : true
ERROR_NETWORK_UNREACHABLE ( 1231) == errc::network_unreachable : false
WSAEHOSTUNREACH (10065) == errc::host_unreachable : true
ERROR_HOST_UNREACHABLE ( 1232) == errc::host_unreachable : false
WSAECONNABORTED (10053) == errc::connection_aborted : true
ERROR_CONNECTION_ABORTED ( 1236) == errc::connection_aborted : false
WSAECONNRESET (10054) == errc::connection_reset : true
ERROR_NETNAME_DELETED ( 64) == errc::connection_reset : false
ERROR_OPERATION_ABORTED ( 995) == errc::operation_canceled : true
ERROR_CANCELLED ( 1223) == errc::operation_canceled : false
Expected behavior
Each winerror.h code compares equal to the same errc condition as its Winsock equivalent - all 13 lines true.
STL version
Microsoft Visual Studio Community 2026
Version 18.10.3
Also reproduced with VS 2022 17.14 (MSVC 14.44.35207). stl/src/syserror.cpp on main has none of these
seven codes.
Additional context
- Boost.Asio works around exactly this, translating these codes by hand before reporting them
(socket_ops.ipp):
complete_iocp_connectmapsERROR_CONNECTION_REFUSED,ERROR_NETWORK_UNREACHABLEandERROR_HOST_UNREACHABLE;
complete_iocp_recvandrecvmapERROR_NETNAME_DELETED->connection_reset(andrecv,
ERROR_PORT_UNREACHABLE->connection_refused). (complete_iocp_acceptmapsERROR_NETNAME_DELETEDto
connection_abortedinstead - for a connection reset before it was accepted - butconnection_resetis what it
means on an established connection, and whatWSAECONNRESETalready maps to.) - The same kind of gap as #2572 (
WAIT_TIMEOUTvserrc::timed_out), fixed by #2744. - We hit this in Stroika, and now map these codes ourselves:
https://github.com/SophistSolutions/Stroika/issues/1192
- 主要语言
- C++
- 星标
- 11.2k
- 派生
- 1.7k
- 平均合并
- 4 天 4 小时
- 30 天内合并 PR
- 14
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/STL 的其他 Issue
-
LWG
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 2 天内回复
-
generator LWG
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
LWG
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
`<__msvc_math.hpp>`: `_USE_MATH_DEFINES` is ignored after the first `<math.h>` include under `/Zc:cmath`可能已有人在做 @tiagomacarios 于 10 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
LWG
难度 4/5 3-5 天 新手友好度 38/100
维护者通常 2 天内回复
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 76/100
ionut-mihalache/aqua#31 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
needs-kind
难度 2/5 1-3 小时 新手友好度 63/100
villagesql/villagesql-server#1702 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/vcpkg-tool#2191 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
harfbuzz/harfbuzz#6966 · 1 条评论 ·
维护者通常 1 天内回复