Build and work on windows #17

nmathewson opened this Issue Dec 15, 2011 · 6 comments


None yet

4 participants


The current codebase, as far as I can tell, is just plain not going to work on windows. I'd be glad to help with making it portable, but first I'd like to know how you want to handle stuff like system includes, threading, etc. I'm adding this issue as a placeholder.


Following up from libevent/libevent#29, I'd like to see libevhtp on Windows, too. Currently, libevhtp isn't a viable alternative to evhttp for those of us who need a cross-platform solution.

Given that libevent already has a cross-platform threading abstraction, it seems like the right approach would be to have libevhtp use libevent's threading facilities, rather than having libevhtp call pthread (or Windows thread) functions directly. A couple of issues that would need to be addressed to make this work:

  1. Currently, evthread-internal.h is a private header file. We would need to move libevent's threading functions into a public header, so that libevhtp could use them.
  2. Although libevent's threading facilities handle locking, they don't currently handle thread creation. So, the pthread_create in evthr.c would need to be #ifdefed between POSIX and Windows, or else we would need to add thread creation to libevent.
ellzey commented Nov 26, 2012

Thanks ppelleti. I think the best step going forward is vtable type overrides for threading and *alloc. Something like this:

struct htp_lock_fns {
    void * (*alloc)(int locktype);
    void   (*free)(htp_mutex * lock, int locktype);
    int    (*lock)(int mode, htp_mutex *lock);
    int    (*unlock)(int mode, htp_mutex  *lock);

struct htp_thread_fns {
    int               (*start)(htp_thread *thread, htp_attr *attr, void * (*start_cb)(void *), void *arg);
    void              (*end)(void *arg);
    int               (*kill)(htp_thread *thread);
    unsigned long int (*id)(void);
    int               (*join)(htp_thread *thread, void **data);
    int               (*detach)(htp_thread *thread);

I'll do my best to mimic what is already in libevent.

killing commented Apr 2, 2013

Hi, we've done some work to make libevhtp built on Windows with mingw. But it requires libevent-pthread, which is not built on windows. Currently we have to modify libevent so that pthread support is built on windows. But wonder if there is better way to do this.

ppelleti commented Apr 4, 2013

I'm happy to help out, but I'd really rather see this done by building libevhtp's threading on top of the threading support which libevent already has, rather than doing something different than what libevent does. (Sounds like you're using some sort of pthread compatibility layer?) Since libevent already supports Windows threads, why not build on that?

killing commented Apr 4, 2013

@ppelleti Yes, we're using a pthread compatibility layer now since we have limited time. We only fixed some other portability issues in the code, not include pthread. So far it works. But I agree it's better to use libevent's infrastructure.

ellzey commented Apr 4, 2013

Since I think this is all stemming from evthr, would it help if I had a vtable for the various thread functions in evthr you can set yourself? If this is not the evthr connection pooling stuff, then you are bound to libevent's threading api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment