Closed hellow554 closed 3 years ago
Yes definitely. But that would have to break backwards compatibility since WebSocket needs one more template argument. This can be considered for next major release.
Why not just remove getUserData and make the WebSocket derive from USERDATA then?
Then you can do things like
struct PerSocketData { int something = 12; };
ws->something++;
That would sync with the JavaScript wrapper as well, since they just do ws.something++; That removes differences between the two
getUserData remains but is now type safe. I did not find a good way to remove the function so it stays
https://github.com/uNetworking/uWebSockets/blob/2d65df86c7988f5d9afa826cfbceda332f06f6a4/misc/main.cpp#L43 https://github.com/uNetworking/uWebSockets/blob/2d65df86c7988f5d9afa826cfbceda332f06f6a4/misc/main.cpp#L48 https://github.com/uNetworking/uWebSockets/blob/2d65df86c7988f5d9afa826cfbceda332f06f6a4/misc/main.cpp#L63 https://github.com/uNetworking/uWebSockets/blob/380b3a7134ee0b52fd0ed02bcef8ddecdf244576/src/App.h#L216
should get updated
Currently
getUserData
returns avoid*
which must be casted manually to my type. But I will pass the type in thews
function, so my question is, would it be possible to pass that type internaly to the Websocket class as well, so we can get a function signature like this:T &getUserData()
?Would make it a little bit safer to use.