#stream #rotor #tcp-socket #sockets #mio

rotor-stream

The stream abstration on top of rotor. This is the easiest way to build a protocol on top of TCP (Unix sockets) with rotor

6 releases (3 breaking)

Uses old Rust 2015

0.6.2 Mar 30, 2016
0.6.1 Mar 28, 2016
0.5.1 Mar 3, 2016
0.4.0 Feb 10, 2016
0.1.0 Jan 4, 2016

#5 in #rotor

Download history 22/week @ 2023-11-20 17/week @ 2023-11-27 1/week @ 2023-12-04 8/week @ 2023-12-11 16/week @ 2023-12-18 12/week @ 2023-12-25 19/week @ 2024-01-08 14/week @ 2024-01-15 9/week @ 2024-01-22 6/week @ 2024-02-05 16/week @ 2024-02-12 19/week @ 2024-02-19 37/week @ 2024-02-26 38/week @ 2024-03-04

111 downloads per month
Used in 4 crates

MIT license

47KB
973 lines

Rotor Stream

Status:Alpha
Dependencies:rotor, mio, netbuf

A stream abstraction based on MIO. Features:

  • State machine-based implementation (as usually in rotor)
  • Uses netbuf for buffering, buffer has contiguous data slice (easy parsing)
  • Input data abstractions: read-x-bytes, read-until-delimiter
  • Perfect for request-reply style protocols
  • Independent of whether it's client or server, tcp or unix sockets
  • (TODO) should work on top of SSL later

lib.rs:

Stream abstraction for rotor

The crate provides:

  • Buffering for network sockets
  • Simple abstractions like read N bytes, read until '\n'
  • Persistent (auto-reconnecting) client connections
  • Abstraction for accepting connection on server-side

Assumptions for streams:

  1. You read data by length-prefixed or fixed-string-delimited chunks rather than byte-by-byte
  2. Each chunk fits memory
  3. Your data stream is not entirely full-duplex: while you can read and write simultaneously, when you apply pushback (i.e. waiting for bytes to be flushed), you can't do reads [*]

[*] This matches HTTP perfectly, and most bidirectional interactive workflows (including based on websockets). But for some cases may be hard to implement. One such case is when you need to generate some output stream (you can't buffer it), and have to parse input stream at the same time.

Dependencies

~4.5MB
~80K SLoC