[Spice-devel] [PATCH spice-streaming-agent 5/9] Unify the structure of write_all() and read_all()
Frediano Ziglio
fziglio at redhat.com
Wed May 16 13:47:29 UTC 2018
>
> On Wed, 2018-05-16 at 05:31 -0400, Frediano Ziglio wrote:
> > >
> > > On Tue, 2018-05-15 at 16:44 -0400, Frediano Ziglio wrote:
> > > > A bit more comment would be good. For instance why not unifying the
> > > > other
> > > > way
> > > > around?
> > >
> > > Well, the reason is this one seems a bit cleaner and easier to read.
> > > Want me to put that in the commit message? :) Anything else? I don't
> > > feel this needs much explaining...
> > >
> >
> > What "seems" to you is not objective by definition.
> > In my experience I saw both implementation, they are both fine and correct
> > and different people have different styles.
> > Commit messages are not just for review now, think in 5 years possible
> > new people looking at the code.
>
> Indeed, it is my subjective reason to pick one of the ways. That's why
> I asked you if I really should put that in the commit message.
>
> There is nothing more to it, I just picked one way and I think we agree
> it's better to have the functions unified.
>
> So, what do you want me to do? :)
>
Just report this in the commit message, could be something along
"Both versions are fine but just for coherency syntax is unified.
The line
write(fd, (const char *) buf + written, len - written);
looks over complicated to the read_all version seems more clear."
(if this is the reason why one looks more clear).
> > > > >
> > > > > Signed-off-by: Lukáš Hrázký <lhrazky at redhat.com>
> > > > > ---
> > > > > src/stream-port.cpp | 20 +++++++++++---------
> > > > > src/stream-port.hpp | 4 ++--
> > > > > 2 files changed, 13 insertions(+), 11 deletions(-)
> > > > >
> > > > > diff --git a/src/stream-port.cpp b/src/stream-port.cpp
> > > > > index 526c564..cee63ac 100644
> > > > > --- a/src/stream-port.cpp
> > > > > +++ b/src/stream-port.cpp
> > > > > @@ -17,10 +17,10 @@
> > > > > namespace spice {
> > > > > namespace streaming_agent {
> > > > >
> > > > > -void read_all(int fd, void *msg, size_t len)
> > > > > +void read_all(int fd, void *buf, size_t len)
> > > > > {
> > > > > while (len > 0) {
> > > > > - ssize_t n = read(fd, msg, len);
> > > > > + ssize_t n = read(fd, buf, len);
> > > > >
> > > > > if (n < 0) {
> > > > > if (errno == EINTR) {
> > > > > @@ -30,22 +30,24 @@ void read_all(int fd, void *msg, size_t len)
> > > > > }
> > > > >
> > > > > len -= n;
> > > > > - msg = (uint8_t *) msg + n;
> > > > > + buf = (uint8_t *) buf + n;
> > > > > }
> > > > > }
> > > > >
> > > > > -void write_all(int fd, const void *buf, const size_t len)
> > > > > +void write_all(int fd, const void *buf, size_t len)
> > > > > {
> > > > > - size_t written = 0;
> > > > > - while (written < len) {
> > > > > - int l = write(fd, (const char *) buf + written, len -
> > > > > written);
> > > > > - if (l < 0) {
> > > > > + while (len > 0) {
> > > > > + ssize_t n = write(fd, buf, len);
> > > > > +
> > > > > + if (n < 0) {
> > > > > if (errno == EINTR) {
> > > > > continue;
> > > > > }
> > > > > throw WriteError("Writing message to device failed",
> > > > > errno);
> > > > > }
> > > > > - written += l;
> > > > > +
> > > > > + len -= n;
> > > > > + buf = (uint8_t *) buf + n;
I would add a const here.
> > > > > }
> > > > > }
> > > > >
> > > > > diff --git a/src/stream-port.hpp b/src/stream-port.hpp
> > > > > index 7780a37..b2d8352 100644
> > > > > --- a/src/stream-port.hpp
> > > > > +++ b/src/stream-port.hpp
> > > > > @@ -13,8 +13,8 @@
> > > > > namespace spice {
> > > > > namespace streaming_agent {
> > > > >
> > > > > -void read_all(int fd, void *msg, size_t len);
> > > > > -void write_all(int fd, const void *buf, const size_t len);
> > > > > +void read_all(int fd, void *buf, size_t len);
> > > > > +void write_all(int fd, const void *buf, size_t len);
> > > > >
> > > > > }} // namespace spice::streaming_agent
> > > > >
> > > >
> > > > Frediano
>
More information about the Spice-devel
mailing list