-
Notifications
You must be signed in to change notification settings - Fork 83
Supporting dependency injection via direct use of external socket. #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I added two things. a function is_udp_socket(socket) to ensure it's UDP. and a bool ownsSocket for host to ensure it behave with internal mechanism for socket or to use external without creating or closing socket or changing the configuration of it. (Leaving it all to the implementer of their own network.) You use your own socket by putting it in the new argument of enet_host_create() ENetSocket* externalUDPSocket. You set it to NULL to use the internal socket as normally done. This should theoretically work. I am unable to test it for myself because I don't need to make my own network so I'm not sure how to do it either. Things to test: Use of external socket should work. is_udp_socket should be valid. External socket should only be managed by the programmer.
modified: test/cli-server.c
|
Hey there, Thanks for the awesome work on this! One vital element that I noticed is that your suggested change is modifying and breaking the API compatibility. I agree that functional is interesting, but I think this specific change remains an option to be used in a fork, and not merged here in the repo. |
|
@inlife Thanks you for your kind word! |
|
I'm having trouble trying to modify this. |
I needed to re-request zpl-c#71 because codespace wasn't working for me. The change I made is an attempt to address the API-compatibility concern. I assumed it had to do with how adding an extra parameter to existing function (enet_host_create) would cause inconsistence requirement. So I addressed this by moving it over to enet_host_create_ext() and reuse the code with enet_host_create calling it set to NULL. Making it behave exactly as one would expect. Hope this is a proper solution! :)
|
@inlife I looked into ABI. this is sort of hard to understand but I'm curious why it would matter here? I thought you wouldn't be having any issues since you're compiling your own dll and the main program can be compiled for it as well? |
Direct response to feature request:
I added two things. A function: is_udp_socket(socket) to ensure it's UDP. and a bool ownsSocket as part of ENetHost to ensure it behave with internal mechanism for socket or to use external without creating or closing socket or changing the configuration of it. (Leaving it all to the implementer of their own network.)
You use your own socket by putting it in the new argument of enet_host_create() ENetSocket* externalUDPSocket.
You set it to NULL to use the internal socket as normally done.
This should theoretically work and will not break anything except you now need to fill in extra parameter. I am unable to test it for myself because I don't need to make my own network so I'm not sure how to do it either.
Things to test:
Use of external socket should work.
is_udp_socket should be valid.
External socket should only be managed by the programmer.