peekResponse :: (Ptr Header -> IO a) -> Failure a -> Handle -> IO a
peekResponse success failure h = allocaBytes 24 $ \p -> do
    len <- hGetBuf h p 24
    if len /= 24
        then failure DataReadFailed
        else do
            peekWord16be (plusPtr p 6) >>= \st ->
                if st == 0
                    then success p
                    else do
                        bl <- peekWord32be (plusPtr p 8)
                        failure . MemcachedException st =<< S.hGet h (fromIntegral bl)

peekResponse :: (Ptr Header -> IO a) -> Failure a -> Handle -> IO a
peekResponse success failure h = allocaBytes 24 $ \p -> do
    len <- hGetBuf h p 24
    if len /= 24
        then failure DataReadFailed
        else do
            peekWord16be (plusPtr p 6) >>= \st ->
                if st == 0
                    then success p
                    else do
                        bl <- peekWord32be (plusPtr p 8)
                        failure . MemcachedException st =<< S.hGet h (fromIntegral bl)

peekResponse success failure h = allocaBytes 24 $ \p -> do
    len <- hGetBuf h p 24
    if len /= 24
        then failure DataReadFailed
        else do
            peekWord16be (plusPtr p 6) >>= \st ->
                if st == 0
                    then success p
                    else do
                        bl <- peekWord32be (plusPtr p 8)
                        failure . MemcachedException st =<< S.hGet h (fromIntegral bl)
