Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does windows need withSocketsDo?

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?

like image 373
MdxBhmt Avatar asked Dec 16 '22 00:12

MdxBhmt


2 Answers

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.

like image 114
Neil Mitchell Avatar answered Dec 17 '22 14:12

Neil Mitchell


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.

like image 40
sclv Avatar answered Dec 17 '22 13:12

sclv