Finish up bindings to most core gRPC functions (#1)
* grpc_server_request_call
* basic slice functionality
* rename function to emphasize side effects
* add docs
* ByteBuffer function bindings
* replace unsafeCoerce with more specific function, add docs, tests.
* add newtypes for Tag and Reserved void pointers
* manually fix request_registered_call binding
* use nocode keyword to fix Ptr () problems
* decouple copying Slice from freeing slice
* Add time ops
* remove nocode decls
* Start Op module, fix c2hs preprocessing order
* metadata manipulation operations
* metadata free function, test
* helper functions for constructing ops of each type
* bindings for op creation functions
* finish up Op creation functions, implement Op destruction, add docs.
* tweak documentation
* rework Op creation functions to work with an array of ops, for ease of use with grpc_call_start_batch
* forgot to change return types
* wrap hook lines, fix types to op creation functions
* implement part of the payload test
* hideous, but working, end to end test
* bindings for connectivity state checks, split test into two threads
* various cleanup
* rename Core to Unsafe for emphasis, clean up tests more
* add requested comment
* remove slice_unref binding, use sliceFree when converting buffer to bytestring
2016-05-13 18:12:37 +02:00
|
|
|
module Network.GRPC.Unsafe.Op where
|
|
|
|
|
|
|
|
import Control.Exception
|
|
|
|
import Foreign.C.String
|
|
|
|
import Foreign.C.Types
|
|
|
|
import Foreign.Ptr
|
|
|
|
{#import Network.GRPC.Unsafe.ByteBuffer#}
|
|
|
|
{#import Network.GRPC.Unsafe.Metadata#}
|
|
|
|
|
|
|
|
#include <grpc/grpc.h>
|
|
|
|
#include <grpc/status.h>
|
|
|
|
#include <grpc/impl/codegen/grpc_types.h>
|
|
|
|
#include <grpc_haskell.h>
|
|
|
|
|
Begin safe low-level Haskell layer (#7)
* grpc_server_request_call
* basic slice functionality
* rename function to emphasize side effects
* add docs
* ByteBuffer function bindings
* replace unsafeCoerce with more specific function, add docs, tests.
* add newtypes for Tag and Reserved void pointers
* manually fix request_registered_call binding
* use nocode keyword to fix Ptr () problems
* decouple copying Slice from freeing slice
* Add time ops
* remove nocode decls
* Start Op module, fix c2hs preprocessing order
* metadata manipulation operations
* metadata free function, test
* helper functions for constructing ops of each type
* bindings for op creation functions
* finish up Op creation functions, implement Op destruction, add docs.
* tweak documentation
* rework Op creation functions to work with an array of ops, for ease of use with grpc_call_start_batch
* forgot to change return types
* wrap hook lines, fix types to op creation functions
* implement part of the payload test
* hideous, but working, end to end test
* bindings for connectivity state checks, split test into two threads
* various cleanup
* rename Core to Unsafe for emphasis, clean up tests more
* begin safe low-level facilities
* begin completion queue and server stuff
* Finish server start/stop, cq start/stop, add tests
* facilities for safely executing op batches
* reorganize LowLevel modules, begin explicit export list
* client functionality, stub payload test, various refactors
* tweak cabal file, add test
* add more documentation
* doc tweaks
* begin refactor to improve CompletionQueue safety
* export only thread-safe CQ functions, add registered call creation and other CQ utilities
* begin refactor to use GRPCIO monad, fix missing push semaphore, fix mem leak in server calls
* switch to explicit Either where needed
* add crashing tests, continue fleshing out serverHandleNormalCall
* fix haddock error, finish first draft of request handling function
* reduce GHC warnings
* non-registered client request helpers
* initial request/response test working
* don't pass tags around; generate where needed
* server call bracket functions
* correct order of semaphore acquisition and shutdown check
* simple debug flag logging, simplify Call type
* fix various registered method issues (but still not working)
* cleanup
* delete old code
* remove old todo
* use MetadataMap synonym pervasively
* more comments
* update TODOs
* tweak safety caveat
* docs tweaks
* improve haddocks
* add casts to eliminate clang warnings, remove unused function
* update options to eliminate cabal warnings
* remove outdated todo
* remove unneeded exports from CompletionQueue
* rename to GRPCIOCallError, re-add create/shutdown exports (needed for Server module)
* newtypes for hosts and method names
* more newtypes
* more debug logging
* Fix flag name collision
* instrument uses of free
* more debug
* switch to STM for completion queue stuff
* reduce warnings
* more debugging, create/destroy call tests
* refactor, fix failure cleanup for server call creation. More tests passing.
* formatting tweaks
2016-05-24 22:34:50 +02:00
|
|
|
{#enum grpc_op_type as OpType {underscoreToCase} deriving (Eq, Show)#}
|
|
|
|
{#enum grpc_status_code as StatusCode {underscoreToCase} deriving (Eq, Show)#}
|
Finish up bindings to most core gRPC functions (#1)
* grpc_server_request_call
* basic slice functionality
* rename function to emphasize side effects
* add docs
* ByteBuffer function bindings
* replace unsafeCoerce with more specific function, add docs, tests.
* add newtypes for Tag and Reserved void pointers
* manually fix request_registered_call binding
* use nocode keyword to fix Ptr () problems
* decouple copying Slice from freeing slice
* Add time ops
* remove nocode decls
* Start Op module, fix c2hs preprocessing order
* metadata manipulation operations
* metadata free function, test
* helper functions for constructing ops of each type
* bindings for op creation functions
* finish up Op creation functions, implement Op destruction, add docs.
* tweak documentation
* rework Op creation functions to work with an array of ops, for ease of use with grpc_call_start_batch
* forgot to change return types
* wrap hook lines, fix types to op creation functions
* implement part of the payload test
* hideous, but working, end to end test
* bindings for connectivity state checks, split test into two threads
* various cleanup
* rename Core to Unsafe for emphasis, clean up tests more
* add requested comment
* remove slice_unref binding, use sliceFree when converting buffer to bytestring
2016-05-13 18:12:37 +02:00
|
|
|
|
|
|
|
-- NOTE: We don't alloc the space for the enum in Haskell because enum size is
|
|
|
|
-- implementation-dependent. See:
|
|
|
|
-- http://stackoverflow.com/questions/1113855/is-the-sizeofenum-sizeofint-always
|
|
|
|
-- | Allocates space for a 'StatusCode' and returns a pointer to it. Used to
|
|
|
|
-- receive a status code from the server with 'opRecvStatusClient'.
|
|
|
|
{#fun create_status_code_ptr as ^ {} -> `Ptr StatusCode' castPtr#}
|
|
|
|
|
Begin safe low-level Haskell layer (#7)
* grpc_server_request_call
* basic slice functionality
* rename function to emphasize side effects
* add docs
* ByteBuffer function bindings
* replace unsafeCoerce with more specific function, add docs, tests.
* add newtypes for Tag and Reserved void pointers
* manually fix request_registered_call binding
* use nocode keyword to fix Ptr () problems
* decouple copying Slice from freeing slice
* Add time ops
* remove nocode decls
* Start Op module, fix c2hs preprocessing order
* metadata manipulation operations
* metadata free function, test
* helper functions for constructing ops of each type
* bindings for op creation functions
* finish up Op creation functions, implement Op destruction, add docs.
* tweak documentation
* rework Op creation functions to work with an array of ops, for ease of use with grpc_call_start_batch
* forgot to change return types
* wrap hook lines, fix types to op creation functions
* implement part of the payload test
* hideous, but working, end to end test
* bindings for connectivity state checks, split test into two threads
* various cleanup
* rename Core to Unsafe for emphasis, clean up tests more
* begin safe low-level facilities
* begin completion queue and server stuff
* Finish server start/stop, cq start/stop, add tests
* facilities for safely executing op batches
* reorganize LowLevel modules, begin explicit export list
* client functionality, stub payload test, various refactors
* tweak cabal file, add test
* add more documentation
* doc tweaks
* begin refactor to improve CompletionQueue safety
* export only thread-safe CQ functions, add registered call creation and other CQ utilities
* begin refactor to use GRPCIO monad, fix missing push semaphore, fix mem leak in server calls
* switch to explicit Either where needed
* add crashing tests, continue fleshing out serverHandleNormalCall
* fix haddock error, finish first draft of request handling function
* reduce GHC warnings
* non-registered client request helpers
* initial request/response test working
* don't pass tags around; generate where needed
* server call bracket functions
* correct order of semaphore acquisition and shutdown check
* simple debug flag logging, simplify Call type
* fix various registered method issues (but still not working)
* cleanup
* delete old code
* remove old todo
* use MetadataMap synonym pervasively
* more comments
* update TODOs
* tweak safety caveat
* docs tweaks
* improve haddocks
* add casts to eliminate clang warnings, remove unused function
* update options to eliminate cabal warnings
* remove outdated todo
* remove unneeded exports from CompletionQueue
* rename to GRPCIOCallError, re-add create/shutdown exports (needed for Server module)
* newtypes for hosts and method names
* more newtypes
* more debug logging
* Fix flag name collision
* instrument uses of free
* more debug
* switch to STM for completion queue stuff
* reduce warnings
* more debugging, create/destroy call tests
* refactor, fix failure cleanup for server call creation. More tests passing.
* formatting tweaks
2016-05-24 22:34:50 +02:00
|
|
|
{#fun deref_status_code_ptr as ^ {castPtr `Ptr StatusCode'} -> `StatusCode'#}
|
|
|
|
|
Finish up bindings to most core gRPC functions (#1)
* grpc_server_request_call
* basic slice functionality
* rename function to emphasize side effects
* add docs
* ByteBuffer function bindings
* replace unsafeCoerce with more specific function, add docs, tests.
* add newtypes for Tag and Reserved void pointers
* manually fix request_registered_call binding
* use nocode keyword to fix Ptr () problems
* decouple copying Slice from freeing slice
* Add time ops
* remove nocode decls
* Start Op module, fix c2hs preprocessing order
* metadata manipulation operations
* metadata free function, test
* helper functions for constructing ops of each type
* bindings for op creation functions
* finish up Op creation functions, implement Op destruction, add docs.
* tweak documentation
* rework Op creation functions to work with an array of ops, for ease of use with grpc_call_start_batch
* forgot to change return types
* wrap hook lines, fix types to op creation functions
* implement part of the payload test
* hideous, but working, end to end test
* bindings for connectivity state checks, split test into two threads
* various cleanup
* rename Core to Unsafe for emphasis, clean up tests more
* add requested comment
* remove slice_unref binding, use sliceFree when converting buffer to bytestring
2016-05-13 18:12:37 +02:00
|
|
|
{#fun destroy_status_code_ptr as ^ {castPtr `Ptr StatusCode'} -> `()' #}
|
|
|
|
|
|
|
|
-- | Represents an array of ops to be passed to 'grpcCallStartBatch'.
|
|
|
|
-- Create an array with 'opArrayCreate', then create individual ops in the array
|
|
|
|
-- using the op* functions. For these functions, the first two arguments are
|
|
|
|
-- always the OpArray to mutate and the index in the array at which to create
|
|
|
|
-- the new op. After processing the batch and getting out any results, call
|
|
|
|
-- 'opArrayDestroy'.
|
|
|
|
{#pointer *grpc_op as OpArray newtype #}
|
|
|
|
|
|
|
|
-- | Creates an empty 'OpArray' with space for the given number of ops.
|
|
|
|
{#fun op_array_create as ^ {`Int'} -> `OpArray'#}
|
|
|
|
|
|
|
|
-- | Destroys an 'OpArray' of the given size.
|
|
|
|
{#fun op_array_destroy as ^ {`OpArray', `Int'} -> `()'#}
|
|
|
|
|
|
|
|
-- | brackets creating and destroying an 'OpArray' with the given size.
|
|
|
|
withOpArray :: Int -> (OpArray -> IO a) -> IO a
|
|
|
|
withOpArray n f = bracket (opArrayCreate n) (flip opArrayDestroy n) f
|
|
|
|
|
|
|
|
-- | Creates an op of type GRPC_OP_SEND_INITIAL_METADATA at the specified
|
|
|
|
-- index of the given 'OpArray', containing the given
|
|
|
|
-- metadata. The metadata is copied and can be destroyed after calling this
|
|
|
|
-- function.
|
|
|
|
{#fun op_send_initial_metadata as ^
|
|
|
|
{`OpArray', `Int', `MetadataKeyValPtr', `Int'} -> `()'#}
|
|
|
|
|
|
|
|
-- | Creates an op of type GRPC_OP_SEND_INITIAL_METADATA at the specified
|
|
|
|
-- index of the given 'OpArray'. The op will contain no metadata.
|
|
|
|
{#fun op_send_initial_metadata_empty as ^ {`OpArray', `Int'} -> `()'#}
|
|
|
|
|
|
|
|
-- | Creates an op of type GRPC_OP_SEND_MESSAGE at the specified index of
|
|
|
|
-- the given 'OpArray'. The given 'ByteBuffer' is
|
|
|
|
-- copied and can be destroyed after calling this function.
|
|
|
|
{#fun op_send_message as ^ {`OpArray', `Int', `ByteBuffer'} -> `()'#}
|
|
|
|
|
|
|
|
-- | Creates an 'Op' of type GRPC_OP_SEND_CLOSE_FROM_CLIENT at the specified
|
|
|
|
-- index of the given 'OpArray'.
|
|
|
|
{#fun op_send_close_client as ^ {`OpArray', `Int'} -> `()'#}
|
|
|
|
|
|
|
|
-- | Creates an op of type GRPC_OP_RECV_INITIAL_METADATA at the specified
|
|
|
|
-- index of the given 'OpArray', and ties the given
|
|
|
|
-- 'MetadataArray' pointer to that op so that the received metadata can be
|
|
|
|
-- accessed. It is the user's responsibility to destroy the 'MetadataArray'.
|
|
|
|
{#fun op_recv_initial_metadata as ^
|
|
|
|
{`OpArray', `Int',id `Ptr MetadataArray'} -> `()'#}
|
|
|
|
|
|
|
|
-- | Creates an op of type GRPC_OP_RECV_MESSAGE at the specified index of the
|
|
|
|
-- given 'OpArray', and ties the given
|
|
|
|
-- 'ByteBuffer' pointer to that op so that the received message can be
|
|
|
|
-- accessed. It is the user's responsibility to destroy the 'ByteBuffer'.
|
|
|
|
{#fun op_recv_message as ^ {`OpArray', `Int',id `Ptr ByteBuffer'} -> `()'#}
|
|
|
|
|
|
|
|
-- | Creates an op of type GRPC_OP_RECV_STATUS_ON_CLIENT at the specified
|
|
|
|
-- index of the given 'OpArray', and ties all the
|
|
|
|
-- input pointers to that op so that the results of the receive can be
|
|
|
|
-- accessed. It is the user's responsibility to free all the input args after
|
|
|
|
-- this call.
|
|
|
|
{#fun op_recv_status_client as ^
|
|
|
|
{`OpArray', `Int',id `Ptr MetadataArray', castPtr `Ptr StatusCode',
|
|
|
|
castPtr `Ptr CString', `Int'}
|
|
|
|
-> `()'#}
|
|
|
|
|
|
|
|
-- | Creates an op of type GRPC_OP_RECV_CLOSE_ON_SERVER at the specified index
|
|
|
|
-- of the given 'OpArray', and ties the input
|
|
|
|
-- pointer to that op so that the result of the receive can be accessed. It is
|
|
|
|
-- the user's responsibility to free the pointer.
|
|
|
|
{#fun op_recv_close_server as ^ {`OpArray', `Int', id `Ptr CInt'} -> `()'#}
|
|
|
|
|
|
|
|
-- | Creates an op of type GRPC_OP_SEND_STATUS_FROM_SERVER at the specified
|
|
|
|
-- index of the given 'OpArray'. The given
|
|
|
|
-- Metadata and string are copied when creating the op, and can be safely
|
|
|
|
-- destroyed immediately after calling this function.
|
|
|
|
{#fun op_send_status_server as ^
|
|
|
|
{`OpArray', `Int', `Int', `MetadataKeyValPtr', `StatusCode', `String'}
|
|
|
|
-> `()'#}
|