Skip to content

Commit

Permalink
lib-http: Add http_client_get_global_context()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Dec 15, 2017
1 parent 993b1b9 commit a9f3703
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib-http/http-client.c
Expand Up @@ -87,6 +87,8 @@
*/

static struct http_client_context *http_client_global_context = NULL;

/*
* Client
*/
Expand Down Expand Up @@ -533,3 +535,21 @@ void http_client_context_switch_ioloop(struct http_client_context *cctx)
hshared = hshared->next)
http_client_host_shared_switch_ioloop(hshared);
}

static void http_client_global_context_free(void)
{
http_client_context_unref(&http_client_global_context);
}

struct http_client_context *http_client_get_global_context(void)
{
if (http_client_global_context != NULL)
return http_client_global_context;

struct http_client_settings set;
i_zero(&set);
http_client_global_context = http_client_context_create(&set);
/* keep this a bit higher than lib-ssl-iostream */
lib_atexit_priority(http_client_global_context_free, LIB_ATEXIT_PRIORITY_LOW-1);
return http_client_global_context;
}
5 changes: 5 additions & 0 deletions src/lib-http/http-client.h
Expand Up @@ -448,4 +448,9 @@ http_client_context_create(const struct http_client_settings *set);
void http_client_context_ref(struct http_client_context *cctx);
void http_client_context_unref(struct http_client_context **_cctx);

/* Return the default global shared client context, creating it if necessary.
The context is freed automatically at exit. Don't unreference the
returned context. */
struct http_client_context *http_client_get_global_context(void);

#endif

0 comments on commit a9f3703

Please sign in to comment.