Comments (7)
You can use the std::io::Read
implementation for this. It makes a read(2)
system call instead of send(2)
, but those behave the same way with the arguments we pass.
As for the recv
method itself, it will continue to use to uninitialised bytes to not force the caller to initialise them only to overwrite them again. Using the readbuf API would be nice, but that's not stable, so not usable by this crate.
from socket2.
thanks for your reply. I should have, but forgot to clarify that, what I needed is .recv_from()
which is in the same boat as .recv()
(and doc forwarded to .recv()
) .
Currently I'm using read()
, but won't be able to get the source IP.
from socket2.
For recv_from
we don't have a version that uses &[u8]
. We've had attempts to to add them, e.g. #246, but it basically came down to coping all the recv methods only to call the version with uninitialised bytes, so it wasn't worth the maintenance burden.
from socket2.
I guess it was probably a tough decision for you the maintainers, but I was curious how much performance gain of the version with uninitialized buffer. Among all socket2
users, how many percent of users prefer to use this version of uninitialized buffer?
It's probably impossible to change it back, but I just felt it's not a worthy trade-off, i.e. disabling / crippling common use cases for (IMO) edge cases.
from socket2.
I guess it was probably a tough decision for you the maintainers, but I was curious how much performance gain of the version with uninitialized buffer. Among all
socket2
users, how many percent of users prefer to use this version of uninitialized buffer?
I don't really have performance test ready, but here an example of using uninitialised memory for HTTP headers: 5225225/hyper@325b7e5 that saves ~5%.
It's probably impossible to change it back, but I just felt it's not a worthy trade-off, i.e. disabling / crippling common use cases for (IMO) edge cases.
It's not really the common case though. Most users of this library use advance features, where not initialising memory is considered the common case.
from socket2.
I don't really have performance test ready, but here an example of using uninitialised memory for HTTP headers: 5225225/hyper@325b7e5 that saves ~5%.
5% seems to me really not worth changing a safe Rust code to unsafe Rust code, especially if in the grand scheme of a bigger system.
from socket2.
5% is a lot actually. That's massive improvement. Especially for a 1 line change that is documented as supported by socket2.
I think the best way forward is the read buf, which is still unstable. So closing in favour of #366.
from socket2.
Related Issues (20)
- QUESTION: How to special `laddr` when dialing connection? HOT 3
- Android support HOT 3
- don'tassign8080 port
- Currently socket2 has no way to set the DF bit on packets. The attached patch adds it. HOT 3
- Error: BoxSend(Os { code: 98, kind: AddrInUse, message: "Address already in use" }) HOT 2
- How to read EventExtra from the event? HOT 2
- socket() always fails on WSL1 due to unsupported SOCK_CLOEXEC flag HOT 5
- Support for {recv,send}mmsg HOT 2
- New release HOT 1
- socket error HOT 1
- Provide `bind_device_by_index_v{4|6}` methods for linux. HOT 7
- ESP-IDF compiation error HOT 4
- Possible to publish a new patch release? HOT 4
- Hyper-util on xtensa esp32 HOT 1
- Not able to create IPv6 raw socket HOT 4
- Add suffix to protocol specific Socket methods
- Is there any way to get the IP header content on the socket created with Type::DGRAM? HOT 2
- Add Layer2 protocols HOT 1
- Add rest of socket options for unix HOT 2
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 socket2.