Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Network/Socket/Cbits.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ wsaEHOSTUNREACH :: CInt
wsaEHOSTUNREACH = #const WSAEHOSTUNREACH
wsaENOPROTOOPT :: CInt
wsaENOPROTOOPT = #const WSAENOPROTOOPT
fileSkipCompletionPortOnSuccess :: Word8
fileSkipCompletionPortOnSuccess = #const FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
#else
fGetFd :: CInt
fGetFd = #const F_GETFD
Expand Down
19 changes: 17 additions & 2 deletions Network/Socket/Syscall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import System.IO.Error (catchIOError)

#if defined(mingw32_HOST_OS)
import Foreign (FunPtr)

Check warning on line 13 in Network/Socket/Syscall.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.14)

The import of ‘Foreign’ is redundant

Check warning on line 13 in Network/Socket/Syscall.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.14)

The import of ‘Foreign’ is redundant

Check warning on line 13 in Network/Socket/Syscall.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.14)

The import of ‘Foreign’ is redundant

Check warning on line 13 in Network/Socket/Syscall.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.4)

The import of ‘Foreign’ is redundant

Check warning on line 13 in Network/Socket/Syscall.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.4)

The import of ‘Foreign’ is redundant

Check warning on line 13 in Network/Socket/Syscall.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.4)

The import of ‘Foreign’ is redundant
import Foreign.Marshal.Alloc (alloca)
import GHC.Conc (asyncDoProc)
import Network.Socket.Cbits
Expand Down Expand Up @@ -89,7 +89,7 @@
setNonBlock fd
#if __IO_MANAGER_WINIO__ >= 2
-- Associate socket with I/O manager immediately if using WinIO
(return () <!> Mgr.associateHandle' (wordPtrToPtr $ fromIntegral fd))
(return () <!> associateSocket fd)
#endif
s <- mkSocket fd
-- This socket is not managed by the IO manager yet.
Expand Down Expand Up @@ -263,7 +263,7 @@
new_sock <- E.bracketOnError (callAccept listing_fd new_sa sz) c_close $ \fd -> do
#if __IO_MANAGER_WINIO__ >= 2
-- Associate accepted socket with I/O manager if using WinIO
(return () <!> Mgr.associateHandle' (wordPtrToPtr $ fromIntegral fd))
(return () <!> associateSocket fd)
#endif
mkSocket fd
new_addr <- peekSocketAddress new_sa
Expand Down Expand Up @@ -295,6 +295,21 @@
# endif /* HAVE_ADVANCED_SOCKET_FLAGS */
#endif

#if __IO_MANAGER_WINIO__ >= 2
-- | Associate a socket with the I/O manager, skipping the completion port for
-- an operation that finishes at once.
associateSocket :: CSocket -> IO ()
associateSocket fd = do
let h = wordPtrToPtr $ fromIntegral fd
Mgr.associateHandle' h
-- Not FILE_SKIP_SET_EVENT_ON_HANDLE: cancelling waits on the handle.
ok <- c_SetFileCompletionNotificationModes h fileSkipCompletionPortOnSuccess
unless ok $ ioError (userError "associateSocket: SetFileCompletionNotificationModes failed")

foreign import ccall unsafe "windows.h SetFileCompletionNotificationModes"
c_SetFileCompletionNotificationModes :: Ptr () -> Word8 -> IO Bool

#endif
foreign import CALLCONV unsafe "socket"
c_socket :: CInt -> CInt -> CInt -> IO CSocket
foreign import CALLCONV unsafe "bind"
Expand Down
Loading