YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.snapcast.protocol.FrameReader Class Reference

Reads frames from a stream (the socket of the connection). More...

Collaboration diagram for de.yaacc.snapcast.protocol.FrameReader:
Collaboration graph

Classes

interface  ReadTimeout
 Sets how long the next read of the stream may block (the socket's receive timeout). More...
 

Public Member Functions

 FrameReader (InputStream in, MicroClock clock, long messageDeadlineMillis)
 
 FrameReader (InputStream in, MicroClock clock, long messageDeadlineMillis, ReadTimeout timeout)
 
Frame read () throws IOException, StreamFormatException
 Reads the next frame.
 

Static Public Member Functions

static FrameReader forClient (InputStream in, MicroClock clock, long messageDeadlineMillis, ReadTimeout timeout, int maxChunkBytes)
 A reader for the client side of a connection.
 
static FrameReader forServer (InputStream in, MicroClock clock, long messageDeadlineMillis, ReadTimeout timeout)
 A reader for the server side of a connection (the built-in Snapcast server, issue #330).
 

Detailed Description

Reads frames from a stream (the socket of the connection).

The size of a frame is checked against its cap right after the 26 byte header and before one byte of the body is read; the body buffer starts small and grows with the bytes that really arrive, so a header that promises 8 MiB and then stalls costs 64 KiB; a frame of a type that is not handled is read past in a small buffer.

Time. The socket's read timeout bounds one read; this class adds a deadline for a whole frame, counted from its first byte, so a sender that drips a byte inside every read timeout still ends. A read timeout before the first byte of a frame is passed on as the SocketTimeoutException that it is (nothing was consumed, the caller may read again); inside a frame it is a TIMEOUT error, and with a ReadTimeout the receive timeout inside a frame is the time left of the deadline, not the (possibly short) timeout that was set for waiting. A clean end between two frames is an EOFException, an end inside a frame is TRUNCATED. One reader belongs to one thread.

Constructor & Destructor Documentation

◆ FrameReader() [1/2]

de.yaacc.snapcast.protocol.FrameReader.FrameReader ( InputStream in,
MicroClock clock,
long messageDeadlineMillis )
Parameters
messageDeadlineMillishow long a frame may take from its first byte to its last

Referenced by de.yaacc.snapcast.protocol.FrameReader.forClient(), and de.yaacc.snapcast.protocol.FrameReader.forServer().

Here is the caller graph for this function:

◆ FrameReader() [2/2]

de.yaacc.snapcast.protocol.FrameReader.FrameReader ( InputStream in,
MicroClock clock,
long messageDeadlineMillis,
ReadTimeout timeout )
Parameters
timeoutwhen given, it is called before every read after the first byte of a frame with the time that is left of the message deadline: a stall inside a frame is then tolerated up to the deadline, whatever receive timeout the caller set for the wait before the frame (that one may be short, for example to wake up for a timer). The stall that exceeds it ends as TIMEOUT.

Member Function Documentation

◆ forClient()

static FrameReader de.yaacc.snapcast.protocol.FrameReader.forClient ( InputStream in,
MicroClock clock,
long messageDeadlineMillis,
ReadTimeout timeout,
int maxChunkBytes )
static

A reader for the client side of a connection.

A server sends neither a Hello nor a ClientInfo, so frames of those types are read past by size like unknown ones and never parsed (a flood of them costs a read, not a JSON parse), and a WireChunk larger than maxChunkBytes (the client's budget for chunks that wait; a real chunk is a few KB) is refused before its body is read.

Here is the call graph for this function:

◆ forServer()

static FrameReader de.yaacc.snapcast.protocol.FrameReader.forServer ( InputStream in,
MicroClock clock,
long messageDeadlineMillis,
ReadTimeout timeout )
static

A reader for the server side of a connection (the built-in Snapcast server, issue #330).

A client sends only Hello, Time and ClientInfo: a frame of any other type is read past by size and never parsed, and a frame above 64 KiB is refused before its body is read, so a client cannot make the server buffer a bulk message.

Here is the call graph for this function:

◆ read()

Frame de.yaacc.snapcast.protocol.FrameReader.read ( ) throws IOException, StreamFormatException

Reads the next frame.

Exceptions
SocketTimeoutExceptionwhen the read timed out before the first byte of a frame
EOFExceptionwhen the stream ended before the first byte of a frame
IOExceptionfor any other failure of the stream
StreamFormatExceptionfor a frame that is too large, too slow, cut short or wrong
Here is the call graph for this function:

The documentation for this class was generated from the following file: