Hi,
I found that it was NOT caused by uv_buf_init with std::string, it was
caused by write requirement nearby the uv_buf_init.
Thx.
#if 0
///It will crash on Windows7, but work on Linux
///uv_write_t write_req;
#else
uv_write_t *write_req = new uv_write_t();
#endif
On Thursday, January 23, 2014 4:54:27 PM UTC+8, Fish Zheng wrote:
>
> Hi, Fedor
> Thanks for your feedback.
> I don't use any optimizations parameters.
>
> However now I just change the variable 'session->cmd_line_' as one
> std::string ptr type, then it works on Windows-7.
>
> On Wednesday, January 22, 2014 8:04:45 PM UTC+8, Fedor Indutny wrote:
>>
>> Hello!
>>
>> I'd suspect that it is a compiler bug, seems like it thinks that
>> `c_str()` is no longer required after `uv_buf_init()` call. Could you
>> please try compiling with disabled optimizations to make sure that we
>> are right?
>>
>> Cheers,
>> Fedor.
>>
>> On Wed, Jan 22, 2014 at 1:15 PM, zhengfish <[email protected]> wrote:
>> > 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.
>>
>
--
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.