Comments (3)
This is tcp-server example, would_block maybe occur after OK(n),and previously read bytes will be dropped due to would_block break. Is it possible to continue? Is would_block final state of the tcpstream read operation?
I'm not entirely sure what you mean with your first question. But to answer the second one, no a WouldBlock
error is not the final state of a TcpStream
, it simply means that currently all bytes are read. So for example the peer of the connection send an entire request and is now waiting for a response. If a read call returns Ok(0)
it means all bytes are read and the peer is not going to send more.
from mio.
I'm not entirely sure what you mean with your first question. But to answer the second one, no a
WouldBlock
error is not the final state of aTcpStream
, it simply means that currently all bytes are read. So for example the peer of the connection send an entire request and is now waiting for a response. If a read call returnsOk(0)
it means all bytes are read and the peer is not going to send more.
I have a very simple self-defined protocol just like this:
|magic_code|body_length|body|
Client uses body_length 4bytes to tell the server how many bytes need to read. Some very rarely would_block error occurs while server have not read the entire body bytes, for example, body_length is 4000, but server only read 1500 bytes from tcpStream and meanwhile would_block error returned by tcpStream.read().
Is it supposed that client did not write the entire protocol body bytes?
from mio.
I have a very simple self-defined protocol just like this: |magic_code|body_length|body| Client uses body_length 4bytes to tell the server how many bytes need to read. Some very rarely would_block error occurs while server have not read the entire body bytes, for example, body_length is 4000, but server only read 1500 bytes from tcpStream and meanwhile would_block error returned by tcpStream.read().
Is it supposed that client did not write the entire protocol body bytes?
It is always possible that not the entire request can be read in a single read
call. It may be that the user didn't send the entire request, but it may also be that kernel split up the buffers and only returned one. You should always be ready for short reads and WouldBlock
"errors", these are always possible. The solution is pretty simple though, put a (non-blocking) loop around the read to ensure your the entire request (do put in a limit! Don't want to read 1TB of data into your memory).
from mio.
Related Issues (20)
- Windows named pipes hits unreachable code during read operation HOT 1
- Can TcpStream be read from a different thread? HOT 1
- Exposing `AsRawHandle` on `Registry` HOT 5
- build failed with wasm-pack HOT 1
- Wait for messages in the error queue HOT 6
- Setup WASM/WASI CI
- get any errors when i use `wasm-pack` command by `mio` HOT 4
- Need switch to not use eventfd on `target_os = "linux"` HOT 4
- Add ESP-IDF framework support
- IoRing support for windows HOT 3
- Has waker check doesn't work with try_cloned Registries HOT 1
- compile time error inside `poll.rs` HOT 3
- poll: Optimize locks and allocations in the critical path
- Poll(2) implementation follow-ups
- Official ESP-IDF framework support HOT 3
- Make `CompletionPort` public? HOT 7
- No data coming from Poll HOT 8
- Difference behaves between Linux and Windows HOT 2
- How to wait for a socket to be writable? udp / Interest::READABLE | Interest::WRITABLE HOT 6
- could not compile mio due to 44 previous errors HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mio.