status-im / nim-chronos

Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/
Apache License 2.0
362 stars 51 forks source link

Several changes mostly on windows platform #451

Closed radkesvat closed 1 year ago

radkesvat commented 1 year ago

Hi, thanks for this awesome and useful lib, which I have used to build my own project ReverseTlsTunnel

In this pull request I have done some small changes as I describe below:

First on Windows, ill allow the server sockets (both TCP/UDP) to be Dual-Stack Socket meaning that it can accept connections from ipv4 as well as ipv6, on a single ipv6 socket

This was the default on most Unix-like platforms, but not for windows, so I only made this change for windows by calling:

setSockOpt(serverSocket,osdefs.IPPROTO_IPV6,IPV6_V6ONLY,0)

Also note that I have added "IPPROTO_IPV6" definition to osdefs.nim (windows only) since it was required, with the value of 0x1b


The second change is to ignore the returned error code ERROR_NETNAME_DELETED in accept loop this is also a change only for the windows platform code.

In my project, I had a problem that the server was crashing with the error code

[64] The specified network name is no longer available.

The server could only work for maximum 3 to 5 minutes, and then it would crash with that error.

So I have done some research and the solution was to ignore that error and try to accept a new connection. More details are described here, in a cpython issue.

They had this problem as well and fixed it by ignoring it.

After adding this change, my program is working perfectly fine on Windows without crashing.

radkesvat commented 1 year ago

Oh, sorry i had a typo mistake looks like i pressed the wrong button before commiting and a extra ":" character was is stream.nim line 1897

cheatfate commented 1 year ago

Thank you very much for your help and investigation you have made, we can't accept your PR because we had different vision on dualstack abilities of chronos (which was already merged in #456) and i have replaced your fix for ERROR_NETNAME_DELETED in #460.

radkesvat commented 1 year ago

You’re Welcome