-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting sendMsg and recvMsg. #433
Conversation
Coincidentally, I wrote similar code for |
If we can support it cross platform then I'm in favor of inclusion. @Mistuke's answer about Windows will be key in that decision. |
@eborden I agree. |
@Mistuke I would like to forward this issue. Would you give us your advice? Are you in mountains again? :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the API could have been lower-level to reduce some overhead and to make C-interop easier.
For example in the proposed API recvMsg
returns lists of ByteString
s and Cmsg
s. This can be a costly process to run in low-latency networking code because every payload and ancillary data needs to be copied over to the Haskell heap. Instead it would be nice if we had something analoguous to recvBuf.
Sorry, was very very busy with work. I will go over this today. |
OK. I will try to implement this feature in |
Additional plan:
|
@maoe @vdukhovni Would you review this again? @Mistuke Now it's your turn. If time allows, please implement Windows part. |
It appeared that |
@kazu-yamamoto Sorry missed your message, I will get started on this next Sunday (suspect to be able to get it done same week). Currently untangling some GHC release issues :( |
@Mistuke No rush. But please keep in mind this issue. :-) I'm currently testing this PR with my QUIC implementation. |
Rebased onto |
I haven't forgotten about this! I'm mapping the changes I need to do out and will refactor it and hopefully have something soon! |
WIP PR for Windows support at at kazu-yamamoto#2, should be able to finish it next weekend. |
@Mistuke Gentle ping |
looks like |
Haven't forgotten, still debugging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some mostly documentation-related comments. The code looks fine to me at first glance.
Network/Socket/Posix/Cmsg.hsc
Outdated
|
||
---------------------------------------------------------------- | ||
|
||
-- | Looking up control message. The following shows an example usage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of "Looking up control message", better might be:
Locate a control message of the given type in a list of control messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is this function really necessary? It is the same as Data.List.find . (. cmsgId) . (==)
.
I am not sure it needs to be provided here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the doc and the definition.
But is this function really necessary? It is the same as Data.List.find . (. cmsgId) . (==).
Not sure. But I think it's useful as suggested in the usage.
| cmsgId cmsg == cid = Just cmsg | ||
| otherwise = lookupCmsg cid cmsgs | ||
|
||
-- | Filtering control message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too might be better rephrased, but again, why not just drop it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if you provided the better doc.
foreign import ccall SAFE_ON_WIN "recvFd" c_recvFd :: CInt -> IO CInt | ||
recvFd s = allocaBytes dummyBufSize $ \buf -> do | ||
(NullSockAddr, _, cmsgs, _) <- recvBufMsg s [(buf,dummyBufSize)] 32 mempty | ||
case (lookupCmsg CmsgIdFd cmsgs >>= decodeCmsg) :: Maybe Fd of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here find ((== CmsgIdFd) . cmsgId) cmsgs
could replace lookupCmsg
.
appveyor.yml
Outdated
- GHCVER: 8.0.2 | ||
- GHCVER: 8.2.2 | ||
- GHCVER: 8.4.4 | ||
- GHCVER: 8.6.3 | ||
- GHCVER: 8.8.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By now perhaps 8.8.2 or 8.8.3, whichever is the latest available on Appveyor?
Almost done, it's a bit slow going debugging the API. I have a working C example now fixing the Haskell side. hopefully done this weekend. |
@kazu-yamamoto That should do it. Sorry for the delay. I've been a bit over stretched lately. The only thing I was wondering about is if I can simplify the logic in
Would it present a problem for Linux if when |
I've not checked Linux, but it would be OK to always encode the flags on FreeBSD where I checked the kernel source, and the However, setting I don't know whether anyone depends on this behaviour, but it is perhaps best to not make that change on Unix-like systems. |
Breacking change: CustomSockOpt was deleted.
This PR has been merged. Thank you for your contribution! Let's discuss left issues in another PR. |
Note that the quality of this code is good enough, I believe. But I don't expect that this PR will be merged quickly. I would like to merge this PR after discussion.
Cc: @snoyberg, @farnoy, @ocheron, @lukehoersten, @lpeterse, @vdukhovni
Motivation
MSG_PEEK
for TCP sockets to peek the received data without removing the input queue.IP_TTL
,IP_TOS
for ECN andIP_PKTINFO
to specify the outgoing network interface for UDP packets.So, I would like to discuss how to support
sendmsg()
andrecvmsg()
. Note that they can be used for TCP in addition to UDP.Design
The current wrapper APIs for
sendmsg()
andrecvmsg()
are as follows:MsgFlag
includesMSG_PEEK
Cmsg
is a low level format forsendMsg
andrecvMsg
. Their values can be converted into user-friendly type values such asIPv4TTL
andIPv4PktInfo
viaAuxiliary
class.I believe we don't have to extend, for instance,
recv
to supportMsgFlag
sincerecvMsg
is a superset.Please read test cases to know how to use these APIs more concretely.
Discussion
sendMsg
/recvMsg
be supported innetwork
. Or another package?Note
IPv4TTL
/IPv6HopLimit
andIPv4TOS
/IPv6TClass
are reading-purpose only.IPv4PktInfo
andIPv6PktInfo
forsendMsg
are not tested yet.