File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -382,6 +382,12 @@ module Network.Socket (
382
382
383
383
-- * Special constants
384
384
maxListenQueue ,
385
+
386
+ -- * STM to check read and write
387
+ waitReadSocketSTM ,
388
+ waitAndCancelReadSocketSTM ,
389
+ waitWriteSocketSTM ,
390
+ waitAndCancelWriteSocketSTM ,
385
391
) where
386
392
387
393
import Network.Socket.Buffer hiding (
@@ -399,6 +405,7 @@ import Network.Socket.Info
399
405
import Network.Socket.Internal
400
406
import Network.Socket.Name hiding (getPeerName , getSocketName )
401
407
import Network.Socket.Options
408
+ import Network.Socket.STM
402
409
import Network.Socket.Shutdown
403
410
import Network.Socket.SockAddr
404
411
import Network.Socket.Syscall hiding (accept , bind , connect )
Original file line number Diff line number Diff line change
1
+ module Network.Socket.STM where
2
+
3
+ import Control.Concurrent
4
+ import Control.Concurrent.STM
5
+ import Network.Socket.Types
6
+ import System.Posix.Types
7
+
8
+ -- | STM action to wait until the socket is ready for reading.
9
+ waitReadSocketSTM :: Socket -> IO (STM () )
10
+ waitReadSocketSTM s = fst <$> waitAndCancelReadSocketSTM s
11
+
12
+ -- | STM action to wait until the socket is ready for reading and STM
13
+ -- action to cancel the waiting.
14
+ waitAndCancelReadSocketSTM :: Socket -> IO (STM () , IO () )
15
+ waitAndCancelReadSocketSTM s = withFdSocket s $ threadWaitReadSTM . Fd
16
+
17
+ -- | STM action to wait until the socket is ready for writing.
18
+ waitWriteSocketSTM :: Socket -> IO (STM () )
19
+ waitWriteSocketSTM s = fst <$> waitAndCancelWriteSocketSTM s
20
+
21
+ -- | STM action to wait until the socket is ready for writing and STM
22
+ -- action to cancel the waiting.
23
+ waitAndCancelWriteSocketSTM :: Socket -> IO (STM () , IO () )
24
+ waitAndCancelWriteSocketSTM s = withFdSocket s $ threadWaitWriteSTM . Fd
Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ library
115
115
Network.Socket.Name
116
116
Network.Socket.Options
117
117
Network.Socket.ReadShow
118
+ Network.Socket.STM
118
119
Network.Socket.Shutdown
119
120
Network.Socket.SockAddr
120
121
Network.Socket.Syscall
@@ -132,7 +133,8 @@ library
132
133
base >= 4.9 && < 5 ,
133
134
bytestring >= 0.10 ,
134
135
deepseq,
135
- directory
136
+ directory,
137
+ stm
136
138
137
139
if !os(windows)
138
140
other-modules :
You can’t perform that action at this time.
0 commit comments