packages feed

postgresql-simple 0.3.3.0 → 0.3.3.1

raw patch · 2 files changed

+30/−10 lines, 2 files

Files

postgresql-simple.cabal view
@@ -1,5 +1,5 @@ Name:                postgresql-simple-Version:             0.3.3.0+Version:             0.3.3.1 Synopsis:            Mid-Level PostgreSQL client library Description:     Mid-Level PostgreSQL client library, forked from mysql-simple.@@ -8,7 +8,7 @@ Author:              Bryan O'Sullivan, Leon P Smith Maintainer:          Leon P Smith <leon@melding-monads.com> Copyright:           (c) 2011 MailRank, Inc.-                     (c) 2011-2012 Leon P Smith+                     (c) 2011-2013 Leon P Smith Category:            Database Build-type:          Simple @@ -75,7 +75,7 @@ source-repository this   type:     git   location: http://github.com/lpsmith/postgresql-simple-  tag:      v0.3.3.0+  tag:      v0.3.3.1  test-suite test   type:           exitcode-stdio-1.0
src/Database/PostgreSQL/Simple/Notification.hs view
@@ -1,4 +1,6 @@-{-# LANGUAGE RecordWildCards, NamedFieldPuns #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE NamedFieldPuns #-}+{-# LANGUAGE RecordWildCards #-}  ----------------------------------------------------------------------------- -- |@@ -14,6 +16,16 @@ -- <http://www.postgresql.org/docs/9.1/static/sql-notify.html> for more -- information. --+-- Note that on Windows,  @getNotification@ currently uses a polling loop+-- of 1 second to check for more notifications,  due to some inadequacies+-- in GHC's IO implementation and interface on that platform.   See GHC +-- issue #7353 for more information.  While this workaround is less than+-- ideal,  notifications are still better than polling the database directly.+-- Notifications do not create any extra work for the backend,  and are +-- likely cheaper on the client side as well.+--+-- <http://hackage.haskell.org/trac/ghc/ticket/7353>+-- -----------------------------------------------------------------------------  module Database.PostgreSQL.Simple.Notification@@ -22,7 +34,7 @@      , getNotificationNonBlocking      ) where -import           Control.Concurrent ( threadWaitRead )+import           Control.Concurrent import           Control.Monad ( when ) import qualified Data.ByteString as B import           Database.PostgreSQL.Simple.Internal@@ -36,8 +48,7 @@    }  errfd :: String-errfd   = "Database.PostgreSQL.Simple.Notification.getNotification: \-          \failed to fetch file descriptor"+errfd = "Database.PostgreSQL.Simple.Notification.getNotification: failed to fetch file descriptor"  convertNotice :: PQ.Notify -> Notification convertNotice PQ.Notify{..}@@ -49,9 +60,9 @@ --   'getNotification' blocks until one arrives.  getNotification :: Connection -> IO Notification-getNotification = loop False+getNotification conn = loop False   where-    loop doConsume conn = do+    loop doConsume = do         res <- withConnection conn $ \c -> do                          when doConsume (PQ.consumeInput c >> return ())                          mmsg <- PQ.notifies c@@ -64,7 +75,16 @@                            Just msg -> return (Right msg)         -- FIXME? what happens if the connection is closed/reset right here?         case res of-          Left fd -> threadWaitRead fd >> loop True conn+#if defined(mingw32_HOST_OS)+          -- threadWaitRead doesn't work for sockets on Windows, so just poll+          -- for input every second (PQconsumeInput is non-blocking).+          --+          -- We could call select(), but FFI calls can't be interrupted with+          -- async exceptions, whereas threadDelay can.+          Left _fd -> threadDelay 1000000 >> loop True+#else+          Left fd -> threadWaitRead fd >> loop True+#endif           Right msg -> return $! convertNotice msg  -- | Non-blocking variant of 'getNotification'.   Returns a single notification,