[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] Sharing per-thread resources between connections
From: |
Christian Grothoff |
Subject: |
Re: [libmicrohttpd] Sharing per-thread resources between connections |
Date: |
Mon, 30 Jun 2014 18:38:00 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.6.0 |
On 06/30/2014 06:30 PM, Carlos Eduardo Moreira dos Santos wrote:
> Hi,
>
> I'm using zeromq between a request and a response. Its socket is not
> thread-safe and that's one of the reasons I chose MHD_USE_SELECT_INTERNALLY.
> As I am also using a thread pool, I have different sockets for each thread.
> It is expensive to open and close a socket in every connection and I would
> like to share a socket between all same-thread connections. I didn't find a
> way to do it, so I made a small change in the code
> <https://github.com/cemsbr/libmicrohttpd/commit/3151eff47553a8a93db7fb3355366b31aed2b262>
> in order to get the thread number (starting from 0) from the connection
> daemon. Thus, I can initialize an array of sockets only once (in the main
> function) and have them indexed by the thread number to be accessed later.
>
> As a side effect, I have to include internal.h, but it is working as
> expected. Was there a better way of doing this that I haven't noticed?
You might want to just use a thread-local variable to hold your connection.
My 1 cent ;-).
Christian
signature.asc
Description: OpenPGP digital signature