Commit fa32bb0f authored by Andrew Krieger's avatar Andrew Krieger Committed by Facebook Github Bot

s/if _WIN32/ifdef _WIN32/g

Summary:
Avoids -Wundef on non-Windows builds.
folly/system/ThreadId.h had #elif _WIN32 which was changed to
#elif defined(_WIN32)

Reviewed By: Orvid

Differential Revision: D17399760

fbshipit-source-id: 76583374c33d5d59e7c64b9a7a05c660a817bb92
parent a783cdd3
...@@ -55,7 +55,7 @@ void AsyncPipeReader::close() { ...@@ -55,7 +55,7 @@ void AsyncPipeReader::close() {
} }
} }
#if _WIN32 #ifdef _WIN32
static int recv_internal(NetworkSocket s, void* buf, size_t count) { static int recv_internal(NetworkSocket s, void* buf, size_t count) {
auto r = netops::recv(s, buf, count, 0); auto r = netops::recv(s, buf, count, 0);
if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) { if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) {
...@@ -115,7 +115,7 @@ void AsyncPipeReader::handlerReady(uint16_t events) noexcept { ...@@ -115,7 +115,7 @@ void AsyncPipeReader::handlerReady(uint16_t events) noexcept {
} }
// Perform the read // Perform the read
#if _WIN32 #ifdef _WIN32
// On Windows you can't call read on a socket, so call recv instead. // On Windows you can't call read on a socket, so call recv instead.
ssize_t bytesRead = ssize_t bytesRead =
folly::fileutil_detail::wrapNoInt(recv_internal, fd_, buf, buflen); folly::fileutil_detail::wrapNoInt(recv_internal, fd_, buf, buflen);
...@@ -237,7 +237,7 @@ void AsyncPipeWriter::handlerReady(uint16_t events) noexcept { ...@@ -237,7 +237,7 @@ void AsyncPipeWriter::handlerReady(uint16_t events) noexcept {
handleWrite(); handleWrite();
} }
#if _WIN32 #ifdef _WIN32
static int send_internal(NetworkSocket s, const void* buf, size_t count) { static int send_internal(NetworkSocket s, const void* buf, size_t count) {
auto r = netops::send(s, buf, count, 0); auto r = netops::send(s, buf, count, 0);
if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) { if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) {
...@@ -257,7 +257,7 @@ void AsyncPipeWriter::handleWrite() { ...@@ -257,7 +257,7 @@ void AsyncPipeWriter::handleWrite() {
// someday, support writev. The logic for partial writes is a bit complex // someday, support writev. The logic for partial writes is a bit complex
const IOBuf* head = curQueue.front(); const IOBuf* head = curQueue.front();
CHECK(head->length()); CHECK(head->length());
#if _WIN32 #ifdef _WIN32
// On Windows you can't call write on a socket. // On Windows you can't call write on a socket.
ssize_t rc = folly::fileutil_detail::wrapNoInt( ssize_t rc = folly::fileutil_detail::wrapNoInt(
send_internal, fd_, head->data(), head->length()); send_internal, fd_, head->data(), head->length());
......
...@@ -59,7 +59,7 @@ LogMessage::LogMessage( ...@@ -59,7 +59,7 @@ LogMessage::LogMessage(
} }
StringPiece LogMessage::getFileBaseName() const { StringPiece LogMessage::getFileBaseName() const {
#if _WIN32 #ifdef _WIN32
// Windows allows either backwards or forwards slash as path separator // Windows allows either backwards or forwards slash as path separator
auto idx1 = filename_.rfind('\\'); auto idx1 = filename_.rfind('\\');
auto idx2 = filename_.rfind('/'); auto idx2 = filename_.rfind('/');
......
...@@ -155,7 +155,7 @@ TEST(AsyncFileWriter, ioError) { ...@@ -155,7 +155,7 @@ TEST(AsyncFileWriter, ioError) {
// //
// GTest on Windows doesn't support alternation in the regex syntax -_-.... // GTest on Windows doesn't support alternation in the regex syntax -_-....
const std::string kExpectedErrorMessage = const std::string kExpectedErrorMessage =
#if _WIN32 #ifdef _WIN32
// The `pipe` call above is actually implemented via sockets, so we get // The `pipe` call above is actually implemented via sockets, so we get
// a different error message. // a different error message.
"An established connection was aborted by the software in your host machine\\."; "An established connection was aborted by the software in your host machine\\.";
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <folly/Portability.h> #include <folly/Portability.h>
#include <folly/net/detail/SocketFileDescriptorMap.h> #include <folly/net/detail/SocketFileDescriptorMap.h>
#if _WIN32 #ifdef _WIN32
#include <event2/util.h> // @manual #include <event2/util.h> // @manual
#include <MSWSock.h> // @manual #include <MSWSock.h> // @manual
...@@ -36,7 +36,7 @@ namespace folly { ...@@ -36,7 +36,7 @@ namespace folly {
namespace netops { namespace netops {
namespace { namespace {
#if _WIN32 #ifdef _WIN32
// WSA has to be explicitly initialized. // WSA has to be explicitly initialized.
static struct WinSockInit { static struct WinSockInit {
WinSockInit() { WinSockInit() {
...@@ -61,7 +61,7 @@ int translate_wsa_error(int wsaErr) { ...@@ -61,7 +61,7 @@ int translate_wsa_error(int wsaErr) {
template <class R, class F, class... Args> template <class R, class F, class... Args>
static R wrapSocketFunction(F f, NetworkSocket s, Args... args) { static R wrapSocketFunction(F f, NetworkSocket s, Args... args) {
R ret = f(s.data, args...); R ret = f(s.data, args...);
#if _WIN32 #ifdef _WIN32
errno = translate_wsa_error(WSAGetLastError()); errno = translate_wsa_error(WSAGetLastError());
#endif #endif
return ret; return ret;
...@@ -93,7 +93,7 @@ int close(NetworkSocket s) { ...@@ -93,7 +93,7 @@ int close(NetworkSocket s) {
int connect(NetworkSocket s, const sockaddr* name, socklen_t namelen) { int connect(NetworkSocket s, const sockaddr* name, socklen_t namelen) {
auto r = wrapSocketFunction<int>(::connect, s, name, namelen); auto r = wrapSocketFunction<int>(::connect, s, name, namelen);
#if _WIN32 #ifdef _WIN32
if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) { if (r == -1 && WSAGetLastError() == WSAEWOULDBLOCK) {
errno = EINPROGRESS; errno = EINPROGRESS;
} }
...@@ -117,7 +117,7 @@ int getsockopt( ...@@ -117,7 +117,7 @@ int getsockopt(
socklen_t* optlen) { socklen_t* optlen) {
auto ret = wrapSocketFunction<int>( auto ret = wrapSocketFunction<int>(
::getsockopt, s, level, optname, (char*)optval, optlen); ::getsockopt, s, level, optname, (char*)optval, optlen);
#if _WIN32 #ifdef _WIN32
if (optname == TCP_NODELAY && *optlen == 1) { if (optname == TCP_NODELAY && *optlen == 1) {
// Windows is weird about this value, and documents it as a // Windows is weird about this value, and documents it as a
// BOOL (ie. int) but expects the variable to be bool (1-byte), // BOOL (ie. int) but expects the variable to be bool (1-byte),
...@@ -170,7 +170,7 @@ int poll(PollDescriptor fds[], nfds_t nfds, int timeout) { ...@@ -170,7 +170,7 @@ int poll(PollDescriptor fds[], nfds_t nfds, int timeout) {
// Pun it through // Pun it through
pollfd* files = reinterpret_cast<pollfd*>(reinterpret_cast<void*>(fds)); pollfd* files = reinterpret_cast<pollfd*>(reinterpret_cast<void*>(fds));
#if _WIN32 #ifdef _WIN32
return ::WSAPoll(files, (ULONG)nfds, timeout); return ::WSAPoll(files, (ULONG)nfds, timeout);
#else #else
return ::poll(files, nfds, timeout); return ::poll(files, nfds, timeout);
...@@ -178,7 +178,7 @@ int poll(PollDescriptor fds[], nfds_t nfds, int timeout) { ...@@ -178,7 +178,7 @@ int poll(PollDescriptor fds[], nfds_t nfds, int timeout) {
} }
ssize_t recv(NetworkSocket s, void* buf, size_t len, int flags) { ssize_t recv(NetworkSocket s, void* buf, size_t len, int flags) {
#if _WIN32 #ifdef _WIN32
if ((flags & MSG_DONTWAIT) == MSG_DONTWAIT) { if ((flags & MSG_DONTWAIT) == MSG_DONTWAIT) {
flags &= ~MSG_DONTWAIT; flags &= ~MSG_DONTWAIT;
...@@ -211,7 +211,7 @@ ssize_t recvfrom( ...@@ -211,7 +211,7 @@ ssize_t recvfrom(
int flags, int flags,
sockaddr* from, sockaddr* from,
socklen_t* fromlen) { socklen_t* fromlen) {
#if _WIN32 #ifdef _WIN32
if ((flags & MSG_TRUNC) == MSG_TRUNC) { if ((flags & MSG_TRUNC) == MSG_TRUNC) {
SOCKET h = s.data; SOCKET h = s.data;
...@@ -266,7 +266,7 @@ ssize_t recvfrom( ...@@ -266,7 +266,7 @@ ssize_t recvfrom(
} }
ssize_t recvmsg(NetworkSocket s, msghdr* message, int flags) { ssize_t recvmsg(NetworkSocket s, msghdr* message, int flags) {
#if _WIN32 #ifdef _WIN32
(void)flags; (void)flags;
SOCKET h = s.data; SOCKET h = s.data;
...@@ -317,7 +317,7 @@ ssize_t recvmsg(NetworkSocket s, msghdr* message, int flags) { ...@@ -317,7 +317,7 @@ ssize_t recvmsg(NetworkSocket s, msghdr* message, int flags) {
} }
ssize_t send(NetworkSocket s, const void* buf, size_t len, int flags) { ssize_t send(NetworkSocket s, const void* buf, size_t len, int flags) {
#if _WIN32 #ifdef _WIN32
return wrapSocketFunction<ssize_t>( return wrapSocketFunction<ssize_t>(
::send, s, (const char*)buf, (int)len, flags); ::send, s, (const char*)buf, (int)len, flags);
#else #else
...@@ -326,7 +326,7 @@ ssize_t send(NetworkSocket s, const void* buf, size_t len, int flags) { ...@@ -326,7 +326,7 @@ ssize_t send(NetworkSocket s, const void* buf, size_t len, int flags) {
} }
ssize_t sendmsg(NetworkSocket socket, const msghdr* message, int flags) { ssize_t sendmsg(NetworkSocket socket, const msghdr* message, int flags) {
#if _WIN32 #ifdef _WIN32
(void)flags; (void)flags;
SOCKET h = socket.data; SOCKET h = socket.data;
...@@ -400,7 +400,7 @@ ssize_t sendto( ...@@ -400,7 +400,7 @@ ssize_t sendto(
int flags, int flags,
const sockaddr* to, const sockaddr* to,
socklen_t tolen) { socklen_t tolen) {
#if _WIN32 #ifdef _WIN32
return wrapSocketFunction<ssize_t>( return wrapSocketFunction<ssize_t>(
::sendto, s, (const char*)buf, (int)len, flags, to, (int)tolen); ::sendto, s, (const char*)buf, (int)len, flags, to, (int)tolen);
#else #else
...@@ -414,7 +414,7 @@ int setsockopt( ...@@ -414,7 +414,7 @@ int setsockopt(
int optname, int optname,
const void* optval, const void* optval,
socklen_t optlen) { socklen_t optlen) {
#if _WIN32 #ifdef _WIN32
if (optname == SO_REUSEADDR) { if (optname == SO_REUSEADDR) {
// We don't have an equivelent to the Linux & OSX meaning of this // We don't have an equivelent to the Linux & OSX meaning of this
// on Windows, so ignore it. // on Windows, so ignore it.
...@@ -441,7 +441,7 @@ NetworkSocket socket(int af, int type, int protocol) { ...@@ -441,7 +441,7 @@ NetworkSocket socket(int af, int type, int protocol) {
} }
int socketpair(int domain, int type, int protocol, NetworkSocket sv[2]) { int socketpair(int domain, int type, int protocol, NetworkSocket sv[2]) {
#if _WIN32 #ifdef _WIN32
if (domain != PF_UNIX || type != SOCK_STREAM || protocol != 0) { if (domain != PF_UNIX || type != SOCK_STREAM || protocol != 0) {
return -1; return -1;
} }
...@@ -466,7 +466,7 @@ int socketpair(int domain, int type, int protocol, NetworkSocket sv[2]) { ...@@ -466,7 +466,7 @@ int socketpair(int domain, int type, int protocol, NetworkSocket sv[2]) {
} }
int set_socket_non_blocking(NetworkSocket s) { int set_socket_non_blocking(NetworkSocket s) {
#if _WIN32 #ifdef _WIN32
u_long nonBlockingEnabled = 1; u_long nonBlockingEnabled = 1;
return ioctlsocket(s.data, FIONBIO, &nonBlockingEnabled); return ioctlsocket(s.data, FIONBIO, &nonBlockingEnabled);
#else #else
...@@ -479,7 +479,7 @@ int set_socket_non_blocking(NetworkSocket s) { ...@@ -479,7 +479,7 @@ int set_socket_non_blocking(NetworkSocket s) {
} }
int set_socket_close_on_exec(NetworkSocket s) { int set_socket_close_on_exec(NetworkSocket s) {
#if _WIN32 #ifdef _WIN32
if (SetHandleInformation((HANDLE)s.data, HANDLE_FLAG_INHERIT, 0)) { if (SetHandleInformation((HANDLE)s.data, HANDLE_FLAG_INHERIT, 0)) {
return 0; return 0;
} }
......
...@@ -28,7 +28,7 @@ namespace folly { ...@@ -28,7 +28,7 @@ namespace folly {
* for explicitly converting to/from file descriptors, even on Windows. * for explicitly converting to/from file descriptors, even on Windows.
*/ */
struct NetworkSocket { struct NetworkSocket {
#if _WIN32 #ifdef _WIN32
using native_handle_type = SOCKET; using native_handle_type = SOCKET;
static constexpr native_handle_type invalid_handle_value = INVALID_SOCKET; static constexpr native_handle_type invalid_handle_value = INVALID_SOCKET;
#else #else
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <folly/net/detail/SocketFileDescriptorMap.h> #include <folly/net/detail/SocketFileDescriptorMap.h>
#if _WIN32 #ifdef _WIN32
#include <shared_mutex> #include <shared_mutex>
#include <unordered_map> #include <unordered_map>
......
...@@ -28,7 +28,7 @@ namespace folly { ...@@ -28,7 +28,7 @@ namespace folly {
namespace netops { namespace netops {
namespace detail { namespace detail {
struct SocketFileDescriptorMap { struct SocketFileDescriptorMap {
#if _WIN32 #ifdef _WIN32
static int close(int fd) noexcept; static int close(int fd) noexcept;
static int close(SOCKET sock) noexcept; static int close(SOCKET sock) noexcept;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <folly/portability/Builtins.h> #include <folly/portability/Builtins.h>
#if _WIN32 #ifdef _WIN32
#include <folly/portability/Windows.h> #include <folly/portability/Windows.h>
namespace folly { namespace folly {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <folly/portability/Sched.h> #include <folly/portability/Sched.h>
#if _WIN32 #ifdef _WIN32
#include <thread> #include <thread>
namespace folly { namespace folly {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <errno.h> #include <errno.h>
#include <mutex> #include <mutex>
#if _WIN32 #ifdef _WIN32
namespace folly::portability::semaphore { namespace folly::portability::semaphore {
struct sem_t_ { struct sem_t_ {
std::mutex mtx{}; std::mutex mtx{};
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#if _WIN32 #ifdef _WIN32
#include <intrin.h> #include <intrin.h>
#endif #endif
......
...@@ -42,7 +42,7 @@ namespace folly { ...@@ -42,7 +42,7 @@ namespace folly {
inline uint64_t getCurrentThreadID() { inline uint64_t getCurrentThreadID() {
#if __APPLE__ #if __APPLE__
return uint64_t(pthread_mach_thread_np(pthread_self())); return uint64_t(pthread_mach_thread_np(pthread_self()));
#elif _WIN32 #elif defined(_WIN32)
return uint64_t(GetCurrentThreadId()); return uint64_t(GetCurrentThreadId());
#else #else
return uint64_t(pthread_self()); return uint64_t(pthread_self());
...@@ -82,7 +82,7 @@ inline uint64_t getOSThreadID() { ...@@ -82,7 +82,7 @@ inline uint64_t getOSThreadID() {
uint64_t tid; uint64_t tid;
pthread_threadid_np(nullptr, &tid); pthread_threadid_np(nullptr, &tid);
return tid; return tid;
#elif _WIN32 #elif defined(_WIN32)
return uint64_t(GetCurrentThreadId()); return uint64_t(GetCurrentThreadId());
#else #else
return uint64_t(syscall(FOLLY_SYS_gettid)); return uint64_t(syscall(FOLLY_SYS_gettid));
......
...@@ -109,7 +109,7 @@ Optional<std::string> getCurrentThreadName() { ...@@ -109,7 +109,7 @@ Optional<std::string> getCurrentThreadName() {
bool setThreadName(std::thread::id tid, StringPiece name) { bool setThreadName(std::thread::id tid, StringPiece name) {
auto trimmedName = name.subpiece(0, kMaxThreadNameLength - 1).str(); auto trimmedName = name.subpiece(0, kMaxThreadNameLength - 1).str();
#if _WIN32 #ifdef _WIN32
static_assert( static_assert(
sizeof(unsigned int) == sizeof(std::thread::id), sizeof(unsigned int) == sizeof(std::thread::id),
"This assumes std::thread::id is a thin wrapper around " "This assumes std::thread::id is a thin wrapper around "
...@@ -171,7 +171,7 @@ bool setThreadName(std::thread::id tid, StringPiece name) { ...@@ -171,7 +171,7 @@ bool setThreadName(std::thread::id tid, StringPiece name) {
} }
bool setThreadName(pthread_t pid, StringPiece name) { bool setThreadName(pthread_t pid, StringPiece name) {
#if _WIN32 #ifdef _WIN32
static_assert( static_assert(
sizeof(unsigned int) == sizeof(std::thread::id), sizeof(unsigned int) == sizeof(std::thread::id),
"This assumes std::thread::id is a thin wrapper around " "This assumes std::thread::id is a thin wrapper around "
......
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