Prepare to add support for other messages. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- src/spice-streaming-agent.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp index 80e3408..d72c30b 100644 --- a/src/spice-streaming-agent.cpp +++ b/src/spice-streaming-agent.cpp @@ -77,10 +77,11 @@ static int have_something_to_read(int timeout) return 0; } +static int read_stream_start_stop(uint32_t len); + static int read_command_from_device(void) { StreamDevHeader hdr; - uint8_t msg[64]; int n; std::lock_guard<std::mutex> stream_guard(stream_mtx); @@ -93,17 +94,26 @@ static int read_command_from_device(void) throw std::runtime_error("BAD VERSION " + std::to_string(hdr.protocol_version) + " (expected is " + std::to_string(STREAM_DEVICE_PROTOCOL) + ")"); } - if (hdr.type != STREAM_TYPE_START_STOP) { - throw std::runtime_error("UNKNOWN msg of type " + std::to_string(hdr.type)); + + switch (hdr.type) { + case STREAM_TYPE_START_STOP: + return read_stream_start_stop(hdr.size); } - if (hdr.size >= sizeof(msg)) { - throw std::runtime_error("msg size (" + std::to_string(hdr.size) + ") is too long " + throw std::runtime_error("UNKNOWN msg of type " + std::to_string(hdr.type)); +} + +static int read_stream_start_stop(uint32_t len) +{ + uint8_t msg[256]; + + if (len >= sizeof(msg)) { + throw std::runtime_error("msg size (" + std::to_string(len) + ") is too long " "(longer than " + std::to_string(sizeof(msg)) + ")"); } - n = read(streamfd, &msg, hdr.size); - if (n != hdr.size) { + int n = read(streamfd, &msg, len); + if (n != len) { throw std::runtime_error("read command from device FAILED -- read " + std::to_string(n) + - " expected " + std::to_string(hdr.size)); + " expected " + std::to_string(len)); } streaming_requested = (msg[0] != 0); /* num_codecs */ syslog(LOG_INFO, "GOT START_STOP message -- request to %s streaming\n", -- 2.14.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel