Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding the STM module. #586

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
7 changes: 7 additions & 0 deletions Network/Socket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ module Network.Socket (

-- * Special constants
maxListenQueue,

-- * STM to check read and write
waitReadSocketSTM,
waitAndCancelReadSocketSTM,
waitWriteSocketSTM,
waitAndCancelWriteSocketSTM,
) where

import Network.Socket.Buffer hiding (
Expand All @@ -399,6 +405,7 @@ import Network.Socket.Info
import Network.Socket.Internal
import Network.Socket.Name hiding (getPeerName, getSocketName)
import Network.Socket.Options
import Network.Socket.STM
import Network.Socket.Shutdown
import Network.Socket.SockAddr
import Network.Socket.Syscall hiding (accept, bind, connect)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file formatting only?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Sorry. fourmolue did it automatically.

Expand Down
24 changes: 24 additions & 0 deletions Network/Socket/STM.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Network.Socket.STM where

import Control.Concurrent
import Control.Concurrent.STM
import Network.Socket.Types
import System.Posix.Types

-- | STM action to wait until the socket is ready for reading.
waitReadSocketSTM :: Socket -> IO (STM ())
waitReadSocketSTM s = fst <$> waitAndCancelReadSocketSTM s

-- | STM action to wait until the socket is ready for reading and STM
-- action to cancel the waiting.
waitAndCancelReadSocketSTM :: Socket -> IO (STM (), IO ())
waitAndCancelReadSocketSTM s = withFdSocket s $ threadWaitReadSTM . Fd

-- | STM action to wait until the socket is ready for writing.
waitWriteSocketSTM :: Socket -> IO (STM ())
waitWriteSocketSTM s = fst <$> waitAndCancelWriteSocketSTM s

-- | STM action to wait until the socket is ready for writing and STM
-- action to cancel the waiting.
waitAndCancelWriteSocketSTM :: Socket -> IO (STM (), IO ())
waitAndCancelWriteSocketSTM s = withFdSocket s $ threadWaitWriteSTM . Fd
4 changes: 3 additions & 1 deletion network.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ library
Network.Socket.Name
Network.Socket.Options
Network.Socket.ReadShow
Network.Socket.STM
Network.Socket.Shutdown
Network.Socket.SockAddr
Network.Socket.Syscall
Expand All @@ -132,7 +133,8 @@ library
base >=4.9 && <5,
bytestring >=0.10,
deepseq,
directory
directory,
stm

if !os(windows)
other-modules:
Expand Down
Loading