Commit 53edc275 authored by Igor Sugak's avatar Igor Sugak Committed by facebook-github-bot-0

folly: use -Wheader-hygiene with clang

Summary: `-Wheader-hygiene` warns on using namespace directive in global context in header.  Fix all of the violations.

Reviewed By: yfeldblum

Differential Revision: D2867655

fb-gh-sync-id: 46840f8ece99e7af262058e631635d870bd51149
parent 1ac421a5
...@@ -21,10 +21,6 @@ ...@@ -21,10 +21,6 @@
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
#include <poll.h> #include <poll.h>
// This is a test-only header
/* using override */
using namespace folly;
enum StateEnum { enum StateEnum {
STATE_WAITING, STATE_WAITING,
STATE_SUCCEEDED, STATE_SUCCEEDED,
...@@ -33,11 +29,11 @@ enum StateEnum { ...@@ -33,11 +29,11 @@ enum StateEnum {
typedef std::function<void()> VoidCallback; typedef std::function<void()> VoidCallback;
class ConnCallback : public AsyncSocket::ConnectCallback { class ConnCallback : public folly::AsyncSocket::ConnectCallback {
public: public:
ConnCallback() ConnCallback()
: state(STATE_WAITING) : state(STATE_WAITING),
, exception(AsyncSocketException::UNKNOWN, "none") {} exception(folly::AsyncSocketException::UNKNOWN, "none") {}
void connectSuccess() noexcept override { void connectSuccess() noexcept override {
state = STATE_SUCCEEDED; state = STATE_SUCCEEDED;
...@@ -46,7 +42,7 @@ class ConnCallback : public AsyncSocket::ConnectCallback { ...@@ -46,7 +42,7 @@ class ConnCallback : public AsyncSocket::ConnectCallback {
} }
} }
void connectErr(const AsyncSocketException& ex) noexcept override { void connectErr(const folly::AsyncSocketException& ex) noexcept override {
state = STATE_FAILED; state = STATE_FAILED;
exception = ex; exception = ex;
if (errorCallback) { if (errorCallback) {
...@@ -55,17 +51,17 @@ class ConnCallback : public AsyncSocket::ConnectCallback { ...@@ -55,17 +51,17 @@ class ConnCallback : public AsyncSocket::ConnectCallback {
} }
StateEnum state; StateEnum state;
AsyncSocketException exception; folly::AsyncSocketException exception;
VoidCallback successCallback; VoidCallback successCallback;
VoidCallback errorCallback; VoidCallback errorCallback;
}; };
class WriteCallback : public AsyncTransportWrapper::WriteCallback { class WriteCallback : public folly::AsyncTransportWrapper::WriteCallback {
public: public:
WriteCallback() WriteCallback()
: state(STATE_WAITING) : state(STATE_WAITING),
, bytesWritten(0) bytesWritten(0),
, exception(AsyncSocketException::UNKNOWN, "none") {} exception(folly::AsyncSocketException::UNKNOWN, "none") {}
void writeSuccess() noexcept override { void writeSuccess() noexcept override {
state = STATE_SUCCEEDED; state = STATE_SUCCEEDED;
...@@ -75,7 +71,7 @@ class WriteCallback : public AsyncTransportWrapper::WriteCallback { ...@@ -75,7 +71,7 @@ class WriteCallback : public AsyncTransportWrapper::WriteCallback {
} }
void writeErr(size_t bytesWritten, void writeErr(size_t bytesWritten,
const AsyncSocketException& ex) noexcept override { const folly::AsyncSocketException& ex) noexcept override {
state = STATE_FAILED; state = STATE_FAILED;
this->bytesWritten = bytesWritten; this->bytesWritten = bytesWritten;
exception = ex; exception = ex;
...@@ -86,18 +82,18 @@ class WriteCallback : public AsyncTransportWrapper::WriteCallback { ...@@ -86,18 +82,18 @@ class WriteCallback : public AsyncTransportWrapper::WriteCallback {
StateEnum state; StateEnum state;
size_t bytesWritten; size_t bytesWritten;
AsyncSocketException exception; folly::AsyncSocketException exception;
VoidCallback successCallback; VoidCallback successCallback;
VoidCallback errorCallback; VoidCallback errorCallback;
}; };
class ReadCallback : public AsyncTransportWrapper::ReadCallback { class ReadCallback : public folly::AsyncTransportWrapper::ReadCallback {
public: public:
explicit ReadCallback(size_t _maxBufferSz = 4096) explicit ReadCallback(size_t _maxBufferSz = 4096)
: state(STATE_WAITING) : state(STATE_WAITING),
, exception(AsyncSocketException::UNKNOWN, "none") exception(folly::AsyncSocketException::UNKNOWN, "none"),
, buffers() buffers(),
, maxBufferSz(_maxBufferSz) {} maxBufferSz(_maxBufferSz) {}
~ReadCallback() { ~ReadCallback() {
for (std::vector<Buffer>::iterator it = buffers.begin(); for (std::vector<Buffer>::iterator it = buffers.begin();
...@@ -129,7 +125,7 @@ class ReadCallback : public AsyncTransportWrapper::ReadCallback { ...@@ -129,7 +125,7 @@ class ReadCallback : public AsyncTransportWrapper::ReadCallback {
state = STATE_SUCCEEDED; state = STATE_SUCCEEDED;
} }
void readErr(const AsyncSocketException& ex) noexcept override { void readErr(const folly::AsyncSocketException& ex) noexcept override {
state = STATE_FAILED; state = STATE_FAILED;
exception = ex; exception = ex;
} }
...@@ -178,14 +174,14 @@ class ReadCallback : public AsyncTransportWrapper::ReadCallback { ...@@ -178,14 +174,14 @@ class ReadCallback : public AsyncTransportWrapper::ReadCallback {
}; };
StateEnum state; StateEnum state;
AsyncSocketException exception; folly::AsyncSocketException exception;
std::vector<Buffer> buffers; std::vector<Buffer> buffers;
Buffer currentBuffer; Buffer currentBuffer;
VoidCallback dataAvailableCallback; VoidCallback dataAvailableCallback;
const size_t maxBufferSz; const size_t maxBufferSz;
}; };
class BufferCallback : public AsyncTransport::BufferCallback { class BufferCallback : public folly::AsyncTransport::BufferCallback {
public: public:
BufferCallback() : buffered_(false), bufferCleared_(false) {} BufferCallback() : buffered_(false), bufferCleared_(false) {}
...@@ -213,18 +209,23 @@ class TestServer { ...@@ -213,18 +209,23 @@ class TestServer {
: fd_(-1) { : fd_(-1) {
fd_ = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); fd_ = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd_ < 0) { if (fd_ < 0) {
throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, throw folly::AsyncSocketException(
"failed to create test server socket", errno); folly::AsyncSocketException::INTERNAL_ERROR,
"failed to create test server socket",
errno);
} }
if (fcntl(fd_, F_SETFL, O_NONBLOCK) != 0) { if (fcntl(fd_, F_SETFL, O_NONBLOCK) != 0) {
throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, throw folly::AsyncSocketException(
"failed to put test server socket in " folly::AsyncSocketException::INTERNAL_ERROR,
"non-blocking mode", errno); "failed to put test server socket in "
"non-blocking mode",
errno);
} }
if (listen(fd_, 10) != 0) { if (listen(fd_, 10) != 0) {
throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, throw folly::AsyncSocketException(
"failed to listen on test server socket", folly::AsyncSocketException::INTERNAL_ERROR,
errno); "failed to listen on test server socket",
errno);
} }
address_.setFromLocalAddress(fd_); address_.setFromLocalAddress(fd_);
...@@ -244,17 +245,22 @@ class TestServer { ...@@ -244,17 +245,22 @@ class TestServer {
pfd.events = POLLIN; pfd.events = POLLIN;
int ret = poll(&pfd, 1, timeout); int ret = poll(&pfd, 1, timeout);
if (ret == 0) { if (ret == 0) {
throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, throw folly::AsyncSocketException(
"test server accept() timed out"); folly::AsyncSocketException::INTERNAL_ERROR,
"test server accept() timed out");
} else if (ret < 0) { } else if (ret < 0) {
throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, throw folly::AsyncSocketException(
"test server accept() poll failed", errno); folly::AsyncSocketException::INTERNAL_ERROR,
"test server accept() poll failed",
errno);
} }
int acceptedFd = ::accept(fd_, nullptr, nullptr); int acceptedFd = ::accept(fd_, nullptr, nullptr);
if (acceptedFd < 0) { if (acceptedFd < 0) {
throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, throw folly::AsyncSocketException(
"test server accept() failed", errno); folly::AsyncSocketException::INTERNAL_ERROR,
"test server accept() failed",
errno);
} }
return acceptedFd; return acceptedFd;
...@@ -265,9 +271,10 @@ class TestServer { ...@@ -265,9 +271,10 @@ class TestServer {
return std::shared_ptr<BlockingSocket>(new BlockingSocket(fd)); return std::shared_ptr<BlockingSocket>(new BlockingSocket(fd));
} }
std::shared_ptr<AsyncSocket> acceptAsync(EventBase* evb, int timeout=50) { std::shared_ptr<folly::AsyncSocket> acceptAsync(folly::EventBase* evb,
int timeout = 50) {
int fd = acceptFD(timeout); int fd = acceptFD(timeout);
return AsyncSocket::newSocket(evb, fd); return folly::AsyncSocket::newSocket(evb, fd);
} }
/** /**
......
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