Skip to content

Commit 54f3afc

Browse files
committed
adding filterCmsg.
1 parent aef4e42 commit 54f3afc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Network/Socket.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ module Network.Socket
229229
,CmsgIdIPv6PktInfo)
230230
-- ** APIs for control message
231231
, lookupCmsg
232+
, filterCmsg
232233
, decodeCmsg
233234
, encodeCmsg
234235
-- ** Class and yypes for control message

Network/Socket/Posix/Cmsg.hsc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ pattern CmsgIdFd = CmsgId (#const SOL_SOCKET) (#const SCM_RIGHTS)
7575
-- > (lookupCmsg CmsgIdIPv4TOS cmsgs >>= decodeCmsg) :: Maybe IPv4TOS
7676
lookupCmsg :: CmsgId -> [Cmsg] -> Maybe Cmsg
7777
lookupCmsg _ [] = Nothing
78-
lookupCmsg aid (cmsg@(Cmsg cid _):cmsgs)
79-
| aid == cid = Just cmsg
80-
| otherwise = lookupCmsg aid cmsgs
78+
lookupCmsg cid (cmsg:cmsgs)
79+
| cmsgId cmsg == cid = Just cmsg
80+
| otherwise = lookupCmsg cid cmsgs
81+
82+
-- | Filtering control message.
83+
filterCmsg :: CmsgId -> [Cmsg] -> [Cmsg]
84+
filterCmsg cid cmsgs = filter (\cmsg -> cmsgId cmsg == cid) cmsgs
8185

8286
----------------------------------------------------------------
8387

0 commit comments

Comments
 (0)