From 4ae3936ac95447ce369325059618c3c1e2a635e3 Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Mon, 11 Jul 2016 12:53:19 -0500 Subject: [PATCH] Apply same pluck permission region fix to unregistered serverRequestCall --- .../LowLevel/CompletionQueue/Unregistered.hs | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/src/Network/GRPC/LowLevel/CompletionQueue/Unregistered.hs b/src/Network/GRPC/LowLevel/CompletionQueue/Unregistered.hs index 1ddbd1a..ce4818f 100644 --- a/src/Network/GRPC/LowLevel/CompletionQueue/Unregistered.hs +++ b/src/Network/GRPC/LowLevel/CompletionQueue/Unregistered.hs @@ -36,36 +36,37 @@ serverRequestCall server cq@CompletionQueue{..} = withPermission Push cq $ bracket malloc free $ \callPtr -> C.withMetadataArrayPtr $ \metadataArrayPtr -> - C.withCallDetails $ \callDetails -> do - grpcDebug $ "serverRequestCall: callPtr is " ++ show callPtr - metadataArray <- peek metadataArrayPtr - tag <- newTag cq - callError <- C.grpcServerRequestCall server callPtr callDetails - metadataArray unsafeCQ unsafeCQ tag - grpcDebug $ "serverRequestCall: callError was " ++ show callError - if callError /= C.CallOk - then do grpcDebug "serverRequestCall: got call error; cleaning up." - return $ Left $ GRPCIOCallError callError - else do pluckResult <- pluck cq tag Nothing - grpcDebug $ "serverRequestCall: pluckResult was " - ++ show pluckResult - case pluckResult of - Left x -> do - grpcDebug "serverRequestCall: pluck error." - return $ Left x - Right () -> do - rawCall <- peek callPtr - metadata <- C.getAllMetadataArray metadataArray - deadline <- getDeadline callDetails - method <- getMethod callDetails - host <- getHost callDetails - let call = U.ServerCall rawCall - metadata - Nothing - deadline - method - host - return $ Right call + C.withCallDetails $ \callDetails -> + withPermission Pluck cq $ do + grpcDebug $ "serverRequestCall: callPtr is " ++ show callPtr + metadataArray <- peek metadataArrayPtr + tag <- newTag cq + callError <- C.grpcServerRequestCall server callPtr callDetails + metadataArray unsafeCQ unsafeCQ tag + grpcDebug $ "serverRequestCall: callError was " ++ show callError + if callError /= C.CallOk + then do grpcDebug "serverRequestCall: got call error; cleaning up." + return $ Left $ GRPCIOCallError callError + else do pluckResult <- pluck cq tag Nothing + grpcDebug $ "serverRequestCall: pluckResult was " + ++ show pluckResult + case pluckResult of + Left x -> do + grpcDebug "serverRequestCall: pluck error." + return $ Left x + Right () -> do + rawCall <- peek callPtr + metadata <- C.getAllMetadataArray metadataArray + deadline <- getDeadline callDetails + method <- getMethod callDetails + host <- getHost callDetails + let call = U.ServerCall rawCall + metadata + Nothing + deadline + method + host + return $ Right call where getDeadline callDetails = do C.timeSpec <$> C.callDetailsGetDeadline callDetails