1
1
{-# LANGUAGE CPP #-}
2
+ {-# LANGUAGE ScopedTypeVariables #-}
2
3
3
4
#include "HsNet.h"
4
5
##include "HsNetDef.h"
@@ -13,28 +14,32 @@ module Network.Socket.Unix (
13
14
, getPeerEid
14
15
) where
15
16
16
- import System.Posix.Types (Fd (.. ))
17
-
17
+ import Foreign.Marshal.Alloc (allocaBytes )
18
18
import Network.Socket.Buffer
19
+ import Network.Socket.Fcntl
19
20
import Network.Socket.Imports
21
+ import Network.Socket.Types
22
+ import System.Posix.Types (Fd (.. ))
23
+
20
24
#if defined(mingw32_HOST_OS)
25
+ import Network.Socket.Syscall
21
26
import Network.Socket.Win32.Cmsg
27
+ import System.Directory
28
+ import System.IO
29
+ import System.IO.Temp
22
30
#else
31
+ import Foreign.Marshal.Array (peekArray )
32
+ import Network.Socket.Internal
23
33
import Network.Socket.Posix.Cmsg
24
34
#endif
25
- import Network.Socket.Types
26
35
27
36
#if defined(HAVE_GETPEEREID)
28
37
import System.IO.Error (catchIOError )
29
38
#endif
30
39
#ifdef HAVE_GETPEEREID
31
40
import Foreign.Marshal.Alloc (alloca )
32
41
#endif
33
- import Foreign.Marshal.Alloc (allocaBytes )
34
- import Foreign.Marshal.Array (peekArray )
35
42
36
- import Network.Socket.Fcntl
37
- import Network.Socket.Internal
38
43
#ifdef HAVE_STRUCT_UCRED_SO_PEERCRED
39
44
import Network.Socket.Options
40
45
#endif
@@ -165,6 +170,21 @@ socketPair :: Family -- Family Name (usually AF_UNIX)
165
170
-> SocketType -- Socket Type (usually Stream)
166
171
-> ProtocolNumber -- Protocol Number
167
172
-> IO (Socket , Socket ) -- unnamed and connected.
173
+ #if defined(mingw32_HOST_OS)
174
+ socketPair _ _ _ = withSystemTempFile " temp-for-pair" $ \ file hdl -> do
175
+ hClose hdl
176
+ removeFile file
177
+ listenSock <- socket AF_UNIX Stream defaultProtocol
178
+ bind listenSock $ SockAddrUnix file
179
+ listen listenSock 10
180
+ clientSock <- socket AF_UNIX Stream defaultProtocol
181
+ connect clientSock $ SockAddrUnix file
182
+ (serverSock, _ :: SockAddr ) <- accept listenSock
183
+ close listenSock
184
+ withFdSocket clientSock setNonBlockIfNeeded
185
+ withFdSocket serverSock setNonBlockIfNeeded
186
+ return (clientSock, serverSock)
187
+ #else
168
188
socketPair family stype protocol =
169
189
allocaBytes (2 * sizeOf (1 :: CInt )) $ \ fdArr -> do
170
190
let c_stype = packSocketType stype
@@ -179,3 +199,4 @@ socketPair family stype protocol =
179
199
180
200
foreign import ccall unsafe " socketpair"
181
201
c_socketpair :: CInt -> CInt -> CInt -> Ptr CInt -> IO CInt
202
+ #endif
0 commit comments