神秘的手柄的情况

时间:2012-11-07 21:24:35

标签: haskell conduit

首先我会给你代码,然后是错误,然后是一些类型信息。问题是:我怎样才能弄清楚发生了什么?我该如何解决这个问题?

readTask = do
   req' <-  parseUrl "https://10.64.251.32/rest/api/latest/issue/BNAP-291"
   manager <- newManager manSettings
   let req'' = applyBasicAuth (pack "sandboxer") (pack "sandboxer") req'
   Response _ _ _ body <-runResourceT $ http req'' manager 
   pBody <- runResourceT $
            body $$+- sinkParser json

   --   print pBody
   --   closeManager manager

   return ()
      where manSettings =
               def
                 { managerCheckCerts = \ _ _ -> return CertificateUsageAccept }

编译好。这是我运行编译代码时发生的事情

dist/build/Spike/Spike
Spike: <socket: 3>: hGetBuf: illegal operation (handle is closed)

body是以下类型

Data.Conduit.Internal.ResumableSource
(Control.Monad.Trans.Resource.ResourceT IO)
Data.ByteString.Internal.ByteString

反馈意见,我不知道如何开始排除故障。

1 个答案:

答案 0 :(得分:1)

第一个runResourceT调用是在解析正文之前关闭套接字。您需要将两个runResourceT调用合并为一个。 ResourceT是一个Monad实例,因此您可以使用do表示法和一些小手术在解析完成后释放套接字:

readTask = do
   req' <-  parseUrl "https://10.64.251.32/rest/api/latest/issue/BNAP-291"
   manager <- newManager manSettings
   let req'' = applyBasicAuth (pack "sandboxer") (pack "sandboxer") req'
   runResourceT $ do
      Response _ _ _ body <- http req'' manager 
      pBody <- body $$+- sinkParser json
      liftIO $ print pBody

   closeManager manager

   return ()
      where manSettings =
               def
                 { managerCheckCerts = \ _ _ -> return CertificateUsageAccept }