Commit 4401039f authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by facebook-github-bot-1

Support MSVC, which does not have VLAs, in folly/io/async/AsyncSocket.cpp

Summary: [Folly] Support MSVC, which does not have VLAs, in `folly/io/async/AsyncSocket.cpp`.

We use VLAs in compilers that have them, and fixed-size arrays in compilers that do not.

Reviewed By: @JoelMarcey

Differential Revision: D2450689
parent e4527fb5
...@@ -365,6 +365,10 @@ AC_CACHE_CHECK( ...@@ -365,6 +365,10 @@ AC_CACHE_CHECK(
[folly_cv_prog_cc_xsi_strerror_r=yes], [folly_cv_prog_cc_xsi_strerror_r=yes],
[folly_cv_prog_cc_xsi_strerror_r=no])]) [folly_cv_prog_cc_xsi_strerror_r=no])])
if test "$folly_cv_prog_cc_xsi_strerror_r" = "yes"; then
AC_DEFINE([HAVE_XSI_STRERROR_R], [1], [Define to 1 if the runtime supports XSI-style strerror_r])
fi
AC_CACHE_CHECK( AC_CACHE_CHECK(
[for ext/random and __gnu_cxx::sfmt19937], [for ext/random and __gnu_cxx::sfmt19937],
[folly_cv_prog_cc_have_extrandom_sfmt19937], [folly_cv_prog_cc_have_extrandom_sfmt19937],
...@@ -379,9 +383,26 @@ AC_CACHE_CHECK( ...@@ -379,9 +383,26 @@ AC_CACHE_CHECK(
[folly_cv_prog_cc_have_extrandom_sfmt19937=yes], [folly_cv_prog_cc_have_extrandom_sfmt19937=yes],
[folly_cv_prog_cc_have_extrandom_sfmt19937=no])]) [folly_cv_prog_cc_have_extrandom_sfmt19937=no])])
if test "$folly_cv_prog_cc_xsi_strerror_r" = "yes"; then AC_CACHE_CHECK(
AC_DEFINE([HAVE_XSI_STRERROR_R], [1], [Define to 1 if the runtime supports XSI-style strerror_r]) [for VLA (variable-length array) support],
fi [folly_cv_prog_cc_have_vla],
[AC_COMPILE_IFELSE(
[AC_LANG_SOURCE[
int main(int argc, char** argv) {
unsigned size = argc;
char data[size];
return 0;
}
]],
[folly_cv_prog_cc_have_vla=yes],
[folly_cv_prog_cc_have_vla=no])])
test "$folly_cv_prog_cc_have_vla" = yes && have_vla=1 || have_vla=0
AC_DEFINE_UNQUOTED(
[HAVE_VLA],
[$have_vla],
[Define to 1 if the compiler has VLA (variable-length array) support,
otherwise define to 0])
# Checks for library functions. # Checks for library functions.
AC_CHECK_FUNCS([getdelim \ AC_CHECK_FUNCS([getdelim \
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <boost/preprocessor/control/if.hpp>
using std::string; using std::string;
using std::unique_ptr; using std::unique_ptr;
...@@ -622,9 +623,10 @@ void AsyncSocket::writev(WriteCallback* callback, ...@@ -622,9 +623,10 @@ void AsyncSocket::writev(WriteCallback* callback,
void AsyncSocket::writeChain(WriteCallback* callback, unique_ptr<IOBuf>&& buf, void AsyncSocket::writeChain(WriteCallback* callback, unique_ptr<IOBuf>&& buf,
WriteFlags flags) { WriteFlags flags) {
constexpr size_t kSmallSizeMax = 64;
size_t count = buf->countChainElements(); size_t count = buf->countChainElements();
if (count <= 64) { if (count <= kSmallSizeMax) {
iovec vec[count]; iovec vec[BOOST_PP_IF(FOLLY_HAVE_VLA, count, kSmallSizeMax)];
writeChainImpl(callback, vec, count, std::move(buf), flags); writeChainImpl(callback, vec, count, std::move(buf), flags);
} else { } else {
iovec* vec = new iovec[count]; iovec* vec = new iovec[count];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment