Revision 3603605a htools/Ganeti/Luxi.hs

b/htools/Ganeti/Luxi.hs
60 60
withTimeout :: Int -> String -> IO a -> IO a
61 61
withTimeout secs descr action = do
62 62
  result <- timeout (secs * 1000000) action
63
  (case result of
64
     Nothing -> fail $ "Timeout in " ++ descr
65
     Just v -> return v)
63
  case result of
64
    Nothing -> fail $ "Timeout in " ++ descr
65
    Just v -> return v
66 66

  
67 67
-- * Generic protocol functionality
68 68

  
......
213 213
              nbuf <- withTimeout queryTimeout "reading luxi response" $
214 214
                      S.recv (socket s) 4096
215 215
              let (msg, remaining) = break (eOM ==) nbuf
216
              (if null remaining
217
               then _recv (obuf ++ msg)
218
               else return (obuf ++ msg, tail remaining))
216
              if null remaining
217
                then _recv (obuf ++ msg)
218
                else return (obuf ++ msg, tail remaining)
219 219
  cbuf <- readIORef $ rbuf s
220 220
  let (imsg, ibuf) = break (eOM ==) cbuf
221 221
  (msg, nbuf) <-
222
      (if null ibuf      -- if old buffer didn't contain a full message
223
       then _recv cbuf   -- then we read from network
224
       else return (imsg, tail ibuf)) -- else we return data from our buffer
222
    if null ibuf      -- if old buffer didn't contain a full message
223
      then _recv cbuf   -- then we read from network
224
      else return (imsg, tail ibuf) -- else we return data from our buffer
225 225
  writeIORef (rbuf s) nbuf
226 226
  return msg
227 227

  
......
244 244
  let arr = J.fromJSObject oarr
245 245
  status <- fromObj arr (strOfKey Success)::Result Bool
246 246
  let rkey = strOfKey Result
247
  (if status
248
   then fromObj arr rkey
249
   else fromObj arr rkey >>= fail)
247
  if status
248
    then fromObj arr rkey
249
    else fromObj arr rkey >>= fail
250 250

  
251 251
-- | Generic luxi method call.
252 252
callMethod :: LuxiOp -> Client -> IO (Result JSValue)

Also available in: Unified diff