howerj / httpc

HTTP client for embedded use - supports redirects and resume.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add context pointer to httpc_options

denravonska opened this issue · comments

Would it be possible to add a void *context to the options struct? That would make it easier to use in C++ when you need to access class members. Example:

// Static method to enable calls from C.
int HttpClient::HttpOpen(void **socket, struct httpc_options *os, void *opts, const char *domain, unsigned short port, int use_ssl)
{
    HttpClient * self = reinterpret_cast<HttpClient *>(os->context);
    auto res = self->socketFactory.CreateSocket();
    ...
}

That sounds like a good idea and it can be added to in a backwards compatible way by adding the context pointer to the end of the httpc_options structure. I should probably write a C++ wrapper at some point but I'm very rusty (no pun) with it.

It would also be good to have it accessible in the time and sleep functors, but that can't be made backwards compatible :(

I might add it and bump the major version number, I know how annoying it is to deal with callbacks that do not allow a user defined param field.