|
YAACC - UPNP Client and Server
|
Reads frames from a stream (the socket of the connection). More...

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). | |
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.
| de.yaacc.snapcast.protocol.FrameReader.FrameReader | ( | InputStream | in, |
| MicroClock | clock, | ||
| long | messageDeadlineMillis ) |
| messageDeadlineMillis | how 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().

| de.yaacc.snapcast.protocol.FrameReader.FrameReader | ( | InputStream | in, |
| MicroClock | clock, | ||
| long | messageDeadlineMillis, | ||
| ReadTimeout | timeout ) |
| timeout | when 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. |
|
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.

|
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.

| Frame de.yaacc.snapcast.protocol.FrameReader.read | ( | ) | throws IOException, StreamFormatException |
Reads the next frame.
| SocketTimeoutException | when the read timed out before the first byte of a frame |
| EOFException | when the stream ended before the first byte of a frame |
| IOException | for any other failure of the stream |
| StreamFormatException | for a frame that is too large, too slow, cut short or wrong |
