vapor-community / sockets

🔌 Non-blocking TCP socket layer, with event-driven server and client.
MIT License
575 stars 54 forks source link

add readn func to TCPReadableSocket #110

Closed codetalks-new closed 7 years ago

codetalks-new commented 7 years ago

as TCP is a stream protocol, At many times, one data packet may be send within different segment. so a readn func would help us a lot. advices need to improve it.

loganwright commented 7 years ago

@banxi1988 there's some conflicts because we've done some reversions to workaround bugs we were getting on linux w/ dispatch apis. Those branches are saved to add back in the future, but I'd like to understand this PR better and see if we can't get it in for our next release.

Can you elaborate a bit on how readn differs from read here?

codetalks-new commented 7 years ago

Hi, in theory, the recv func without MSG_WAITALL flag may return before fully recv the specified number of bytes. so in sometimes I want to use readn func to ensure (or to wait) for all the required bytes.

tanner0101 commented 7 years ago

@banxi1988 could you explain the use case for this method? If you want x amount of bytes why wouldn't you just call stream.read(max: x) ?

loganwright commented 7 years ago

@banxi1988 we're starting beta tags, I think what you have could be additive, but if you could respond to Tanner's question and give a good explanation to us about what is additive about this, much appreciated 👍

codetalks-new commented 7 years ago

@mjmsmith @tanner0101 Hi, I decide to close this PR, because,MSG_WAITALL socket options may be more suitable.