conClose and curClose
This commit is contained in:
parent
f5a946c0e0
commit
78427d37b1
1 changed files with 19 additions and 2 deletions
|
@ -1,8 +1,8 @@
|
||||||
module Database.MongoDB
|
module Database.MongoDB
|
||||||
(
|
(
|
||||||
connect, connectOnPort,
|
connect, connectOnPort, conClose,
|
||||||
delete, insert, insertMany, query, remove, update,
|
delete, insert, insertMany, query, remove, update,
|
||||||
nextDoc,
|
nextDoc, curClose,
|
||||||
Collection, FieldSelector, NumToSkip, NumToReturn, RequestID, Selector,
|
Collection, FieldSelector, NumToSkip, NumToReturn, RequestID, Selector,
|
||||||
Opcode(..),
|
Opcode(..),
|
||||||
QueryOpt(..),
|
QueryOpt(..),
|
||||||
|
@ -44,6 +44,9 @@ connectOnPort host port = do
|
||||||
nsRef <- newIORef ns
|
nsRef <- newIORef ns
|
||||||
return $ Connection { cHandle = h, cRand = nsRef }
|
return $ Connection { cHandle = h, cRand = nsRef }
|
||||||
|
|
||||||
|
conClose :: Connection -> IO ()
|
||||||
|
conClose = hClose . cHandle
|
||||||
|
|
||||||
data Cursor = Cursor {
|
data Cursor = Cursor {
|
||||||
curCon :: Connection,
|
curCon :: Connection,
|
||||||
curID :: IORef Int64,
|
curID :: IORef Int64,
|
||||||
|
@ -277,6 +280,20 @@ getMore cur = do
|
||||||
writeIORef (curDocBytes cur) docBytes'
|
writeIORef (curDocBytes cur) docBytes'
|
||||||
return $ Just doc
|
return $ Just doc
|
||||||
|
|
||||||
|
|
||||||
|
curClose :: Cursor -> IO ()
|
||||||
|
curClose cur = do
|
||||||
|
let h = cHandle $ curCon cur
|
||||||
|
cid <- readIORef $ curID cur
|
||||||
|
let body = runPut $ do
|
||||||
|
putI32 0
|
||||||
|
putI32 1
|
||||||
|
putI64 cid
|
||||||
|
(reqID, msg) <- packMsg (curCon cur) OP_KILL_CURSORS body
|
||||||
|
L.hPut h msg
|
||||||
|
writeIORef (curClosed cur) True
|
||||||
|
return ()
|
||||||
|
|
||||||
putCol col = putByteString (pack col) >> putNull
|
putCol col = putByteString (pack col) >> putNull
|
||||||
|
|
||||||
packMsg :: Connection -> Opcode -> L.ByteString -> IO (RequestID, L.ByteString)
|
packMsg :: Connection -> Opcode -> L.ByteString -> IO (RequestID, L.ByteString)
|
||||||
|
|
Loading…
Reference in a new issue