Hi Sergey Lyubka,

Follow your suggestion I rewrite request handler with very simply logic.

First time the handler just return MG_REQUEST_CALL_AGAIN and then send back 
return MG_REQUEST_PROCESSED.

But it also not work properly, So I wonder if the MG_REQUEST_CALL_AGAIN can 
work properly.

static int index_html(struct mg_connection *conn)
{
    if (NULL == conn->connection_param)
    {
      printf("first call index_html!\n");
      conn->connection_param = calloc(1, sizeof(int));
      return MG_REQUEST_CALL_AGAIN;
    }

    printf("second call index_html!\n");
    mg_printf_data(conn, "Hello! Requested URI is [%s]", conn->uri);
    return MG_REQUEST_PROCESSED;
}

在 2014年2月4日星期二UTC+8下午7时43分49秒,Sergey Lyubka写道:
>
> So you're making a proxy.
> I suggest not using static variables in a request handler.
> They can be overridden by any other random request.
> use conn->connection_param instead.
> Pass it to the client as a parameter.
>
>
>
>
> On Tue, Feb 4, 2014 at 8:34 AM, nietsnie <[email protected]<javascript:>
> > wrote:
>
>> Hi all,
>>
>> I start a server with a URI handler called cmgmRequestHandler. First time 
>> cmgmRequestHandler will return MG_REQUEST_CALL_AGAIN and send a request to 
>> another web server via mg_connect call. After download success from another 
>> server the Request Handler will call mg_send_data to give browser a 
>> response which content comes from another server.
>>
>> I find that after download success and call mg_send_data the request 
>> handler return MG_REQUEST_PROCESSED, the browser can not catch the response.
>> Anyone can give me a right solution? Thanks very much!
>>
>> static int cmgmRequestHandler(struct mg_connection *conn)
>> {
>>     static ConnectionParam param;
>>
>>     if (isIdle(&param))
>>     {
>>         if (isConnect(conn))
>>         {
>>             printf("Connect Control Module!\n");
>>             mg_connect(server, "127.0.0.1", 8090,  0, ts1, &param);
>>             param.status = MG_PARAM_CONNECTING;
>>             return MG_REQUEST_CALL_AGAIN;
>>         }
>>         else
>>         {
>>             printf("Other Request!\n");
>>             return MG_REQUEST_NOT_PROCESSED;
>>         }
>>     }
>>     if (isConnecting(&param) || isConnected(&param))
>>     {
>>         printf("Connecting Control Module!\n");
>>         return MG_REQUEST_CALL_AGAIN;
>>     }
>>     else if (isDownloadSuccess(&param))
>>     {
>>         printf("Control Module Download Success!\n");
>>         mg_send_data(conn, param.content, strlen(param.content));
>>         param.status = MG_PARAM_ERROR;
>>         return MG_REQUEST_PROCESSED;
>>     }
>>
>>     return MG_REQUEST_NOT_PROCESSED;
>> }
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "mongoose-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/mongoose-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"mongoose-users" 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/mongoose-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to