Safe Haskell | None |
---|---|
Language | Haskell98 |
System.Posix.CircularBuffer
Contents
Description
Create a circular buffer over shared memory that can be accessed from separate processes.
This module assumes that exactly one WriteBuffer and one ReadBuffer will be used to access the same shared memory object. The ReadBuffer and WriteBuffer may exist in separate processes.
to use this library, in one process
bracket (createBuffer "aBuffer" "aSemaphore" 256 0o600) (removeBuffer) (\buffer -> doSomethingWith buffer)
and in the other
bracket (openBuffer "aBuffer" "aSemaphore" 256 0o600) (closeBuffer) (\buffer -> doSomethingWith buffer)
The buffer may be opened from either the reader or writer end, but you should ensure that the buffer is created before it is opened.
As the underlying objects (shm and named posix semaphores) exist in the file system, failing to call removeBuffer will leave stale objects in the filesystem.
Opening multiple ReadBuffers or WriteBuffers with the same names (whether in one process or several) results in undefined behavior.
- data WriteBuffer a
- data ReadBuffer a
- class Shared b where
- createBuffer :: String -> String -> Int -> FileMode -> IO b
- openBuffer :: String -> String -> Int -> FileMode -> IO b
- closeBuffer :: b -> IO ()
- removeBuffer :: b -> IO ()
- unlinkBuffer :: b -> IO ()
- data WaitStrategy
- putBuffer :: Storable a => WriteBuffer a -> a -> IO ()
- getBuffer :: Storable a => WaitStrategy -> ReadBuffer a -> IO a
- tryGetBuffer :: Storable a => ReadBuffer a -> IO (Maybe a)
- putBufferList :: Storable a => WriteBuffer a -> [a] -> IO ()
- getAvailable :: Storable a => ReadBuffer a -> IO [a]
- sizeOfInt :: Int
Documentation
data WriteBuffer a Source
Instances
Storable a => Shared (WriteBuffer a) |
data ReadBuffer a Source
Instances
Storable a => Shared (ReadBuffer a) |
Functions for creatingopeningclosing/removing shared buffers.
Methods
createBuffer :: String -> String -> Int -> FileMode -> IO b Source
openBuffer :: String -> String -> Int -> FileMode -> IO b Source
closeBuffer :: b -> IO () Source
removeBuffer :: b -> IO () Source
unlinkBuffer :: b -> IO () Source
data WaitStrategy Source
normal interface
putBuffer :: Storable a => WriteBuffer a -> a -> IO () Source
Write a value to the writer end.
This function is thread-safe.
getBuffer :: Storable a => WaitStrategy -> ReadBuffer a -> IO a Source
read the next value from the reader end.
This function is *NOT* thread-safe.
tryGetBuffer :: Storable a => ReadBuffer a -> IO (Maybe a) Source
Try to read the next value from the reader end.
This function is *NOT* thread-safe.
batch operations
putBufferList :: Storable a => WriteBuffer a -> [a] -> IO () Source
Write a list of values to the writer end.
This function is thread-safe.
getAvailable :: Storable a => ReadBuffer a -> IO [a] Source
read all currently available values from the reader end.
This function is *NOT* thread-safe.