Hi, libuv team,

In my code, I want to init one buffer with std::string variable's value.
However I found I cannot call uv_buf_init with std::string directly on
Windows-7, if I do that, my program will quit libuv loop without any
warning.
As a comparison, I can do that on Linux.
My libuv version is v0.10.21.



Here is my code-snippet:

------------------------------------------------------------code-snippet---------------------------------------------------------

// callback for connect
void on_connect ( uv_connect_t * req, int status )
{
    FUNCTION_CALL

    if ( status )
    {
        fprintf ( stdout, "remote connection failed, need to enable remote
service\n" );

        if ( uv_last_error ( req->handle->loop ).code != UV_ECANCELED )
        {
            SHOW_UV_ERROR ( req->handle->loop );
            free ( req->data );
            free ( req );
        }
        return;
    }

    session_t * session = ( session_t * ) req->data;
    //fprintf ( stdout, "cmd_line[%d]:\n%s\n", session->cmd_line_.length(
), ( char * ) session->cmd_line_.c_str( ) );

    /**
     * uv_buf_t buf[1];
     * buf[0].len = len;
     * buf[0].base = message;
     */

    /* buf init */
#if 0
    // Here it works on both Windows-7 and Linux
    char buf_tmp[4096] = { 0 };
    uv_buf_t buf = uv_buf_init ( buf_tmp, session->cmd_line_.length( ) );
    buf.base = ( char * ) session->cmd_line_.c_str( );
#else
    // TODO
    // It works on Linux, but dosen't work on Windows-7
    // On Windows-7, here it will lead program quit without any warning or
error.
    // It even will not call on_write_end() function after uv_write()
called normally.
    uv_buf_t buf = uv_buf_init ( ( char * ) session->cmd_line_.c_str( ),
session->cmd_line_.length( ) );
#endif

    uv_stream_t * tcp = req->handle;

    uv_write_t write_req;

    int buf_count = 1;

    int rc = uv_write ( & write_req, tcp, & buf, buf_count, on_write_end );
    if ( rc )
    {
        SHOW_UV_ERROR ( req->handle->loop );
        fprintf ( stderr, "uv_write() called failed\n" );
    }
    else
    {
        fprintf ( stderr, "uv_write() called normally.\n" );
    }
}


-- 

     _                         __ _     _
 ___| |__   ___ _ __   __ _   / _(_)___| |__
|_  / '_ \ / _ \ '_ \ / _` | | |_| / __| '_ \
 / /| | | |  __/ | | | (_| | |  _| \__ \ | | |
/___|_| |_|\___|_| |_|\__, | |_| |_|___/_| |_|
                      |___/

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to