Commit Graph

50 Commits (master)

Author SHA1 Message Date
luojia65 c111bee3b6 Code format using `cargo fmt` 2021-10-27 16:35:05 +08:00
luojia65 a714def8d0 Add lint `#[must_use]` for ring buffer functions.
This lint is in stable Rust now: https://github.com/rust-lang/rust/issues/43302.
These changes are noted according to code comment from @whitequark.
Some test cases and functions are altered due to changes of #[must_use].
2021-10-27 16:26:57 +08:00
Thibaut Vandervelden 6a27136047 Fix clippy lints 2021-08-18 16:05:50 +02:00
Dario Nieuwenhuis 98fe17890a rustfmt 2021-06-27 09:31:59 +02:00
Ryan Summers 421870ee75 Restructuring to allow-unused 2021-06-09 11:30:02 +02:00
Ryan Summers 2fb5880628 Fixing feature flag 2021-06-09 11:13:56 +02:00
Ryan Summers 84866f8f69 Updating packet buffer clear to be UDP-only 2021-05-31 18:07:19 +02:00
Ryan Summers fa77ddd836 Updating UDP close to clear RX/TX buffers 2021-05-31 18:04:02 +02:00
Dario Nieuwenhuis d64c8593f0 Add defmt logging support 2021-04-01 01:30:47 +02:00
Dario Nieuwenhuis c09ca370b2 Simplify Socket lifetimes 2021-01-09 01:59:02 +01:00
Alex Crawford 6b524dc74d Various cleanups
These were flagged by `cargo clippy`:

    warning: using `clone` on a `Copy` type
    warning: passing a unit value to a function
    warning: redundant closure found
    warning: called `iter().cloned().collect()` on a slice to create a
             `Vec`. Calling `to_vec()` is both faster and more readable
2021-01-04 10:39:06 -08:00
Dario Nieuwenhuis 45df367d7e More clippy fixes. 2021-01-04 01:19:20 +01:00
Alex Crawford ec5c924d88 Prefer elided lifetimes
These were flagged by `cargo clippy`:

    warning: explicit lifetimes given in parameter types where they
             could be elided (or replaced with `'_` if needed by type
             declaration)
2020-12-27 17:00:03 -08:00
Alex Crawford d2b557e01c Prefer assignment operators
These were flagged by `cargo clippy`:

    warning: manual implementation of an assign operation
2020-12-27 17:00:03 -08:00
Dario Nieuwenhuis 88256dbdcf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +01:00
Gary Guo 18b728ebba Fix packet buffer panic caused by large payload (#332)
When packet buffer's payload buffer does not have enough contiguous
window left, the ring buffer roll over uses an incorrect size
causing the ring buffer pointer not resetting to the head.

When the payload enqueued is larger than 1/2 of the payload ring
buffer, this bug will cause the slice returned by
`PacketBuffer::enqueue` to not match the requested size, and
trigger `debug_assert` in debug profile or size mismatch panic in
`copy_from_slice` when compiled in release profile.
2020-04-14 10:48:31 +02:00
Scott Mabin d7916c9a92 Add capacity methods to all sockets. 2019-11-05 23:07:12 +00:00
Kai Lüke 49e985a66e Implement peek functions for UDP sockets
This needed a peek function for the packet buffer.

Closes: #278
Approved by: whitequark
2019-02-28 00:58:33 +08:00
Kai Lüke 15c6c24a87 Increase number of assembler gaps to 32 for std/alloc targets
Only allowing four missing packets is hurting
performance for large receive windows.

The new value was picked by observing good
performance with 500 kB socket buffers.

Closes: #264
Approved by: whitequark
2018-10-05 18:36:35 +08:00
Kai Lüke 2047aaea28 Only change the assembler state on success
The current hole was always shrinked even if the
packet assembler rejected adding a packet due to
not being able to insert a new hole.

Shrink only after a new hole was added.
Shrinking before or after does not make a difference
because offset + size < hole_size and thus
contigs[index] is not empty, passing the
debug_assert in add_contig_at.

https://github.com/m-labs/smoltcp/issues/261

Closes: #265
Approved by: whitequark
2018-09-22 22:00:14 +08:00
jhwgh1968 ed3862f63b Add iter_data() to Assembler
Closes: #262
Approved by: whitequark
2018-09-01 08:29:59 +08:00
Dan Robertson 276acfb7ef Fix packet buffer enqueue logic error
The size of the contiguous window should be prioritized over the size of
the contiguous window if padding were added.

For example, given the following packet buffer:

  1   2     3
|---|----|------|

If 2 is used and 1 and 3 are empty, enqueing a buffer of size 4 should
be placed in contiguous window 3 and the size of 1 should not cause
any issues in enqueue.

Closes: #247
Approved by: whitequark
2018-06-21 21:04:50 +08:00
Astro e5a3de210c Optimize RingBuffer::enqueue_many_with to an empty buffer.
This optimization makes sure that enqueueing to an empty ring buffer
would never wrap around, in turn ensuring that enqueueing to an empty
packet buffer would never use more than one metadata entry.
Right now, pushing buffer-sized packets into a packet buffer requires
at least two metadata entries, which is surprising and wasteful.
2018-05-24 22:00:00 +00:00
whitequark 485b46a5e6 fn PacketMetadata::empty() → const PacketMetadata::EMPTY.
Fixes #181.
2018-03-24 03:23:37 +00:00
whitequark 41de9c7ee0 Distinguish PacketBuffer running out of payload space and capacity.
This makes the behavior of UdpSocket resemble that of RawSocket.
2018-02-22 11:57:39 +00:00
whitequark c474d0c32e Factor out storage::PacketBuffer from socket::UdpSocket. 2018-02-22 11:34:58 +00:00
Philipp Oppermann ed2dcaaff9 Use separate metadata and payload buffers for UDP sockets.
Co-authored-by: Dan Robertson <danlrobertson89@gmail.com>
2018-02-22 06:33:11 +00:00
Dan Robertson b653a6e421 Fix documentation warnings.
- There are several warnings that are thrown when running `cargo doc`. Fix
  these warnings.
- Convert all module documentation to use /*! for consistency.
2018-01-05 19:38:23 +00:00
whitequark b2c2214725 Convert all assert!s not documented as panics into debug_assert!s.
Document the rest.
2017-12-22 20:38:54 +00:00
whitequark fa636b9fcb Style fixes. 2017-10-24 18:08:22 +00:00
whitequark ba93552ccd Fix many warnings. 2017-09-25 00:55:54 +00:00
whitequark 4826d37c45 Allow disabling any of: raw, TCP or UDP sockets. 2017-09-25 00:20:22 +00:00
whitequark 8e13333988 Remove all remnants of the collections feature. 2017-09-22 20:40:13 +00:00
whitequark 075a2ebb83 Make sure all side-effectful RingBuffer methods are #[must_use].
Some of them already use Result, but the ones that can return
an empty slice (or a slice shorter than requested) also must have
their return value (at least) checked.
2017-09-22 17:08:46 +00:00
whitequark 0bbab2aeed Add RingBuffer::{enqueue_allocated,dequeue_allocated}.
These should be used instead of enqueue_many because they do not
require the caller to handle wraparound explicitly.
2017-09-22 17:04:56 +00:00
whitequark e6bf27d078 Add RingBuffer::{read_allocated,write_unallocated}. 2017-09-22 16:23:37 +00:00
whitequark a9d6a9b7b8 Fix a few warnings. 2017-09-22 10:06:40 +00:00
whitequark 7a2cd7842d Implement reassembly of out-of-order TCP segments. 2017-09-22 10:06:40 +00:00
whitequark ba2d7f483a Implement a buffer (re)assembler. 2017-09-20 20:46:15 +00:00
whitequark be0dcb145c Fix warnings. 2017-09-15 06:05:41 +00:00
whitequark e8788be3a0 RingBuffer::{empty,full}→is_{empty,full}.
Query methods in Rust conventionally start with the "is" prefix.
2017-09-08 23:23:40 +00:00
whitequark 844843c4bc Remove RingBuffer::set_len().
set_len() with a positive length change is better represented
with enqueue(), and set_len() with a negative length change
is not really a valid operation on its own.
2017-09-07 23:54:39 +00:00
whitequark 1102bd94e7 Refactor the "random access" ring buffer interface. 2017-09-07 23:47:42 +00:00
whitequark 5dc0353b2a Refactor the "continuous" ring buffer interface.
This also makes TcpSocket::{send,recv}_slice slightly more efficient
in case when the slice wraps around the corresponding buffer,
halving the necessary amount of calls.
2017-09-07 21:17:31 +00:00
whitequark a9719f4a13 Merge the TCP ring buffer and generic ring buffer.
This adds a few methods to RingBuffer that don't quite fit into
its interface (the slice ones), but we can fix that later.
2017-09-07 00:09:34 +00:00
whitequark 996389d653 Compute soft deadline in poll() and use nonblocking sockets.
Before this commit, anything that touched RawSocket or TapInterface
worked partly by accident and partly because of a horrible crutch
that resulted in massive latencies as well as inevitable packet loss
every time an ARP request had to be issued. Also, there was no way
to use poll() other than by continuously calling it in a busy loop.

After this commit, poll() indicates when the earliest timer expires,
and so the caller can sleep until that moment (or until packets
arrive).

Note that there is a subtle problem remaining: every time poll()
is called, every socket with a pending outbound packet whose
IP address doesn't correspond to a MAC address will send a new
ARP request, resulting in potentially a whole lot of such requests.
ARP rate limiting is a separate topic though.
2017-08-29 19:47:11 +00:00
whitequark ad12573f62 Rework and test UDP sockets.
Before, errors such as packets not fitting into a buffer would have
resulted in panics, and errors such as unbound sockets were
simply ignored.
2017-07-27 22:30:01 +00:00
whitequark 8d8a4ea583 Get rid of Result<_, ()>.
The use of this type has several drawbacks:
  * It does not allow distinguishing between different error
    conditions. In fact, we wrongly conflated some of them
    before this commit.
  * It does not allow propagation via ? and requires manual use
    of map_err, which is especially tiresome for downstream code.
  * It prevents us from expanding the set of error conditions
    even if right now we have only one.
  * It prevents us from blanket using Result<T> everywhere
    (a nitpick at most).

Instead, use Result<T, Error> everywhere, and differentiate error
conditions where applicable.
2017-07-27 13:55:47 +00:00
whitequark 776ca6eada Rename RingBuffer::{dequeue_mut→dequeue}, remove RingBuffer::dequeue.
There's nothing dequeue can do that dequeue_mut cannot.
2017-07-24 05:30:22 +00:00
Egor Karavaev c1c4ed68c5 Factor out the `RingBuffer` container. 2017-06-21 02:50:10 +00:00