sapling/eden/fs/nfs/portmap/PortmapClient.cpp
Xavier Deguillard 235ccac7f3 nfs: ifdef it on Windows
Summary:
MSVC is broken as it doesn't understand the various macros used to generate
XdrTrait for specific types, and I can't figure out a way to make that work.
Even if I provide dummy version of these, the buck build breaks due to glog
trying to redefine the ERROR symbol that some Microsoft headers contain. For
now, let's just ifdef it out since it's unlikely that we're going to be using
NFS on Windows anytime soon.

Reviewed By: singhsrb

Differential Revision: D26293519

fbshipit-source-id: bbaf325c7d1f1688327708360244797a6d48179e
2021-02-05 21:22:56 -08:00

71 lines
2.0 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#ifndef _WIN32
#include "eden/fs/nfs/portmap/PortmapClient.h"
#include <folly/Exception.h>
#include <folly/SocketAddress.h>
#include <folly/String.h>
#include <folly/logging/xlog.h>
using folly::IOBuf;
using folly::IOBufQueue;
using folly::SocketAddress;
namespace facebook::eden {
namespace {
constexpr uint32_t kPortmapPortNumber = 111;
constexpr uint32_t kPortmapProgNumber = 100000;
constexpr uint32_t kPortmapVersionNumber = 4;
constexpr uint32_t kPortmapSet = 1;
constexpr uint32_t kPortmapUnSet = 2;
constexpr uint32_t kPortmapGetAddr = 3;
} // namespace
EDEN_XDR_SERDE_IMPL(PortmapMapping, prog, vers, netid, addr, owner);
PortmapClient::PortmapClient()
: client_(SocketAddress("127.0.0.1", kPortmapPortNumber)) {
#ifdef __APPLE__
{
// Connect to the portmap "tickler" socket.
// This causes launchd to spawn `rpcbind` and bring up the portmap service.
auto addr = SocketAddress::makeFromPath("/var/run/portmap.socket");
sockaddr_storage stg;
auto len = addr.getAddress(&stg);
tickler_ = folly::netops::socket(addr.getFamily(), SOCK_STREAM, 0);
folly::checkUnixError(
folly::netops::connect(tickler_, (sockaddr*)&stg, len),
"connect to ",
addr.getPath());
}
#endif
client_.connect();
}
bool PortmapClient::unsetMapping(PortmapMapping map) {
return client_.call<bool, PortmapMapping>(
kPortmapProgNumber, kPortmapVersionNumber, kPortmapUnSet, map);
}
bool PortmapClient::setMapping(PortmapMapping map) {
return client_.call<bool, PortmapMapping>(
kPortmapProgNumber, kPortmapVersionNumber, kPortmapSet, map);
}
std::string PortmapClient::getAddr(PortmapMapping map) {
return client_.call<std::string, PortmapMapping>(
kPortmapProgNumber, kPortmapVersionNumber, kPortmapGetAddr, map);
}
} // namespace facebook::eden
#endif