Commit Graph
19 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
buttafaceandCory Benfield 44d67ba4e0 Update and finish Android port. (#1695)
Motivation:

Be able to run and test swift-nio on Android.

Modifications:

- Remove the custom ifaddrs and use the one from the Android NDK instead.
- Enable a bunch of conditionally-compiled code for Android.
- Add a handful of constants and other Android declarations.
- Cast some types because of mismatches specific to Android.

Result:

Most tests pass on Android AArch64 and ARMv7.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-11-27 11:16:11 +00:00
Saleem Abdulrasool 366850acdd NIO: implement sendmsg and recvmsg on Windows (#1674)
`WSASendMsg` and `WSARecvMsg` are not directly accessible to use.
Instead, one must perform an IOCTL on the socket to retrieve the
extension point and then use that function pointer to perform the
operation.  Use this to implement the functionality on Windows.
2020-10-20 08:22:20 +01: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
Saleem Abdulrasool 1cdbf763fb NIO: reflow some comments (NFC) (#1677) 2020-10-14 18:05:40 +01:00
Saleem Abdulrasool 5d57ca0f3a NIO: implement cleanupSocket(unixDomainSocketPath:) for Windows (#1654)
* NIO: implement `cleanupSocket(unixDomainSocketPath:)` for Windows

This adds an initial implementation for the UDS clean up path on
Windows.  Unlike Unix, you cannot simply `stat` the destination to
determine if it is a UDS endpoint.

One must first create a file handle from the path.  Assuming that we are
able to create that, we should verify that the file that we are dealing
with is a not a disk type as the subsequent checks will fail.  Now, we
can use the file handle to query the information of the file.  This will
allow us to determine if it is a reparse point.  If not, it is
impossible for it to be a UDS as a UDS endpoint is a reparse point with
the tag IO_REPARSE_TAG_AF_UNIX.  Once we know that we have a reparse
point, we must query the kernel for information about it via the
`DeviceIoControl` system call (perform an ioctl in Unix speak).  The
returned buffer's tag will identify if we have a UDS.

For the next dance, we must now _close_ the handle as the handle being
left open will cause the subsequent `DeleteFileW` to fail due to there
being an open handle.  Once we have cleaned up the file handle that we
created, we can safely attempt to remove the file via `DeleteFileW`.

This should hopefully be sufficiently robust from possible error
scenarios for the removal of a UDS endpoint.

* NIO: improve the UDS cleanup path on Windows

Instead of doing the complex close-handle dance, instead prefer
`SetFileInformationByHandle` which:
1. avoids a second UTF-8 -> UCS-2 conversion
2. avoids the need for the handle closing dance
3. avoids a third re-query of the handle
4. enables us to use "POSIX" deletion semantics (file is immediately
   removed from the namespace but data streams are left intact)

This comes at the cost of being Windows 10 centric, which I find a
reasonable trade-off as Windows 7 has been EOL'ed by Microsoft, and more
importantly, Unix Domain Sockets are only available on Windows 10!

Thanks to @adierking for the reminder about SetFileInformationByHandle!
2020-10-05 12:49:28 +01:00
Cory Benfield c3e2359c55 Minor cleanups of Windows compatability code. (#1663)
Motivation:

Cleanup some noise that came in with some previous Windows compat
patches.

Modifications:

- Move INVALID_SOCKET to NIOBSDSocket, and refer to it by a better name
  there.
- Comment in an empty block to indicate that it's supposed to be empty.

Result:

Bit cleaner code.
2020-09-30 19:55:21 +01:00
Saleem Abdulrasool 2d913d65af NIO: make BSDSocketAPI build on Windows (#1657)
These interfaces use types from WinSDK to re-export them in the NIO
namespace.  Import the types required.  This allows us to build this
file on Windows again.
2020-09-25 18:30:17 +01:00
f7dc232e0c NIO: remove poll from the _BSDSocketProtocol protocol (#1635)
This removes the testing-only API of `poll` on Windows which does not
have a semantic compatible poll.

Co-authored-by: David Evans <d.evans@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-21 10:31:13 +01:00
Saleem Abdulrasool 36b19f98c3 NIO: repair the build after e3508b0d0 (#1636)
`ssize_t` is not a standard type and does not have a portable Swift
spelling.  Use `size_t` which is compatible in size, but is signed
instead.  This is needed in order to be compatible to more standard
conforming environments like Windows.
2020-09-21 09:36:18 +01:00
Peter Adams ee8acd9b3d Use sendmsg rather than sendto to send UDP data. (#1587)
Motivation:

sendmsg is more powerful - this is paving the way for
Explicit Congestion Notifications to be sent.

Modifications:

Replace the sendto system call with sendmsg up to DatagramChannel.

Result:

Sendmsg will be used to send UDP data.
2020-07-10 13:41:13 +01:00
Cory Benfield e3508b0d04 Move DatagramChannel over to using recvmsg. (#1473)
Motivation:

When attempting to obtain metadata about a read, we need to use recvmsg
in order to obtain that data. While we're using recvmmsg for vector
reads right now, our scalar reads use recvfrom, which does not provide
us with that metadata.

While we're not extracting metadata right now, we may well do so in
future, so we can apply it now.

Modifications:

- Move recvfrom usage to recvmsg.

Result:

We'll be able to extend recvmsg to extract metadata.
2020-07-08 09:10:32 +01:00
Saleem Abdulrasool 5de1e41310 NIO: Implement BSD sockets APIs for Windows (#1471)
Motivation:

Split out the internal implied BSD socket API code to allow alternative implementations of these interfaces on other platforms.

Modifications:

- Split the code apart.
- Provide POSIX and Windows implementations of the BSD socket API.

Result:

Should be easier to run NIO unmodified on Windows.
2020-07-03 10:14:36 +01:00
Peter AdamsandCory Benfield 4851816b65 Channel option to enable ECN reporting (#1506)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-06-02 16:36:17 +01:00
Cory Benfield 30265d69a8 Adjust names of BSDSocket option values. (#1510)
Motivation:

The names of most of the BSD socket option values were brought over into
their NIO helper properties, with their namespace removed. This vastly
increases the risk of collision, particularly for things like TCP_INFO,
which just became .info.

Modifications:

- Added the prefixes back, e.g. `.info` is now `.tcp_info`.
- Renamed socket type `.dgram` to `.datagram`, as this is the nice clean
  API and we should use nice clean names.

Result:

Better APIs
2020-05-11 15:13:58 +01:00
Saleem Abdulrasool c7ab09013d Add BSDSocket.AddressFamily (#1469)
This finishes up the encapsulation that is required to ensure that we
are not leaking libc interfaces to clients but instead vend an
enumeration that they can use.  The enumeration is open so although we
may not have the full interface enumerated, users will not be prevented
from using alternate values.
2020-04-07 22:17:30 +01:00
Saleem Abdulrasool 2e2dcc25ca Add BSDSocket.ProtocolFamily (#1468)
This encapsulates the enumeration of protocol families rather than
relying on the underlying C library to provide the value.
2020-04-07 11:45:20 +01:00
Saleem Abdulrasool 37b48094ba Add BSDSocket.SocketType to represent the socket type (#1467)
This adds a new enumeration which encapsulates the socket type values.
This enables ports to provide the same surface with a different name as
necessary.
2020-04-03 17:16:48 +01:00
Saleem AbdulrasoolandCory Benfield bcc180dab6 Add new BSDSocket namespace (#1461)
* NIO: Add new `BSDSocket` namespace

This starts the split of the POSIX/Linux/Darwin/BSD interfaces and the
BSD Socket interfaces in order to support Windows.  The constants on
Windows are not part of the C standard library and need to be explicitly
prefixed.  Use the import by name to avoid the `#if` conditions on the
wrapped versions.  This will allow us to cleanly cleave the dependency
on the underlying C library.

This change adds a `BSDSocket.OptionLevel` and `BSDSocket.Option` types
which allow us to get proper enumerations for these values and pipe them
throughout the NIO codebase.

* Apply suggestions from code review

Co-Authored-By: Cory Benfield <lukasa@apple.com>
2020-04-02 19:06:48 +01:00