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

[Libevent-users] Re:



On Sat, Feb 27, 2010 at 9:32 AM, ash ar <ashar51985@xxxxxxxxx> wrote:
> Hi,
>
> I have tried to embed libevent as a static library with my C++ application
> and would like to get http requests in my c++ application. Seems it works
> fine normally.
>
> I have use the following code..
>
> ______________________________________________
>
> void WebServer::ProcessHandler(struct evhttp_request *req, void *arg)
> {
>
>     struct evbuffer *buf;
>     buf = evbuffer_new();
>
>     if (buf == NULL)
>         cout << "failed to create response buffer";
>
>     char* uriInput = NULL;
>     if (req->type == EVHTTP_REQ_GET)
>     {
>         uriInput = (char*)evhttp_request_uri(req);
>     }
>     else if (req->type == EVHTTP_REQ_POST)
>     {
>         struct evbuffer *input_headers = evbuffer_new();
>         input_headers = req->input_buffer;
>         uriInput = (char*)input_headers->buffer;
>     }
>
>     evbuffer_add_printf(buf, "Requested: %s\n", evhttp_request_uri(req));
>     evhttp_send_reply(req, HTTP_OK, "OK", buf);
>
>     evhttp_connection_free(req->evcon);
>     free(uriInput);
>     evbuffer_free(buf);
>
>     return;
> };
>
> void webserver::ThreadProcess()
> {
>     struct evhttp *httpd;
>
>     event_init();
>     httpd = evhttp_start("0.0.0.0", 8080);
>
>     evhttp_set_cb(httpd, "/", &WebServer::ProcessHandler, NULL);
>
>     event_dispatch();
>
>     evhttp_free(httpd);
> }
>
> __________________________________________________
>
> But seems, the above code does not work as a threaded function. ie, call the
> same functions from different thread , when a first call is in progress I
> want to try a second call synchronously.

I'm not sure I get the question completely.  You want to call the some
functions (what functions?)  from two threads once?  Or you want the
callback to execute in a different thread from your main code?  Or you
want two callbacks to execute at once?

-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.