conClose and curClose

This commit is contained in:
Scott R. Parish 2010-01-16 18:04:15 -06:00
parent f5a946c0e0
commit 78427d37b1

View file

@ -1,8 +1,8 @@
module Database.MongoDB
(
connect, connectOnPort,
connect, connectOnPort, conClose,
delete, insert, insertMany, query, remove, update,
nextDoc,
nextDoc, curClose,
Collection, FieldSelector, NumToSkip, NumToReturn, RequestID, Selector,
Opcode(..),
QueryOpt(..),
@ -44,6 +44,9 @@ connectOnPort host port = do
nsRef <- newIORef ns
return $ Connection { cHandle = h, cRand = nsRef }
conClose :: Connection -> IO ()
conClose = hClose . cHandle
data Cursor = Cursor {
curCon :: Connection,
curID :: IORef Int64,
@ -277,6 +280,20 @@ getMore cur = do
writeIORef (curDocBytes cur) docBytes'
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
packMsg :: Connection -> Opcode -> L.ByteString -> IO (RequestID, L.ByteString)