Skip to content

Commit 27a750a

Browse files
authored
Merge pull request #80 from codedownio/windows-unix-sockets
Allow Unix sockets on Windows
2 parents c3d7034 + 46c2630 commit 27a750a

File tree

4 files changed

+5
-29
lines changed

4 files changed

+5
-29
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog for streaming-commons
22

3+
## 0.2.3.0
4+
5+
* Allow Unix sockets on Windows (https://github.com/fpco/streaming-commons/pull/80)
6+
37
## 0.2.2.6
48

59
* Remove the zlib headers [#72](https://github.com/fpco/streaming-commons/issues/72)

Data/Streaming/Network.hs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,40 @@ module Data.Streaming.Network
88
, HostPreference
99
, Message (..)
1010
, AppData
11-
#if !WINDOWS
1211
, ServerSettingsUnix
1312
, ClientSettingsUnix
1413
, AppDataUnix
15-
#endif
1614
-- ** Smart constructors
1715
, serverSettingsTCP
1816
, serverSettingsTCPSocket
1917
, clientSettingsTCP
2018
, serverSettingsUDP
2119
, clientSettingsUDP
22-
#if !WINDOWS
2320
, serverSettingsUnix
2421
, clientSettingsUnix
25-
#endif
2622
, message
2723
-- ** Classes
2824
, HasPort (..)
2925
, HasAfterBind (..)
3026
, HasReadWrite (..)
3127
, HasReadBufferSize (..)
32-
#if !WINDOWS
3328
, HasPath (..)
34-
#endif
3529
-- ** Setters
3630
, setPort
3731
, setHost
3832
, setAddrFamily
3933
, setAfterBind
4034
, setNeedLocalAddr
4135
, setReadBufferSize
42-
#if !WINDOWS
4336
, setPath
44-
#endif
4537
-- ** Getters
4638
, getPort
4739
, getHost
4840
, getAddrFamily
4941
, getAfterBind
5042
, getNeedLocalAddr
5143
, getReadBufferSize
52-
#if !WINDOWS
5344
, getPath
54-
#endif
5545
, appRead
5646
, appWrite
5747
, appSockAddr
@@ -82,13 +72,11 @@ module Data.Streaming.Network
8272
, bindPortUDP
8373
, bindRandomPortUDP
8474
, getSocketUDP
85-
#if !WINDOWS
8675
-- ** Unix
8776
, bindPath
8877
, getSocketUnix
8978
, runUnixServer
9079
, runUnixClient
91-
#endif
9280
) where
9381

9482
import qualified Network.Socket as NS
@@ -265,7 +253,6 @@ defaultReadBufferSize :: Int
265253
defaultReadBufferSize = unsafeDupablePerformIO $
266254
bracket (NS.socket NS.AF_INET NS.Stream 0) NS.close (\sock -> NS.getSocketOption sock NS.RecvBuffer)
267255

268-
#if !WINDOWS
269256
-- | Attempt to connect to the given Unix domain socket path.
270257
getSocketUnix :: FilePath -> IO Socket
271258
getSocketUnix path = do
@@ -317,7 +304,6 @@ clientSettingsUnix path = ClientSettingsUnix
317304
{ clientPath = path
318305
, clientReadBufferSizeUnix = defaultReadBufferSize
319306
}
320-
#endif
321307

322308
#if defined(__GLASGOW_HASKELL__) && WINDOWS
323309
-- Socket recv and accept calls on Windows platform cannot be interrupted when compiled with -threaded.
@@ -495,7 +481,6 @@ setAddrFamily af cs = cs { clientAddrFamily = af }
495481
getAddrFamily :: ClientSettings -> NS.Family
496482
getAddrFamily = clientAddrFamily
497483

498-
#if !WINDOWS
499484
class HasPath a where
500485
pathLens :: Functor f => (FilePath -> f FilePath) -> a -> f a
501486
instance HasPath ServerSettingsUnix where
@@ -508,7 +493,6 @@ getPath = getConstant . pathLens Constant
508493

509494
setPath :: HasPath a => FilePath -> a -> a
510495
setPath p = runIdentity . pathLens (const (Identity p))
511-
#endif
512496

513497
setNeedLocalAddr :: Bool -> ServerSettings -> ServerSettings
514498
setNeedLocalAddr x y = y { serverNeedLocalAddr = x }
@@ -520,10 +504,8 @@ class HasAfterBind a where
520504
afterBindLens :: Functor f => ((Socket -> IO ()) -> f (Socket -> IO ())) -> a -> f a
521505
instance HasAfterBind ServerSettings where
522506
afterBindLens f ss = fmap (\p -> ss { serverAfterBind = p }) (f (serverAfterBind ss))
523-
#if !WINDOWS
524507
instance HasAfterBind ServerSettingsUnix where
525508
afterBindLens f ss = fmap (\p -> ss { serverAfterBindUnix = p }) (f (serverAfterBindUnix ss))
526-
#endif
527509

528510
getAfterBind :: HasAfterBind a => a -> (Socket -> IO ())
529511
getAfterBind = getConstant . afterBindLens Constant
@@ -540,14 +522,12 @@ instance HasReadBufferSize ServerSettings where
540522
-- | Since 0.1.13
541523
instance HasReadBufferSize ClientSettings where
542524
readBufferSizeLens f cs = fmap (\p -> cs { clientReadBufferSize = p }) (f (clientReadBufferSize cs))
543-
#if !WINDOWS
544525
-- | Since 0.1.13
545526
instance HasReadBufferSize ServerSettingsUnix where
546527
readBufferSizeLens f ss = fmap (\p -> ss { serverReadBufferSizeUnix = p }) (f (serverReadBufferSizeUnix ss))
547528
-- | Since 0.1.14
548529
instance HasReadBufferSize ClientSettingsUnix where
549530
readBufferSizeLens f ss = fmap (\p -> ss { clientReadBufferSizeUnix = p }) (f (clientReadBufferSizeUnix ss))
550-
#endif
551531

552532
-- | Get buffer size used when reading from socket.
553533
--
@@ -640,19 +620,16 @@ class HasReadWrite a where
640620
instance HasReadWrite AppData where
641621
readLens f a = fmap (\x -> a { appRead' = x }) (f (appRead' a))
642622
writeLens f a = fmap (\x -> a { appWrite' = x }) (f (appWrite' a))
643-
#if !WINDOWS
644623
instance HasReadWrite AppDataUnix where
645624
readLens f a = fmap (\x -> a { appReadUnix = x }) (f (appReadUnix a))
646625
writeLens f a = fmap (\x -> a { appWriteUnix = x }) (f (appWriteUnix a))
647-
#endif
648626

649627
appRead :: HasReadWrite a => a -> IO ByteString
650628
appRead = getConstant . readLens Constant
651629

652630
appWrite :: HasReadWrite a => a -> ByteString -> IO ()
653631
appWrite = getConstant . writeLens Constant
654632

655-
#if !WINDOWS
656633
-- | Run an @Application@ with the given settings. This function will create a
657634
-- new listening socket, accept connections on it, and spawn a new thread for
658635
-- each connection.
@@ -686,4 +663,3 @@ runUnixClient (ClientSettingsUnix path readBufferSize) app = E.bracket
686663
{ appReadUnix = safeRecv sock readBufferSize
687664
, appWriteUnix = sendAll sock
688665
})
689-
#endif

