Azure / azure-sdk-for-cpp

This repository is for active development of the Azure SDK for C++. For consumers of the SDK we recommend visiting our versioned developer docs at https://azure.github.io/azure-sdk-for-cpp.
MIT License
170 stars 118 forks source link

`SIO_IDEAL_SEND_BACKLOG_QUERY` fails to compile under MinGW-w64 #5745

Open sharadhr opened 4 days ago

sharadhr commented 4 days ago

Hi!

At work, we are using vcpkg to compile azure-core-cpp with a custom CMake toolchain that uses llvm-mingw. The following line fails to compile, with an error: https://github.com/Azure/azure-sdk-for-cpp/blob/55c241902d6897f9c8b9aee2668c76c5d0723ba4/sdk/core/azure-core/src/http/curl/curl.cpp#L192

vcpkg/buildtrees/azure-core-cpp/src/ore_1.11.2-51f61b141e.clean/_/_/_/src/http/curl/curl.cpp:191:24: error: use of undeclared identifier 'SIO_IDEAL_SEND_BACKLOG_QUERY'
  191 |   if (WSAIoctl(socket, SIO_IDEAL_SEND_BACKLOG_QUERY, 0, 0, &ideal, sizeof(ideal), &ideallen, 0, 0)

As far as I've seen, this symbol is undefined on MinGW-w64, and libcurl seems to have a workaround, by manually defining the value. Until MinGW defines this (I've made a mailing list request), could the ioctl be #defined with an include guard? Perhaps:

#if defined(AZ_PLATFORM_WINDOWS)
+#  if defined(__MINGW64__)
+// In Windows SDK, this is defined to _IOR('t', 123, ULONG)
+#  define SIO_IDEAL_SEND_BACKLOG_QUERY _IOR('t', 123, ULONG)
+#  endif
// Windows needs this after every write to socket or performance would be reduced to 1/4 for
// uploading operation.
// https://github.com/Azure/azure-sdk-for-cpp/issues/644
void WinSocketSetBuffSize(curl_socket_t socket)
{
  ULONG ideal{};
  DWORD ideallen{};
  // WSAloctl would get the ideal size for the socket buffer.
  if (WSAIoctl(socket, SIO_IDEAL_SEND_BACKLOG_QUERY, 0, 0, &ideal, sizeof(ideal), &ideallen, 0, 0)
      == 0)
  {
    // if WSAloctl succeeded (returned 0), set the socket buffer size.
    // Specifies the total per-socket buffer space reserved for sends.
    // https://docs.microsoft.com/windows/win32/api/winsock/nf-winsock-setsockopt
    setsockopt(socket, SOL_SOCKET, SO_SNDBUF, (const char*)&ideal, sizeof(ideal));
  }
}
#endif