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

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

#9 in #rotor

Download history 9/week @ 2024-08-29 5/week @ 2024-09-05 6/week @ 2024-09-12 13/week @ 2024-09-19 16/week @ 2024-09-26 12/week @ 2024-10-03 3/week @ 2024-10-10 4/week @ 2024-10-17 3/week @ 2024-10-24 10/week @ 2024-10-31 3/week @ 2024-11-07 3/week @ 2024-11-14 10/week @ 2024-11-21 8/week @ 2024-11-28 19/week @ 2024-12-05 49/week @ 2024-12-12

87 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
~83K SLoC