-
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
Remove EOF errors from receive functions #360
Conversation
It is generally accepted that EOF errors in `Network` were a mistake. Using exceptions for control flow is an anti-pattern in the Haskell community. While we are in the process of introducing epoch breaking changes it makes sense to attempt to remove these historic accidents. There should really be no perceived change for users of `Network.ByteString(.Lazy).recv`, however `recvFrom` does change behavior. There are two key differences in `recvFrom`: 1. It is now returning a `(0, address)` on an EOF. 2. It will peek the socket's address and `getPeerName` on an EOF. This has some implications for performance, and such may be controversial. The second point poses a question. Does the return type of `SocketAddress sa => IO (Int, sa)` make sense for `recvBufFrom`?
7968232
to
d28580e
Compare
+1 from me on removing the |
I'm going to do a quick evaluation of source on hackage to see how frequently |
+1 from me, too. |
Here is a rough accounting of calls on hackage:
|
Here is a further breakdown of the function calls fst
snd
id
void
|
hmm perhaps split the functions up, make a new one that doesn't call That still leaves the exception being removed, but that can be communicated via a changelog? |
I like that plan. That way we are changing a type along with the behavior change. --recvBufFrom :: SocketAddress sa => Socket -> Ptr a -> Int -> IO (Int, sa)
++recvBufFrom :: Socket -> Ptr a -> Int -> IO Int
++recvBufFromWithAddress :: SocketAddress sa => Socket -> Ptr a -> Int -> IO (Int, sa) |
Yeah, that should make things a bit more obvious :) |
Oh you know what, that won't work because of |
Ambiguity between which functions? don't all three of those have different types? |
In this definition we get ambiguity on recvBufFrom :: Socket -> Ptr a -> Int -> IO Int
recvBufFrom s ptr nbytes
| nbytes <= 0 = ioError (mkInvalidRecvArgError "Network.Socket.recvBufFrom")
| otherwise = withNewSocketAddress $ \ptr_sa sz -> alloca $ \ptr_len -> do
fd <- fdSocket s
poke ptr_len (fromIntegral sz)
let cnbytes = fromIntegral nbytes
flags = 0
len <- throwSocketErrorWaitRead s "Network.Socket.recvBufFrom" $
c_recvfrom fd ptr cnbytes flags ptr_sa ptr_len
return $ fromIntegral len |
Before mentioning my opinion, I would like to ask one question about
When does |
I imagine there are others, but a primary error is defined in
|
Ahh right, hmm.. that's a bit unfortunate.. |
I guess the big concern here is backwards compat. Perhaps we should just name the new calls something else and just deprecate the old ones? remove them in the next major version? |
I would also like to clarify the semantics of the old function: the combination of |
To maintain backward compatiblity on function name level and to infer sockaddr type, I would propose merge this PR as is. |
I'm likely not going to get to this till the new year, but if anyone has the motivation, please commit and merge. |
Merged with doc update. |
I'm opening this as an RFC. Please let me know what your thoughts are.
It is generally accepted that EOF errors in
Network
were a mistake.Using exceptions for control flow is an anti-pattern in the Haskell
community. While we are in the process of introducing epoch breaking
changes it makes sense to attempt to remove these historic accidents.
There should really be no perceived change for users of
Network.ByteString(.Lazy).recv
, howeverrecvFrom
does changebehavior. There are two key differences in
recvFrom
:(0, address)
on an EOF.getPeerName
on an EOF. Thishas some implications for performance, and such may be controversial.
The second point poses a question. Does the return type of
SocketAddress sa => IO (Int, sa)
make sense forrecvBufFrom
?