-
Notifications
You must be signed in to change notification settings - Fork 189
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
Add safe modules #211
Add safe modules #211
Conversation
Add a note that sending data to or receiving data from closed socket in unsafe. See haskell#169
LGTM. I would like to ask @winterland1989 to check if conflicts against proposals in #201 exist. |
import Data.Word (Word8) | ||
import Foreign.Ptr (Ptr) | ||
|
||
{-# WARNING send "Use send defined in \"Network.Socket.ByteString.Safe\"" #-} |
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.
Does it make sense to introduce new String
variants that immediately have a warning? If we choose to introduce these then they most definitely must have a warning. The alternative is to not provide them in the first place.
I assume the argument for providing them is that a new-comer might be confused and frustrated when they don't find them. The converse of this is that the existing String
functions are already well documented as being obsolete and introducing new String
functions could cause more confusion and a maintenance burden.
I'd rather not continue to contribute to the "String
problem", so I'd vote against these variants.
Some minor quibbles, but this is looking pretty solid. |
Oh also, I'd like to see haddock documentation put in place for all of these new modules. Nothing fancy, likely the previous documentation can be copied over with minor tweaks. Thanks! |
I'm in favor of document improvement but minimal API change now, add a simple
My head went 180 degree since i worked with |
@winterland1989 You raise some great points. The utility of a high order function is certainly greater than introducing safe modules that must be adjusted every time an api changes, etc. The benefit that So the question then becomes weighing the benefits and costs: modulespro:
con:
functionpro:
con:
The middle path is introducing the bike-shed: |
Yeah, I don't think another module is really necessary, but let's wait @kazu-yamamoto 's judgement on this. In fact network's existing module need more care: cleaning CPPs, adding document etc. |
I think
|
AFAICT, safe operations are only needed when
|
@winterland1989 I think you misunderstand the motivation. Please read #169. |
Sorry for missing the context, but from the linked issue, the problem is that warp's reaper/http-client's timeout are closing Bottom line: I'm still in favor of documenting about protecting |
To make my point clear, i propose: -- | If you're operating `Socket` in multithread environment,
-- for example, use a timeout thread to close `Socket`. you have to
-- make sure `Socket` is opened before read/write, 'withConnectedSocket'
-- will run your action if `Socket` is still 'Connected', otherwise
-- return the 'Socket' status instead.
--
-- Note, this will block other thread which try to close `Socket` by locking
-- the status `MVar`.
withConnectedSocket :: Socket -> (Socket -> IO a) -> IO (Either SocketStatus a)
withConnectedSocket sock@(MkSocket _ _ _ _ statusVar) act =
withMVar statusVar $ \status ->
case status of
Connected -> act sock
_ -> return (Left status) I prefer dealing with |
@winterland1989 I agree on your point of utilizing @kazu-yamamoto Creating |
We could also further abstract to the substrate:
We can then build from there with connected, bound, listening, etc. |
Two initial points:
What's needed to close #169 and make a release? My purpose in doing this was to get a version of I can either:
|
I think that we merged necessary documentation updates. Let's release the new version first. |
This document made an interesting point: It seems |
I close this in favor of #212. |
Closes out #169 according to the plan discussed there. This builds on @Yuras' work.