> > Signed-off-by: Lukáš Hrázký <lhrazky@xxxxxxxxxx> > --- > src/spice-streaming-agent.cpp | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp > index aeee5d3..b88225f 100644 > --- a/src/spice-streaming-agent.cpp > +++ b/src/spice-streaming-agent.cpp > @@ -79,6 +79,15 @@ static int have_something_to_read(int timeout) > return 0; > } > > +static void read_message(void *msg, size_t len) > +{ > + size_t n = read(streamfd, msg, len); > + if (n != len) { > + throw std::runtime_error("Reading message from device failed: read " > + std::to_string(n) + > + ", expected " + std::to_string(len)); > + } > +} > + Why not for symmetry a read_all handling EINTR and partial reads? I think is also a more or less straight forward copy of the write_all. I would pass the "int fd" for reuse as a low level routine. > static void handle_stream_start_stop(uint32_t len) > { > uint8_t msg[256]; > @@ -87,11 +96,8 @@ static void handle_stream_start_stop(uint32_t len) > throw std::runtime_error("msg size (" + std::to_string(len) + ") is > too long " > "(longer than " + > std::to_string(sizeof(msg)) + ")"); > } > - 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(len)); > - } > + > + read_message(msg, len); > streaming_requested = (msg[0] != 0); /* num_codecs */ > syslog(LOG_INFO, "GOT START_STOP message -- request to %s streaming\n", > streaming_requested ? "START" : "STOP"); > @@ -108,12 +114,8 @@ static void handle_stream_capabilities(uint32_t len) > if (len > sizeof(caps)) { > throw std::runtime_error("capability message too long"); > } > - int n = read(streamfd, caps, len); > - if (n != len) { > - throw std::runtime_error("read command from device FAILED -- read " > + std::to_string(n) + > - " expected " + std::to_string(len)); > - } > > + read_message(caps, len); > // we currently do not support extensions so just reply so > StreamDevHeader hdr = { > STREAM_DEVICE_PROTOCOL, Frediano _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel