How to handle "Errorkind::Uncategorized" io error

In a program of mine, reading a TCP socket on Windows returns WSA_IO_PENDING, which is mapped to Uncategorized by the Windows implementation of Rust (see here). However, ErrorKind::Uncategorized is hidden in the docs, and it is explicitly stated that It is not recommended to match an error against "Uncategorized"; use a wildcard match ("_") instead (see here). However, I'm under the impression that WSA_IO_PENDING is a recoverable error and it should be fine to call read on the socket again. My question is, how I should handle this case, seeing that it is explicitly discouraged to match this error kind?

Please do note that I'm not an expert on Windows Sockets and my experience is limited. The current behavior of the my program is to drop the socket and create a new one, which I feel is unnecessary in this case.

Thanks a lot in advance.

raw_os_error and a crate that gives you the WSA_IO_PENDING definition may be an option (but this is a guess on my part so take it accordingly).

3 Likes

Make a pull request to the standard library adding some specific kind of error for this error code.

1 Like

I thought about doing that. I just might. Thanks for your reply.

I have since found a similar workaround that uses something like
(cfg!(windows) && e.raw_os_error() == Some(997)) to handle the error. I will use a similar approach for the time being. Thank you.

1 Like