-
Notifications
You must be signed in to change notification settings - Fork 119
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
issue: 2935075 Fix Windows support #193
Conversation
Can one of the admins verify this patch? |
src/client.cpp
Outdated
if (setitimer(ITIMER_REAL, &timer, NULL)) { | ||
log_err("ERROR: setitimer() failed when disarming"); | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider moving os dependencies into os_abstarct.[h|cpp]
if possible.
For example:
int os_settimer(timer)
{
#ifdef WIN32
#else
#endif
}
Pay attention that Linux and Windows return different values but it can be unified to linux style.
src/ip_address.cpp
Outdated
err = gai_strerror(res); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider moving os dependencies into os_abstarct.[h|cpp] if possible.
src/sockperf.cpp
Outdated
@@ -2337,7 +2352,12 @@ void cleanup() { | |||
if (g_fds_array) { | |||
for (ifd = 0; ifd <= s_fd_max; ifd++) { | |||
if (g_fds_array[ifd]) { | |||
#ifdef WIN32 | |||
closesocket(ifd); | |||
WSACleanup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems as WSACleanup()
call is wrong. It impacts the process and in fact called later as os_sock_cleanup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close() and closesocket()
should be in os_abstract.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WSACleanup()
must be called ifWSAStartup()
was called, So I do need to call it.
doc- https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsastartup
The WSAStartup
function must be the first Windows Sockets function called by an application or DLL. It allows an application or DLL to specify the version of Windows Sockets required and retrieve details of the specific Windows Sockets implementation. The application or DLL can only issue further Windows Sockets functions after successfully calling WSAStartup
.
If the wVersion member of the WSADATA structure is unacceptable to the caller, the application or DLL should call WSACleanup
to release the Winsock DLL resources and fail to initialize the Winsock application.
- I can move
close
andclosesocket
, just to clarify there is a different-
close()
is a unix function work on any file descriptor,
closesocket()
is a Windows-specific function, which works specifically with sockets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WSACleanup()
must be called ifWSAStartup()
was called, So I do need to call it.
doc- https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsastartupThe
WSAStartup
function must be the first Windows Sockets function called by an application or DLL. It allows an application or DLL to specify the version of Windows Sockets required and retrieve details of the specific Windows Sockets implementation. The application or DLL can only issue further Windows Sockets functions after successfully callingWSAStartup
. If the wVersion member of the WSADATA structure is unacceptable to the caller, the application or DLL should callWSACleanup
to release the Winsock DLL resources and fail to initialize the Winsock application.
- I can move
close
andclosesocket
, just to clarify there is a different-
close()
is a unix function work on any file descriptor,
closesocket()
is a Windows-specific function, which works specifically with sockets.
All above is correct but I said that WSACleanup()
is called inside os_sock_cleanup()
and no need to call WSACleanup()
many times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, missed that!
ok no problem
src/sockperf.cpp
Outdated
unlink(g_fds_array[ifd]->server_addr.addr_un.sun_path); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two ways here:
1 - wrapping if (s_user_params.addr.ss_family == AF_UNIX) { }
by #ifndef WIN32
2 - do nothing if code under if (s_user_params.addr.ss_family == AF_UNIX) { }
is compiled under windows. Code should not allow set unix socket under windows. In this case any condition as == AF_UNIX
is FALSE
I prefer the option 2 (Less #ifdef constructions in the code
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In windows AF_UNIX
is only supported in sock_stream
, therefor the if
statement for not using DGRAM
.
I can do nothing, but then if someone use AF_UNIX
in windows without --tcp
option than the behavior is not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only place I left with #ifdef
src/sockperf.cpp
Outdated
errno = EPERM; | ||
exit_with_err("Please compile with VMA Extra API to use these options", SOCKPERF_ERR_FATAL); | ||
} | ||
#endif | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two ways here:
1 - wrapping if (s_user_params.fd_handler_type == SOCKETXTREME) { }
by #ifndef WIN32
2 - do nothing if code under if (s_user_params.fd_handler_type == SOCKETXTREME) { }
is compiled under windows. Code should not allow set SOCKETXTREME mode under windows. In this case any condition as == SOCKETXTREME
is FALSE
I prefer the option 2 (Less #ifdef constructions in the code
)
80a4c16
to
5a98f5c
Compare
win/project/sockperf.vcxproj
Outdated
@@ -133,7 +133,7 @@ | |||
<Optimization>MaxSpeed</Optimization> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<PreprocessorDefinitions>__windows__;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove WIN32
win/project/sockperf.vcxproj
Outdated
@@ -115,7 +115,7 @@ | |||
<Optimization>MaxSpeed</Optimization> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<IntrinsicFunctions>true</IntrinsicFunctions> | |||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<PreprocessorDefinitions>__windows__;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove WIN32
win/project/sockperf.vcxproj
Outdated
@@ -99,7 +99,7 @@ | |||
</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<Optimization>Disabled</Optimization> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<PreprocessorDefinitions>__windows__;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove WIN32
win/project/sockperf.vcxproj
Outdated
@@ -85,7 +85,7 @@ | |||
</PrecompiledHeader> | |||
<WarningLevel>Level3</WarningLevel> | |||
<Optimization>Disabled</Optimization> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<PreprocessorDefinitions>__windows__;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove WIN32
src/common.cpp
Outdated
@@ -64,7 +64,7 @@ std::string sockaddr_to_hostport(const struct sockaddr *addr) | |||
if (addr->sa_family == AF_INET6) { | |||
return "[" + std::string(hbuf) + "]:" + std::string(pbuf); | |||
} else if (addr->sa_family == AF_UNIX) { | |||
return std::string(pbuf) + " [UNIX]"; | |||
return std::string(addr->sa_data) + " [AF_UNIX]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you show output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in linux it's enough to give the pbuf
because getnameinfo
knows how to fill it with the address and the output is good.
In windows, I changed to more common way that works both for linux and windows with addr->sa_data
which is the address directly.
Also changed UNIX
to AF_UNIX
- more generic
BTW, now I see another place to change..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that [AF_UNIX]
is not needed
I prefer [fd=232] Binding to: \tmp\test ...
Can you please adapt https://github.com/Mellanox/sockperf/blob/sockperf_v2/src/iohandlers.cpp#L41
to
printf("[%2d] ADDR = %s # %s\n", list_count++, pbuf, PRINT_PROTOCOL(data->sock_type));
to get output as
[ 0] ADDR = \tmp\test # TCP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one thing, it's SOCK_STREAM / SOCK_DGRAM rather then TCP / UDP
so output like
[ 0] ADDR = \tmp\test # SOCK_STREAM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one thing, it's SOCK_STREAM / SOCK_DGRAM rather then TCP / UDP so output like
[ 0] ADDR = \tmp\test # SOCK_STREAM
TCP/UDP is clear for end user and exist. I do not see benefits in SOCK_STREAM / SOCK_DGRAM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just a semantic we agreed in UDS patch, that AF_UNIX is not a TCP/UDP protocol and it might be confusing.
AF_INET + SOCK_STREAM = TCP
AF_UNIX + SOCK_STREAM !=TCP
That's why in the print I use PRINT_SOCKET_TYPE
and not PRINT_PROTOCOL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior or AF_UNIX + SOCK_STREAM sockets is comparable to TCP.
So seeing
[ 0] ADDR = \tmp\test # TCP
in output points to AF_UNIX + SOCK_STREAM
and
[ 0] ADDR = 1.1.1.1 # TCP
points to AF_INET + SOCK_STREAM
Let keep identical output format for inet and unix
src/ip_address.h
Outdated
#include <afunix.h> | ||
typedef unsigned short int sa_family_t; | ||
|
||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider #elif __linux__
src/sockperf.cpp
Outdated
if (s_user_params.mode == MODE_SERVER) | ||
#ifdef WIN32 | ||
DeleteFileA(g_fds_array[ifd]->server_addr.addr_un.sun_path); | ||
#else | ||
unlink(g_fds_array[ifd]->server_addr.addr_un.sun_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move DeleteFileA
/ unlink
into os_abstract.
consider using remove()
instead of DeleteFileA
src/sockperf.cpp
Outdated
@@ -3332,6 +3354,7 @@ int bringup(const int *p_daemonize) { | |||
/* Setup VMA */ | |||
int _vma_pkts_desc_size = 0; | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line
insert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix commit title "issue 2935075: RM Adding Windows support" to "issue: 2935075 Fix Windows support"
and the second as "issue: 2935075 Add preprocessor definition for windows"
4f45cc2
to
a6c2e1a
Compare
17f5099
to
6bb155b
Compare
bot:retest |
90f5085
to
84cddfd
Compare
bot:retest |
bool success = vma_xlio_try_set_func_pointers(); | ||
if (!success) { | ||
log_dbg("Failed to set function pointers for system functions."); | ||
log_dbg("Check vma-xlio-redirect.cpp for functions which your OS implementation is missing. " | ||
"Re-compile sockperf without them."); | ||
} | ||
#endif | ||
int rc = 0; | ||
if (os_sock_startup() == false) { // Only relevant for Windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we replace #endif
above with #else
and add #endif
below this condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes agree since os_sock_startup()
is only relevant for windows
bot:retest |
bot:retest |
bot:retest |
bot:retest |
bot:retest |
Signed-off-by: Eldar Shalev <eldarsh@nvidia.com>
Adding Windows support for sockperf including AF_UNIX.
Most of the code is added with #ifdef WIN32, so no impact is expected on linux.
Major changes include:
More about AF_UNIX in windows:
https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/