Commit Graph
7 Commits
Author SHA1 Message Date
Austin ffa6a871f7 Feature: Datagram Packet Info (#1888)
* Break out control message parsing by IP version

* Add shims for Darwin packet info

* Add shims for Linux packet info

* Add channel option for receiving datagram packet info

* Add NIOPacketInfo to AddressedEnvelope.Metadata

* Pipe up packet info channel option to receive path

* Add NIOPacketInfo info and fix backwards compatability

* Document packet info socket options

* Cleanup packet info control message parsing

* Add packet info and ECN combined tests

* Find real interface index during NIOPacketInfo tests

* Add PacketInfo tests to Linux tests
2021-07-08 11:04:53 +01:00
Cory Benfield 4bf379b156 Implement faster pointer rebasing. (#1696)
Motivation:

I recently discovered that UnsafeRawBufferPointer.init(rebasing:) is
surprisingly expensive, with 7 traps and 11 branches. A simple
replacement can make it a lot cheaper, down to two traps and four
branches. This ends up having pretty drastic effects on
ByteBuffer-heavy NIO code, which often outlines the call to that
initializer and loses the ability to make a bunch of site-local
optimisations.

While this has been potentially fixed upstream with
https://github.com/apple/swift/pull/34879, there is no good reason to
wait until Swift 5.4 for this improvement.

Due to the niche use-case, I didn't bother doing this for _every_
rebasing in the program. In particular, there is at least one
UnsafeBufferPointer(rebasing:) that I didn't do this with, and there are
uses in both NIOTLS and NIOHTTP1 that I didn't change. While we can fix
those if we really need to, it would be nice to avoid this helper
proliferating too far through our codebase.

Modifications:

- Replaced the use of URBP.init(rebasing:) with a custom hand-rolled
  version that avoids Slice.count.

Result:

Cheaper code. One NIOHTTP2 benchmark sees a 2.9% speedup from this
change alone.
2020-11-30 10:02:15 +00:00
Saleem Abdulrasool 20e63d07dc NIO: extract control message handling into a separate protocol (#1678)
These are part of the BSD sockets APIs, but not directly related to the
socket interfaces.  Create an extension point to permit the different
platforms to shuffle their implementation into place.  This provides a
nicer spelling for the functions and enables the codepaths on Windows as
well.
2020-10-19 16:18:57 +01:00
Cory Benfield acf5465b5e Avoid including non-modular headers. (#1605)
Motivation:

We included netinet/ip.h in CNIODarwin, which unfortunately is not
modularised. This causes issues when using SwiftPM to create xcodeproj
files. There's no real reason to do it this way, when we can just as
easily abstract the issue.

Modifications:

- Moved netinet/ip.h to the .c file instead of the .h.
- Defined some exported namespaced integers to correspond to the macros.
- Performed platform abstraction in Posix instead of everywhere.

Result:

- Creating xcodeproj files should be fine.
2020-07-31 09:57:25 +01:00
Peter Adams 496d697df7 Don't use deadbeef for dead pointers. (#1604)
Motivation:

It turns out using this overflows Int on "Any iOS Device"

Modifications:

Switch the first d to a 7.

Result:

Code will compile on "Any iOS Device".
2020-07-30 18:27:26 +01:00
Peter Adams 86ce6aae8b Explicit Congestion Notification for UDP (#1596)
Motivation:

Network congestion can be controlled without packet loss if explicit congestion notification messages are understood.

Modifications:

Receive single and vector paths to get notification and surface.
Send paths for both single and vector sends.
Round trip tests.
Storage for control messages added in a reusable way.

I have tested allocations and they seem to be fine but the allocation tests for vector read and write were not stable enough to sensibly add to CI.

Result:

Explicit Congestion Notifications can be both sent and received.
2020-07-17 16:25:09 +01:00
Peter Adams f12803dbf1 Add methods to create and parse cmsghdr structured data. (#1590)
Motivation:

cmsghdrs can be used to send an receive extra data on UDP packets.
For example ECN data.

Modifications:

Map in Linux and Darwin versions of cmsghdr macros as functions.
Create strctures for holding a received collection; parsing ecn
data from a received collection and building a collection suitable
for sending.

Result:

Functions to manipulate cmsghdr and data exist.
2020-07-14 12:29:31 +01:00