`<system_error>`: `system_category()` maps `WSAECONNREFUSED` etc. onto `errc`, but not their `winerror.h` equivalents (`ERROR_CONNECTION_REFUSED`, `ERROR_NETNAME_DELETED`, ...)

オープン 初心者向け
#6,471 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp

調査の方向性

stl/src/syserror.cpp から始め、Winsock コードを移植可能な errc 条件にマッピングする _Win_errtab エントリを調べます。記載されている 7 つの winerror.h コードのカバレッジを追加し、その後 repro.cpp のチェックまたは関連する STL エラーシステムのテストを実行して、13 個すべての比較が true を報告することを確認します。

索引モデルが issue の本文から書いたものです。

説明

enhancement

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_connect maps ERROR_CONNECTION_REFUSED, ERROR_NETWORK_UNREACHABLE and ERROR_HOST_UNREACHABLE;
    complete_iocp_recv and recv map ERROR_NETNAME_DELETED -> connection_reset (and recv,
    ERROR_PORT_UNREACHABLE -> connection_refused). (complete_iocp_accept maps ERROR_NETNAME_DELETED to
    connection_aborted instead - for a connection reset before it was accepted - but connection_reset is what it
    means on an established connection, and what WSAECONNRESET already maps to.)
  • The same kind of gap as #2572 (WAIT_TIMEOUT vs errc::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時間
マージ済み PR(30日)
14

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/STL のほかの issue

microsoft/STL の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。