[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/3] libssh: libhpp: overload read function to support timeout parameter


On Mar 20, 15:15, Aris Adamantiadis wrote:
> Hi Petar,
>
> I'm no C++ guru, but I don't understand why you are duplicating the
> read() prototype in multiple versions ? Is it because it is not
> acceptable to have two arguments with default values ?

Yes. Because that would mean that if you only want to change timeout you
still have to specify stderr.

> I also wonder how
> int read(void *dest, size_t count, bool is_stderr)
> and
> int read(void *dest, size_t count, int timeout)
> can coexist, do they have different signatures ?

Yes, one parameter is int, other is bool.

This patch will give this posibility:
read(dest, count);
read(dest, count, stderr);
read(dest, count, timeout);
read(dest, count, stderr, timeout);

This is common way of overloading, having multiple functions, not only
optional parameters, but as you can see it can be done in multiple ways.

other would be as stated above to have just this:
int read(void *dest, size_t count, bool is_stderr=false, int timeout=-1)

Where you would have to specify is_stderr if you want to use timeout so
it's up to you if that is acceptable. I am currently using this patched
version.

Just to note, I would change last overload to:
int read(void *dest, size_t count, bool is_stderr, int timeout=-1)
is_stderr would be required, since we already have overload for it.

> Thanks,
>
> Aris
>
> Le 20/03/14 10:59, Petar Koretic a �crit :
> > Signed-off-by: Petar Koretic <petar.koretic@xxxxxxxxxx>
> > ---
> >  include/libssh/libsshpp.hpp | 20 +++++++++++++++++++-
> >  1 file changed, 19 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/libssh/libsshpp.hpp b/include/libssh/libsshpp.hpp
> > index 0cf945b..48c5156 100644
> > --- a/include/libssh/libsshpp.hpp
> > +++ b/include/libssh/libsshpp.hpp
> > @@ -480,7 +480,7 @@ public:
> >      ssh_throw(err);
> >      return err;
> >    }
> > -  int read(void *dest, size_t count, bool is_stderr=false){
> > +  int read(void *dest, size_t count, bool is_stderr){
> >      int err;
> >      /* handle int overflow */
> >      if(count > 0x7fffffff)
> > @@ -489,6 +489,24 @@ public:
> >      ssh_throw(err);
> >      return err;
> >    }
> > +  int read(void *dest, size_t count, int timeout){
> > +    int err;
> > +    /* handle int overflow */
> > +    if(count > 0x7fffffff)
> > +      count = 0x7fffffff;
> > +    err=ssh_channel_read_timeout(channel,dest,count,false,timeout);
> > +    ssh_throw(err);
> > +    return err;
> > +  }
> > +  int read(void *dest, size_t count, bool is_stderr=false, int timeout=-1){
> > +    int err;
> > +    /* handle int overflow */
> > +    if(count > 0x7fffffff)
> > +      count = 0x7fffffff;
> > +    err=ssh_channel_read_timeout(channel,dest,count,is_stderr,timeout);
> > +    ssh_throw(err);
> > +    return err;
> > +  }
> >    int readNonblocking(void *dest, size_t count, bool is_stderr=false){
> >      int err;
> >      /* handle int overflow */
> >
>

Archive administrator: postmaster@lists.cynapses.org