Skip to content

Commit

Permalink
adding filterCmsg.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Jan 16, 2020
1 parent cc498d6 commit d5bec3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions Network/Socket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ module Network.Socket
,CmsgIdIPv6PktInfo)
-- ** APIs for control message
, lookupCmsg
, filterCmsg
, decodeCmsg
, encodeCmsg
-- ** Class and yypes for control message
Expand Down
10 changes: 7 additions & 3 deletions Network/Socket/Posix/Cmsg.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ pattern CmsgIdFd = CmsgId (#const SOL_SOCKET) (#const SCM_RIGHTS)
-- > (lookupCmsg CmsgIdIPv4TOS cmsgs >>= decodeCmsg) :: Maybe IPv4TOS
lookupCmsg :: CmsgId -> [Cmsg] -> Maybe Cmsg
lookupCmsg _ [] = Nothing
lookupCmsg aid (cmsg@(Cmsg cid _):cmsgs)
| aid == cid = Just cmsg
| otherwise = lookupCmsg aid cmsgs
lookupCmsg cid (cmsg:cmsgs)
| cmsgId cmsg == cid = Just cmsg
| otherwise = lookupCmsg cid cmsgs

-- | Filtering control message.
filterCmsg :: CmsgId -> [Cmsg] -> [Cmsg]
filterCmsg cid cmsgs = filter (\cmsg -> cmsgId cmsg == cid) cmsgs

----------------------------------------------------------------

Expand Down

0 comments on commit d5bec3a

Please sign in to comment.