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

Re: [Libevent-users] New libevent user with some questions



I've since rewritten my pseudocode as a small example written in c:

#include <stdio.h>
#include "event.h"
#include "event2/event.h"
#include "event2/bufferevent.h"
#include "event2/buffer.h"
#include "event2/thread.h"
#include "event2/http.h"

void request_callback(struct evhttp_request* request, void* args){
  printf("got to callback!");
  struct evbuffer* input_buffer = evhttp_request_get_input_buffer(request);
  int len = evbuffer_get_length(input_buffer);
  printf( evbuffer_pullup(input_buffer, len));
  
  
}
int main (int argc, const char * argv[]) {
    // insert code here...
  void* base = event_base_new();
  for(int i=0; i< 100; i++){
    void* http_conn = evhttp_connection_base_new(base, "127.0.0.1", 5984);
    void* request = evhttp_request_new(request_callback, http_conn);
    evhttp_make_request(http_conn, request, EVHTTP_REQ_GET, "/hello-world/39eb79f6fb9a0aa32af7fdeccf3942ac");
  
  }
  event_base_dispatch(base);
  printf("Hello, World!\n");
  return 0;
}

While the code runs, eventually I'm getting segmentation faults.  Clearly I'm not closing/freeing things when I should be.  Do any of you have any suggestions on where I should be doing this?  FYI, the libs I'm using were built from libevent2 trunk last night.

Mike Kohout
On Mon, Oct 12, 2009 at 2:09 PM, Dan Kegel <dank@xxxxxxxxx> wrote:
On Wed, Oct 7, 2009 at 5:14 PM, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
>> 1)  Does the event loop free completed, nonpersisted events?
>
> No; they are deleted (as if by event_del), but not freed (as if by
> event_free).

FWIW, I think the similarity of these names is an API usability bug.
It'd be nice if event_del were deprecated and a new, less
confusing synonym (event_remove?) were introduced.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.