From 78427d37b16e383fd19b23c5e8a746d9a8f2afb1 Mon Sep 17 00:00:00 2001 From: "Scott R. Parish" Date: Sat, 16 Jan 2010 18:04:15 -0600 Subject: [PATCH] conClose and curClose --- Database/MongoDB.hs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Database/MongoDB.hs b/Database/MongoDB.hs index 5fc577a..9e146a6 100644 --- a/Database/MongoDB.hs +++ b/Database/MongoDB.hs @@ -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)