Why does windows need withSocketsDo?

和自甴很熟 提交于 2019-12-30 23:32:34

问题


In windows, sockets need to be initialized, as shown in Networks.

On Windows operating systems, the networking subsystem has to be initialised using withSocketsDo before any networking operations can be used. eg.

  main = withSocketsDo $ do {...}

Although this is only strictly necessary on Windows platforms, it is harmless on other platforms, so for portability it is good practice to use it all the time.

What's special about windows?


回答1:


In existing versions of the network library, withSocketsDo is used to initialize the Winsock library, which is only a requirement on Windows. On other platforms no library needs initializing, so withSocketsDo does nothing.

In future versions of the network library, withSocketsDo is called automatically, so only needs to be included for compatibility with older versions, see this blog post for the details behind the changes.




回答2:


Windows, unlike other platforms, requires processes to kickstart their network connectivity by manually initializing WinSock.dll. Meanwhile, Haskell, unlike other languages, by design does not have global mutable state. Thus, the WinSock initialization can't be hidden inside the load of a library or creation of some singleton object, and instead needs to be registered manually by an explicit call.



来源:https://stackoverflow.com/questions/22430686/why-does-windows-need-withsocketsdo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!