feat(net, driver, buf): support socket state#861
feat(net, driver, buf): support socket state#861George-Miao merged 2 commits intocompio-rs:masterfrom
Conversation
3dca1ed to
afeda66
Compare
|
The state of the socket(empty or non-empty) cannot directly be stored inside of Socket as all the receive methods operate on &self and Socket needs to be thread safe(both Send and Sync), therefore we cant get away with Cell. The options are to either use an AtomicBool to store the state which could turn out to be very expensive for the caller or expose identical receive methods that returns the result along with the state. If we pick the latter, I then think we could either use Option directly or introduce a public enum in compio-driver that holds the Empty NonEmpty and Unsupported state. Those identical methods would then return a tuple consisting of that enum and the result of the receive operation. I have currently added the extra methods that return a tuple consisting of an |
|
So... Since |
1f21b1e to
b04b763
Compare
Berrysoft
left a comment
There was a problem hiding this comment.
Let's add some methods to SocketState to simplify the code, maybe a pair of set & get:
fn set(&self, v: Option<bool>);
fn get(&self) -> Option<bool>;Don't forget adding sock_nonempty for UdpSocket, TcpStream, and UnixStream.
b04b763 to
a8fe226
Compare
|
install-action fails on windows while running CI. |
a8fe226 to
6ee1e35
Compare
|
Used the following method to avoid two conditional checks for the same thing, one while de-structuring the fn set(&self, state: &compio_driver::Extra); |
|
I'm thinking maybe we can add a sys mod under socket based on Something like this: https://github.com/compio-rs/compio/blob/master/compio-net/src/resolve/mod.rs#L1-L9 |
Yeah windows CI is always kind of flaky. Just rerun and you're good. |
George-Miao
left a comment
There was a problem hiding this comment.
LGTM. We can just merge this one if you don't feeling like implementing the sys mod. I can do that after this is merged.
|
I am happy to do it. I was just reading and figuring things out. |
89a11da to
9c37042
Compare
This PR adds support for retrieving socket state that is whether it was empty or non-empty after the receive operation.
Closes #855