socket-sctp 0.2.0.1 → 0.3.0.0
raw patch · 3 files changed
+13/−11 lines, 3 files
Files
- socket-sctp.cabal +1/−1
- src/System/Socket/Protocol/SCTP/Internal.hsc +11/−9
- tests/Notifications.hs +1/−1
socket-sctp.cabal view
@@ -1,5 +1,5 @@ name: socket-sctp-version: 0.2.0.1+version: 0.3.0.0 synopsis: STCP socket extensions library. description: This is a binding to the types and operations of `libsctp`.
src/System/Socket/Protocol/SCTP/Internal.hsc view
@@ -42,7 +42,7 @@ , msgNotification , Notification (..) , AssocId- , unsafeParseNotification+ , parseNotification -- ** SCTP_ASSOC_CHANGE , AssocChange (..) , AcState(..)@@ -50,6 +50,7 @@ import Control.Applicative import Control.Exception+import Control.Monad import Data.Bits import Data.Monoid@@ -430,17 +431,18 @@ | RESTART | SHUTDOWN_COMP | CANT_STR_ASSOC- | UNKNOWN_AC_STATE deriving (Show)+ | UNKNOWN_AC_STATE deriving (Show, Eq, Enum, Read) -- | Parse an SCTP notification.------ This assumes that the buffer contains a complete notification (i.e.--- MSG_EOR was set on the last chunk it contains), and is thus unsafe.--- Unfortunately, because of the possibility of partial notifications--- from a too-small buffer for recvmsg, this must be exposed to users.-unsafeParseNotification :: BS.ByteString -> IO Notification-unsafeParseNotification bs =+-- Requires a full notification buffer to be passed.+parseNotification :: BS.ByteString -> IO Notification+parseNotification bs = BS.unsafeUseAsCStringLen bs $ \(ptr, sz) -> do+ when (sz < #{offset union sctp_notification, sn_header.sn_length} + 4 {- uint32_t -})+ $ error "incomplete notification buffer passed to parseNotification"+ expected_sz <- #{peek union sctp_notification, sn_header.sn_length} ptr :: IO Word32+ when ((fromIntegral sz) < expected_sz)+ $ error "incomplete notification buffer passed to parseNotification" ty <- #{peek union sctp_notification, sn_header.sn_type} ptr :: IO Word16 case ty of #{const SCTP_ASSOC_CHANGE} -> AssocChangeNotification <$> unsafeParseAssocChange (ptr, sz)
tests/Notifications.hs view
@@ -29,7 +29,7 @@ when (flags .&. msgEndOfRecord == mempty) (e 8) when (flags .&. msgNotification == mempty) (e 9)- notification <- unsafeParseNotification msg+ notification <- parseNotification msg case notification of AssocChangeNotification (AssocChange { acState = COMM_UP }) -> return () _ -> e 10