2016-06-21 01:49:31 +00:00
|
|
|
{-|
|
|
|
|
Module : MongoDB TLS
|
|
|
|
Copyright : (c) Victor Denisov, 2016
|
|
|
|
License : Apache 2.0
|
|
|
|
Maintainer : Victor Denisov denisovenator@gmail.com
|
|
|
|
Stability : alpha
|
|
|
|
Portability : POSIX
|
2015-03-05 19:20:02 +00:00
|
|
|
|
2016-06-21 01:49:31 +00:00
|
|
|
This module defines a connection interface. It could be a regular
|
|
|
|
network connection, TLS connection, a mock or anything else.
|
|
|
|
-}
|
2015-03-05 19:20:02 +00:00
|
|
|
|
2016-05-03 04:30:00 +00:00
|
|
|
module Database.MongoDB.Transport (
|
|
|
|
Transport(..),
|
2015-03-05 19:20:02 +00:00
|
|
|
fromHandle,
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Prelude hiding (read)
|
|
|
|
import Data.ByteString (ByteString)
|
|
|
|
import qualified Data.ByteString as ByteString
|
|
|
|
import System.IO
|
|
|
|
|
2016-05-03 04:30:00 +00:00
|
|
|
-- | Abstract transport interface
|
2020-04-01 14:53:37 +00:00
|
|
|
--
|
|
|
|
-- `read` should return `ByteString.null` on EOF
|
2016-05-03 04:30:00 +00:00
|
|
|
data Transport = Transport {
|
2020-04-01 14:53:37 +00:00
|
|
|
read :: Int -> IO ByteString,
|
2015-03-05 19:20:02 +00:00
|
|
|
write :: ByteString -> IO (),
|
|
|
|
flush :: IO (),
|
|
|
|
close :: IO ()}
|
|
|
|
|
2016-05-03 04:30:00 +00:00
|
|
|
fromHandle :: Handle -> IO Transport
|
2016-06-21 01:49:31 +00:00
|
|
|
-- ^ Make connection from handle
|
2015-03-05 19:20:02 +00:00
|
|
|
fromHandle handle = do
|
2016-05-03 04:30:00 +00:00
|
|
|
return Transport
|
2016-05-02 02:05:51 +00:00
|
|
|
{ read = ByteString.hGet handle
|
2015-03-05 19:20:02 +00:00
|
|
|
, write = ByteString.hPut handle
|
|
|
|
, flush = hFlush handle
|
|
|
|
, close = hClose handle
|
|
|
|
}
|