[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [fluid-dev] FluidSynth and BSD sockets.
From: |
Tom M. |
Subject: |
Re: [fluid-dev] FluidSynth and BSD sockets. |
Date: |
Wed, 22 Nov 2017 20:47:44 +0100 |
Yes I also stumbled over this code duplication. So yeah, would be nice if you
could draft a PR.
However I prefer the following naming:
fluid_socket_init()
fluid_socket_cleanup()
fluid_socket_get_error()
> implementig a function (for example) called fluid_sys_bsd_socket_init()
> called at the end of new_fluid_server() into bindings/fluid_cmd.c
Shouldnt that be called in new_fluid_server_socket() ?
Tom
Am Mittwoch, 22. November 2017, 19:40:22 CET schrieb Carlo Bramini:
> Hello everyone,
>
> into fluid.sys there is a piece of code that handles network connections.
> This piece of code is divided into two parts with an #ifndef _WIN32...#endif.
> Comparing these 2 pieces of code, they are absolutely identical except two
> aspects:
>
> 1) the code that handles BSD sockets on Windows calls WSAStartup() before the
> thread starts and WSACleanup() after it exits or if there is an error. In my
> opinion, this can be resolved by implementig a function (for example) called
> fluid_sys_bsd_socket_init() called at the end of new_fluid_server() into
> bindings/fluid_cmd.c. Similar, there will be fluid_sys_bsd_socket_close() and
> it will be called at the end of delete_fluid_server(). For example, something
> like this:
>
> int fluid_sys_bsd_socket_init(void)
> {
> #ifdef _WIN32
> WSADATA wsaData;
> int res = WSAStartup(MAKEWORD(2,2), &wsaData);
> if (res != 0) {
> FLUID_LOG(FLUID_ERR, "Server socket creation error: WSAStartup failed: %d",
> retval);
> return FLUID_FAILED;
> }
> #endif
> return FLUID_OK;
> }
>
> void fluid_sys_bsd_socket_close(void)
> {
> #ifdef _WIN32
> WSACleanup();
> #endif
> }
>
> 2) There are some FLUID_LOG() that print a message with a numeric value
> retrived from WSAGetLastError() for the WIN32 code. The code for POSIX prints
> just the messages without numeric value, although it could be retrieved from
> errno. I would like to suggest to add a little function like this:
>
> static int fluid_get_socket_error(void)
> {
> #ifdef _WIN32
> return WSAGetLastError();
> #else
> return errno;
> #endif
> }
>
> for resoving this thing and _IF_ the error code is something we would like to
> see also in POSIX (but I think that the answer is yes).
>
> After that, I was able to cut the size of fluid_sys.c by almost half.
> What do you think? I can send it if you think that it could be a good idea...
>
> Sincerely.
>