packages feed

posix-api 0.5.0.0 → 0.6.0.0

raw patch · 5 files changed

+35/−69 lines, 5 files

Files

CHANGELOG.md view
@@ -7,6 +7,10 @@  This project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). +## [0.6.0.0] - 2023-07-13++- Use Int instead of CInt for all offsets into byte arrays+ ## [0.5.0.0] - 2023-07-13  - Move Linux.Systemd to systemd-api library to make docs build on hackage.
README.md view
@@ -33,24 +33,6 @@ grey area when it comes to what a "minimal binding" to a function is. Discussion may sometimes be necessary to refine the guidelines. -## Build Instructions--This library relies on a currently-unreleased version of `hsc2hs` in-order to build. In order to try out this library, try:--```-~/dev $ git clone https://github.com/haskell/hsc2hs-~/dev $ cd hsc2hs-~/dev/hsc2hs $ cabal install-~/dev/hsc2hs $ cd ..-~/dev $ git clone https://github.com/andrewthad/posix-api-~/dev $ cd posix-api-~/dev/posix-api $ cabal new-build --with-hsc2hs=~/.cabal/bin/hsc2hs-```--This will build `posix-api` with the unreleased version of the `hsc2hs`-tool.- ## Infelicities  This project currently includes some Linux-specific code. It in the
cbits/HaskellPosix.c view
@@ -44,16 +44,16 @@ ssize_t write_offset(int fd, const char *message, HsInt offset, size_t length){   return write(fd, (const void*)(message + offset), length); }-ssize_t recv_offset(int socket, char *buffer, int offset, size_t length, int flags) {+ssize_t recv_offset(int socket, char *buffer, HsInt offset, size_t length, int flags) {   return recv(socket, (void*)(buffer + offset), length, flags); }-ssize_t send_offset(int socket, const char *buffer, int offset, size_t length, int flags) {+ssize_t send_offset(int socket, const char *buffer, HsInt offset, size_t length, int flags) {   return send(socket, (const void*)(buffer + offset), length, flags); }-ssize_t sendto_offset(int socket, const char *message, int offset, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len){+ssize_t sendto_offset(int socket, const char *message, HsInt offset, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len){   return sendto(socket, (const void*)(message + offset), length, flags, dest_addr, dest_len); }-ssize_t sendto_inet_offset(int socket, const char *message, int offset, size_t length, int flags, uint16_t port, uint32_t inet_addr){+ssize_t sendto_inet_offset(int socket, const char *message, HsInt offset, size_t length, int flags, uint16_t port, uint32_t inet_addr){   struct sockaddr_in dest;   memset(&dest, 0, sizeof(dest));   dest.sin_family = AF_INET;@@ -69,10 +69,10 @@   dest.sin_port = port;   return sendto(socket, message, length, flags, (struct sockaddr*)&dest, sizeof(dest)); }-ssize_t recvfrom_offset(int socket, char *restrict buffer, int offset, size_t length, int flags, struct sockaddr *restrict address, socklen_t *restrict address_len) {+ssize_t recvfrom_offset(int socket, char *restrict buffer, HsInt offset, size_t length, int flags, struct sockaddr *restrict address, socklen_t *restrict address_len) {   return recvfrom(socket, (void*)(buffer + offset), length, flags, address, address_len); }-ssize_t recvfrom_offset_peerless(int socket, char *restrict buffer, int offset, size_t length, int flags) {+ssize_t recvfrom_offset_peerless(int socket, char *restrict buffer, HsInt offset, size_t length, int flags) {   return recvfrom(socket, (void*)(buffer + offset), length, flags, NULL, NULL); } ssize_t recvfrom_addr_peerless(int socket, void *restrict buffer, size_t length, int flags) {@@ -120,24 +120,14 @@   return setsockopt(socket,level,option_name,&option_value,sizeof(int)); } -// There are some compatibility macros in here. Before GHC 8.10,-// no offset is applied to ArrayArray#. ssize_t sendmsg_bytearrays   ( int sockfd-#if __GLASGOW_HASKELL__ >= 810   , StgArrBytes **arrs // used for input-#else-  , StgMutArrPtrs *arr // used for input-#endif   , HsInt off // offset into input chunk array   , HsInt len0 // number of chunks to send   , HsInt offC // offset into first chunk   , int flags   ) {-#if __GLASGOW_HASKELL__ < 810-  StgClosure **arrPayload = arr->payload;-  StgArrBytes **arrs = (StgArrBytes**)arrPayload;-#endif   struct iovec bufs[MAX_BYTEARRAYS];   HsInt len1 = len0 > MAX_BYTEARRAYS ? MAX_BYTEARRAYS : len0;   // We must handle the first chunk specially since@@ -217,24 +207,14 @@   return sendmsg(sockfd,&msg,flags); } -// There are some compatibility macros in here. Before GHC 8.10,-// no offset is applied to ArrayArray#. int recvmmsg_sockaddr_in   ( int sockfd   , int *lens // used for output   , struct sockaddr_in *addrs // used for output-#if __GLASGOW_HASKELL__ >= 810   , StgArrBytes **bufs // used for output-#else-  , StgMutArrPtrs *arr // used for output-#endif   , unsigned int vlen   , int flags   ) {-#if __GLASGOW_HASKELL__ < 810-  StgClosure **bufsX = arr->payload;-  StgArrBytes **bufs = (StgArrBytes**)bufsX;-#endif   // TODO: It's probably better to statically pick   // out a maximum size for these. On the C stack,   // the cost of doing this is basically nothing.
posix-api.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: posix-api-version: 0.5.0.0+version: 0.6.0.0 synopsis: posix bindings description:   This library provides a very thin wrapper around POSIX APIs. It can be
src/Posix/Socket.hs view
@@ -359,28 +359,28 @@ foreign import ccall safe "sys/socket.h send"   c_safe_addr_send :: Fd -> Addr# -> CSize -> MessageFlags 'Send -> IO CSsize foreign import ccall safe "sys/socket.h send_offset"-  c_safe_bytearray_send :: Fd -> ByteArray# -> CInt -> CSize -> MessageFlags 'Send -> IO CSsize+  c_safe_bytearray_send :: Fd -> ByteArray# -> Int -> CSize -> MessageFlags 'Send -> IO CSsize foreign import ccall safe "sys/socket.h send_offset"-  c_safe_mutablebytearray_send :: Fd -> MutableByteArray# RealWorld -> CInt -> CSize -> MessageFlags 'Send -> IO CSsize+  c_safe_mutablebytearray_send :: Fd -> MutableByteArray# RealWorld -> Int -> CSize -> MessageFlags 'Send -> IO CSsize foreign import ccall safe "sys/socket.h send"   c_safe_mutablebytearray_no_offset_send :: Fd -> MutableByteArray# RealWorld -> CSize -> MessageFlags 'Send -> IO CSsize foreign import ccall unsafe "sys/socket.h send"   c_unsafe_addr_send :: Fd -> Addr# -> CSize -> MessageFlags 'Send -> IO CSsize foreign import ccall unsafe "sys/socket.h send_offset"-  c_unsafe_bytearray_send :: Fd -> ByteArray# -> CInt -> CSize -> MessageFlags 'Send -> IO CSsize+  c_unsafe_bytearray_send :: Fd -> ByteArray# -> Int -> CSize -> MessageFlags 'Send -> IO CSsize foreign import ccall unsafe "sys/socket.h send_offset"-  c_unsafe_mutable_bytearray_send :: Fd -> MutableByteArray# RealWorld -> CInt -> CSize -> MessageFlags 'Send -> IO CSsize+  c_unsafe_mutable_bytearray_send :: Fd -> MutableByteArray# RealWorld -> Int -> CSize -> MessageFlags 'Send -> IO CSsize  -- The ByteArray# (second to last argument) is a SocketAddress. foreign import ccall unsafe "sys/socket.h sendto_offset"-  c_unsafe_bytearray_sendto :: Fd -> ByteArray# -> CInt -> CSize -> MessageFlags 'Send -> ByteArray# -> CInt -> IO CSsize+  c_unsafe_bytearray_sendto :: Fd -> ByteArray# -> Int -> CSize -> MessageFlags 'Send -> ByteArray# -> CInt -> IO CSsize -- The ByteArray# (second to last argument) is a SocketAddress. foreign import ccall unsafe "sys/socket.h sendto_offset"-  c_unsafe_mutable_bytearray_sendto :: Fd -> MutableByteArray# RealWorld -> CInt -> CSize -> MessageFlags 'Send -> ByteArray# -> CInt -> IO CSsize+  c_unsafe_mutable_bytearray_sendto :: Fd -> MutableByteArray# RealWorld -> Int -> CSize -> MessageFlags 'Send -> ByteArray# -> CInt -> IO CSsize foreign import ccall unsafe "sys/socket.h sendto_inet_offset"-  c_unsafe_mutable_bytearray_sendto_inet :: Fd -> MutableByteArray# RealWorld -> CInt -> CSize -> MessageFlags 'Send -> Word16 -> Word32 -> IO CSsize+  c_unsafe_mutable_bytearray_sendto_inet :: Fd -> MutableByteArray# RealWorld -> Int -> CSize -> MessageFlags 'Send -> Word16 -> Word32 -> IO CSsize foreign import ccall unsafe "HaskellPosix.h sendto_inet_offset"-  c_unsafe_bytearray_sendto_inet :: Fd -> ByteArray# -> CInt -> CSize -> MessageFlags 'Send -> Word16 -> Word32 -> IO CSsize+  c_unsafe_bytearray_sendto_inet :: Fd -> ByteArray# -> Int -> CSize -> MessageFlags 'Send -> Word16 -> Word32 -> IO CSsize foreign import ccall unsafe "HaskellPosix.h sendto_inet_addr"   c_unsafe_addr_sendto_inet :: Fd -> Addr# -> CSize -> MessageFlags 'Send -> Word16 -> Word32 -> IO CSsize @@ -402,15 +402,15 @@ foreign import ccall unsafe "sys/socket.h recv"   c_unsafe_addr_recv :: Fd -> Addr# -> CSize -> MessageFlags 'Receive -> IO CSsize foreign import ccall unsafe "sys/socket.h recv_offset"-  c_unsafe_mutable_byte_array_recv :: Fd -> MutableByteArray# RealWorld -> CInt -> CSize -> MessageFlags 'Receive -> IO CSsize+  c_unsafe_mutable_byte_array_recv :: Fd -> MutableByteArray# RealWorld -> Int -> CSize -> MessageFlags 'Receive -> IO CSsize  -- The last two arguments are SocketAddress and Ptr CInt. foreign import ccall unsafe "sys/socket.h recvfrom_offset"-  c_unsafe_mutable_byte_array_recvfrom :: Fd -> MutableByteArray# RealWorld -> CInt -> CSize -> MessageFlags 'Receive -> MutableByteArray# RealWorld -> MutableByteArray# RealWorld -> IO CSsize+  c_unsafe_mutable_byte_array_recvfrom :: Fd -> MutableByteArray# RealWorld -> Int -> CSize -> MessageFlags 'Receive -> MutableByteArray# RealWorld -> MutableByteArray# RealWorld -> IO CSsize foreign import ccall unsafe "sys/socket.h recvfrom_offset_peerless"   c_unsafe_mutable_byte_array_peerless_recvfrom ::        Fd-    -> MutableByteArray# RealWorld -> CInt -> CSize+    -> MutableByteArray# RealWorld -> Int -> CSize     -> MessageFlags 'Receive -> IO CSsize foreign import ccall unsafe "sys/socket.h recvfrom_addr_peerless"   c_unsafe_addr_peerless_recvfrom ::@@ -724,7 +724,7 @@ sendByteArray ::      Fd -- ^ Socket   -> ByteArray -- ^ Source byte array-  -> CInt -- ^ Offset into source array+  -> Int -- ^ Offset into source array   -> CSize -- ^ Length in bytes   -> MessageFlags 'Send -- ^ Flags   -> IO (Either Errno CSize) -- ^ Number of bytes pushed to send buffer@@ -732,7 +732,7 @@   then errorsFromSize =<< c_safe_bytearray_send fd b# off len flags   else do     x@(MutableByteArray x#) <- PM.newPinnedByteArray (csizeToInt len)-    PM.copyByteArray x (cintToInt off) b 0 (csizeToInt len)+    PM.copyByteArray x off b 0 (csizeToInt len)     errorsFromSize =<< c_safe_mutablebytearray_no_offset_send fd x# len flags  -- | Write data from multiple byte arrays to the file/socket associated@@ -868,7 +868,7 @@ sendMutableByteArray ::      Fd -- ^ Socket   -> MutableByteArray RealWorld -- ^ Source byte array-  -> CInt -- ^ Offset into source array+  -> Int -- ^ Offset into source array   -> CSize -- ^ Length in bytes   -> MessageFlags 'Send -- ^ Flags   -> IO (Either Errno CSize) -- ^ Number of bytes pushed to send buffer@@ -876,7 +876,7 @@   then errorsFromSize =<< c_safe_mutablebytearray_send fd b# off len flags   else do     x@(MutableByteArray x#) <- PM.newPinnedByteArray (csizeToInt len)-    PM.copyMutableByteArray x (cintToInt off) b 0 (csizeToInt len)+    PM.copyMutableByteArray x off b 0 (csizeToInt len)     errorsFromSize =<< c_safe_mutablebytearray_no_offset_send fd x# len flags  -- | Send data from an address over a network socket. This is not guaranteed@@ -912,7 +912,7 @@ uninterruptibleSendByteArray ::      Fd -- ^ Socket   -> ByteArray -- ^ Source byte array-  -> CInt -- ^ Offset into source array+  -> Int -- ^ Offset into source array   -> CSize -- ^ Length in bytes   -> MessageFlags 'Send -- ^ Flags   -> IO (Either Errno CSize) -- ^ Number of bytes pushed to send buffer@@ -926,7 +926,7 @@ uninterruptibleSendMutableByteArray ::      Fd -- ^ Socket   -> MutableByteArray RealWorld -- ^ Source mutable byte array-  -> CInt -- ^ Offset into source array+  -> Int -- ^ Offset into source array   -> CSize -- ^ Length in bytes   -> MessageFlags 'Send -- ^ Flags   -> IO (Either Errno CSize) -- ^ Number of bytes pushed to send buffer@@ -941,7 +941,7 @@ uninterruptibleSendToByteArray ::      Fd -- ^ Socket   -> ByteArray -- ^ Source byte array-  -> CInt -- ^ Offset into source array+  -> Int -- ^ Offset into source array   -> CSize -- ^ Length in bytes   -> MessageFlags 'Send -- ^ Flags   -> SocketAddress -- ^ Socket Address@@ -956,7 +956,7 @@ uninterruptibleSendToInternetByteArray ::      Fd -- ^ Socket   -> ByteArray -- ^ Source byte array-  -> CInt -- ^ Offset into source array+  -> Int -- ^ Offset into source array   -> CSize -- ^ Length in bytes   -> MessageFlags 'Send -- ^ Flags   -> SocketAddressInternet -- ^ Socket Address@@ -986,7 +986,7 @@ uninterruptibleSendToMutableByteArray ::      Fd -- ^ Socket   -> MutableByteArray RealWorld -- ^ Source byte array-  -> CInt -- ^ Offset into source array+  -> Int -- ^ Offset into source array   -> CSize -- ^ Length in bytes   -> MessageFlags 'Send -- ^ Flags   -> SocketAddress -- ^ Socket Address@@ -1001,7 +1001,7 @@ uninterruptibleSendToInternetMutableByteArray ::      Fd -- ^ Socket   -> MutableByteArray RealWorld -- ^ Source byte array-  -> CInt -- ^ Offset into source array+  -> Int -- ^ Offset into source array   -> CSize -- ^ Length in bytes   -> MessageFlags 'Send -- ^ Flags   -> SocketAddressInternet -- ^ Socket Address@@ -1067,7 +1067,7 @@ uninterruptibleReceiveMutableByteArray ::      Fd -- ^ Socket   -> MutableByteArray RealWorld -- ^ Destination byte array-  -> CInt -- ^ Destination offset+  -> Int -- ^ Destination offset   -> CSize -- ^ Maximum bytes to receive   -> MessageFlags 'Receive -- ^ Flags   -> IO (Either Errno CSize) -- ^ Bytes received into array@@ -1081,7 +1081,7 @@ uninterruptibleReceiveFromMutableByteArray ::      Fd -- ^ Socket   -> MutableByteArray RealWorld -- ^ Destination byte array-  -> CInt -- ^ Destination offset+  -> Int -- ^ Destination offset   -> CSize -- ^ Maximum bytes to receive   -> MessageFlags 'Receive -- ^ Flags   -> CInt -- ^ Maximum socket address size@@ -1144,7 +1144,7 @@ uninterruptibleReceiveFromMutableByteArray_ ::      Fd -- ^ Socket   -> MutableByteArray RealWorld -- ^ Destination byte array-  -> CInt -- ^ Destination offset+  -> Int -- ^ Destination offset   -> CSize -- ^ Maximum bytes to receive   -> MessageFlags 'Receive -- ^ Flags   -> IO (Either Errno CSize) -- ^ Number of bytes received into array