octave-maintainers
[Top][All Lists]
Advanced

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

Re: sockets development discussion


From: Paul Dreik
Subject: Re: sockets development discussion
Date: Tue, 21 Jan 2014 22:34:19 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0


2014-01-04 13:19, Paul Dreik skrev:
> Hi,
> there have been some recent changes to the octave socket package and I
> wanted to share my thoughts and get some feedback.
> 
> 1)
> backwards compatibility.
> I think the sockets package should work not only for the latest stable
> release but also the second latest and possibly older, if it is possible
> to do without much trouble.
This is fixed now, works for>=3.2.

> 
> 2)
> use int instead of a user visible class
> the sockets package has an octave type. I think that just complicates
> the code for no added value.
> returning an int which is the underlying file descriptor would be easier.
> if one wants to keep extra information connected to each socket, that
> can be done internally with the already existing static map. a
> socket_info() function could be added to get that extra info.
> 
> I believe there was some discussion about this a long time ago
> http://octave.1599824.n4.nabble.com/Explanation-of-Octave-operator-overloading-tp1640167p1640177.html
I have made the first step in removing the octave_socket class.


However, I stumbled across this code inside the send(...) function.

  const octave_base_value& data = args(1).get_rep ();
  if (data.is_string ())
    {
      std::string buf = data.string_value ();
      retval = ::send (s, buf.c_str (), buf.length (), flags);
    }
  else if (data.byte_size () == size_t (data.numel ()))
    {
      const NDArray d1 = data.array_value ();
      const octave_idx_type length = d1.numel ();
      const double* d1fvec = d1.data ();

      OCTAVE_LOCAL_BUFFER (unsigned char, buf, length);
      for (int i = 0 ; i < length; i++)
        buf[i] = (unsigned char)d1fvec[i];

      retval = ::send (s, (const char*)buf, data.byte_size (), 0);
    }

The first party clearly just copies a string, no problem.
The else if part however, what does it do? is it for handling uint8_t
and int8_t? If so, why does it copy values into the buffer via doubles?
Is there some better way to do this? Something along a std::memcpy or
why not letting ::send get a pointer to the storage directly?

Paul


reply via email to

[Prev in Thread] Current Thread [Next in Thread]