uNetworking / uSockets

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

Mistake in echo server example? #67

Closed lolriven closed 5 years ago

lolriven commented 5 years ago

I noticed that in the us_create_socket_context function in context.c you allocated memory for us_socket_context_t + context_ext_size so I assume in the call to us_socket_ext you're doing some arithmetic like pointer+=sizeof(us_socket_context_t) and returning the pointer to the allocated structure the user is expecting or class object. Whatever it may be. But if that's the case then why is the call to

 struct us_socket_context_t *echo_context = us_create_socket_context(SSL, loop, sizeof(struct echo_context), options);

Passed with sizeof(struct echo_context) if echo_context itself is empty. Shouldn't the call have been with sizeof(struct echo_socket) instead? Since the example uses us_socket_ext to retrieve a pointer to echo_socket not echo_context...

/* Our socket extension */
struct echo_socket {
    char* backpressure;
    int length;
};

/* Our socket context extension */
struct echo_context {

};
ghost commented 5 years ago

I already answered this in #65

The example is correct