Data/Streaming/Network/Internal.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ module Data.Streaming.Network.Internal
55
, HostPreference (..)
66
, Message (..)
77
, AppData (..)
8-
#if !WINDOWS
98
, ServerSettingsUnix (..)
109
, ClientSettingsUnix (..)
1110
, AppDataUnix (..)
12-
#endif
1311
) where
1412

1513
import Data.String (IsString (..))
@@ -73,7 +71,6 @@ instance IsString HostPreference where
7371
fromString "!6" = HostIPv6Only
7472
fromString s = Host s
7573

76-
#if !WINDOWS
7774
-- | Settings for a Unix domain sockets server.
7875
data ServerSettingsUnix = ServerSettingsUnix
7976
{ serverPath :: !FilePath
@@ -92,7 +89,6 @@ data AppDataUnix = AppDataUnix
9289
{ appReadUnix :: !(IO ByteString)
9390
, appWriteUnix :: !(ByteString -> IO ())
9491
}
95-
#endif
9692

9793
-- | Representation of a single UDP message
9894
data Message = Message { msgData :: {-# UNPACK #-} !ByteString

streaming-commons.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: streaming-commons
2-
version: 0.2.2.6
2+
version: 0.2.3.0
33
synopsis: Common lower-level functions needed by various streaming data libraries
44
description: Provides low-dependency functionality commonly needed by various streaming data libraries, such as conduit and pipes.
55
homepage: https://github.com/fpco/streaming-commons

0 commit comments

Comments
 (0)