uNetworking / uSockets

Miniscule cross-platform eventing, networking & crypto for async applications
Apache License 2.0
1.29k stars 268 forks source link

us_socket_ext confusion #65

Closed lolriven closed 5 years ago

lolriven commented 5 years ago

Hello, I'm slightly confused about what us_socket_ext is doing. Is it allocating memory internally for the size relative to the context structure and returning the newly allocated pointer? Because what I'd like to do is store the socket objects in a class object, but I'd like us_socket_t to be able to reference that object later on. Like a ->data field. Does us_socket_t have a data field I can use or something to reference its parent object. Is us_socket_ext meant to return the class object pointer which us_socket_t is supposed to be stored in?

ghost commented 5 years ago

us_whatever_ext returns the extension of whatever. All constructors take ext_size, so if you do not wish to store all of your extension directly along the rest of whatever, you give it sizeof(void *) for ext_size and interpret us_whatever_ext as void **.

Extension in this context means user data.