uNetworking / uSockets

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

Allow each us_socket_t* to have its own callback. #73

Closed Merethiel closed 5 years ago

Merethiel commented 5 years ago

I don't know if this already exists in the library but it would be nice to expose the callback assignments for each us_socket_t object and be able to reassign them freely. Something like this

struct us_socket_t *oldondata(struct us_socket_t *s, char *data, int length){
    //some sockets still use the old on data if they haven't been reassigned
    return s;
}
struct us_socket_t *newondata(struct us_socket_t *s, char *data, int length){
    //now we're here for the previously joined socket
    return s;
}
struct us_socket_t *onjoin(struct us_socket_t *s, char *data, int length){

    if(somecondition){
        s->on_data = newondata;
    }
    return s;
}

New sockets that join could have their on_data reassigned and the ones that do not get reassigned still use the oldondata from the initial context creation.

Would this be easy to change in the code or would it require much infrastructural changes?

ghost commented 5 years ago

This is not a design goal