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