Re: Avoiding string break...



On Mon, 3 May 2010 22:01:07 +0200
Glus Xof <gtglus gmail com> wrote:

> Excuse-me, I'm using Gio::Socket::receive() & Gio::Socket::send(), not
> Gio::receive() & Gio::send()...
> 
> Both Gio::Socket::receive() & Gio::Socket::send() take as a chain
> types "char *" and  "const gchar *" values, respectively, but not
> std::string (right now, I get the values using the c_str() method...)
> 
> The tests done show me that in most cases all works fine, but
> sometimes, when
> 
> "subchain1\0subchain2"
> 
> only retrive "subchain1"..

These send binary data (at least they do in the unwrapped C API) so you
shouldn't have any problems sending a byte stream with embedded 0
values.

If you are just using 0 in the byte stream as a text delimiter in the
manner of C strings, which would be quite reasonable, then you need to
honour that when manipulating the received data.  In other words, you
need to look again at how you are handling the received byte stream.

In any event, printing "subchain1\0subchain2" as a single string won't
work because 0 is not a valid character in any encoding that I know of
(including ISO-8859-15 and UTF-8).  And if you send that to a function
expecting a C string, it will discard everything after the 0
terminator, as you have found.

Chris




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