Re: Avoiding string break...



As I said I am a newbie in C++, so please take things with a grain of salt. 

Anyway, it looks to me that the bug is in this statement:
std::string received_data (buffer);

So replace it with this

std::string received_data (buffer, messlen);

This might fix it.

-----------------------
Also I am not sure about this:
size = mysocket->send (send_data.c_str(), size);

You might want to try this instead:
size = mysocket->send (send_data.data(), size);





----- Original Message ----
From: Glus Xof <gtglus gmail com>
To: Piscium <groknok yahoo ie>
Cc: gtkmm-list gnome org
Sent: Mon, 3 May, 2010 23:21:56
Subject: Re: Avoiding string break...

2010/5/3 Piscium <groknok yahoo ie>:
> I think you don't need base64 at all. It appears that there is a simple bug in your code where you convert from string object to raw data, or vice-versa.
>
> So the easiest is probably if you post the relevant excerpt of your source code, the bug should be easy to find.

Yes, no problem... thanks,


std::string clear_data;
std::string encrypted_data;
std::string send_data = clear_data+encrypted_data;

gsize to_send = send_data.size();
gsize size = to_send;

/*
* Writing routine excrept
*/

while (to_send > 0)
{
    try
    {
            size = mysocket->send (send_data.c_str(), size);
    }
    catch (...)
    [...]

    if (size == 0)
    {
        std::cerr
        << "Unexpected short write"
        << std::endl;
        return false;
    }

    to_send -= size;
}

/*
* Reading routine excrept
*/

buffer=g_new0(gchar,999999);

try
{
    messlen = mysocket->receive (buffer, 999999);
}
catch (...)
{
    std::cerr
    << Glib::ustring::compose ("Error receiving from socket: %1",
                error.what())
    << std::endl;
    return "";
}

if (messlen==0)
{
    mysocket->close();
        return "";
}
else
{
    buffer[messlen]='\0';
        std::string received_data (buffer);
}





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