From 53edc275b70408e281b9a2a49be9d94762f77401 Mon Sep 17 00:00:00 2001 From: Igor Sugak Date: Wed, 27 Jan 2016 16:12:47 -0800 Subject: [PATCH] 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 --- folly/io/async/test/AsyncSocketTest.h | 85 +++++++++++++++------------ 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/folly/io/async/test/AsyncSocketTest.h b/folly/io/async/test/AsyncSocketTest.h index 722be94f..7bb5958f 100644 --- a/folly/io/async/test/AsyncSocketTest.h +++ b/folly/io/async/test/AsyncSocketTest.h @@ -21,10 +21,6 @@ #include #include -// This is a test-only header -/* using override */ -using namespace folly; - enum StateEnum { STATE_WAITING, STATE_SUCCEEDED, @@ -33,11 +29,11 @@ enum StateEnum { typedef std::function VoidCallback; -class ConnCallback : public AsyncSocket::ConnectCallback { +class ConnCallback : public folly::AsyncSocket::ConnectCallback { public: ConnCallback() - : state(STATE_WAITING) - , exception(AsyncSocketException::UNKNOWN, "none") {} + : state(STATE_WAITING), + exception(folly::AsyncSocketException::UNKNOWN, "none") {} void connectSuccess() noexcept override { state = STATE_SUCCEEDED; @@ -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; exception = ex; if (errorCallback) { @@ -55,17 +51,17 @@ class ConnCallback : public AsyncSocket::ConnectCallback { } StateEnum state; - AsyncSocketException exception; + folly::AsyncSocketException exception; VoidCallback successCallback; VoidCallback errorCallback; }; -class WriteCallback : public AsyncTransportWrapper::WriteCallback { +class WriteCallback : public folly::AsyncTransportWrapper::WriteCallback { public: WriteCallback() - : state(STATE_WAITING) - , bytesWritten(0) - , exception(AsyncSocketException::UNKNOWN, "none") {} + : state(STATE_WAITING), + bytesWritten(0), + exception(folly::AsyncSocketException::UNKNOWN, "none") {} void writeSuccess() noexcept override { state = STATE_SUCCEEDED; @@ -75,7 +71,7 @@ class WriteCallback : public AsyncTransportWrapper::WriteCallback { } void writeErr(size_t bytesWritten, - const AsyncSocketException& ex) noexcept override { + const folly::AsyncSocketException& ex) noexcept override { state = STATE_FAILED; this->bytesWritten = bytesWritten; exception = ex; @@ -86,18 +82,18 @@ class WriteCallback : public AsyncTransportWrapper::WriteCallback { StateEnum state; size_t bytesWritten; - AsyncSocketException exception; + folly::AsyncSocketException exception; VoidCallback successCallback; VoidCallback errorCallback; }; -class ReadCallback : public AsyncTransportWrapper::ReadCallback { +class ReadCallback : public folly::AsyncTransportWrapper::ReadCallback { public: explicit ReadCallback(size_t _maxBufferSz = 4096) - : state(STATE_WAITING) - , exception(AsyncSocketException::UNKNOWN, "none") - , buffers() - , maxBufferSz(_maxBufferSz) {} + : state(STATE_WAITING), + exception(folly::AsyncSocketException::UNKNOWN, "none"), + buffers(), + maxBufferSz(_maxBufferSz) {} ~ReadCallback() { for (std::vector::iterator it = buffers.begin(); @@ -129,7 +125,7 @@ class ReadCallback : public AsyncTransportWrapper::ReadCallback { state = STATE_SUCCEEDED; } - void readErr(const AsyncSocketException& ex) noexcept override { + void readErr(const folly::AsyncSocketException& ex) noexcept override { state = STATE_FAILED; exception = ex; } @@ -178,14 +174,14 @@ class ReadCallback : public AsyncTransportWrapper::ReadCallback { }; StateEnum state; - AsyncSocketException exception; + folly::AsyncSocketException exception; std::vector buffers; Buffer currentBuffer; VoidCallback dataAvailableCallback; const size_t maxBufferSz; }; -class BufferCallback : public AsyncTransport::BufferCallback { +class BufferCallback : public folly::AsyncTransport::BufferCallback { public: BufferCallback() : buffered_(false), bufferCleared_(false) {} @@ -213,18 +209,23 @@ class TestServer { : fd_(-1) { fd_ = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd_ < 0) { - throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, - "failed to create test server socket", errno); + throw folly::AsyncSocketException( + folly::AsyncSocketException::INTERNAL_ERROR, + "failed to create test server socket", + errno); } if (fcntl(fd_, F_SETFL, O_NONBLOCK) != 0) { - throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, - "failed to put test server socket in " - "non-blocking mode", errno); + throw folly::AsyncSocketException( + folly::AsyncSocketException::INTERNAL_ERROR, + "failed to put test server socket in " + "non-blocking mode", + errno); } if (listen(fd_, 10) != 0) { - throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, - "failed to listen on test server socket", - errno); + throw folly::AsyncSocketException( + folly::AsyncSocketException::INTERNAL_ERROR, + "failed to listen on test server socket", + errno); } address_.setFromLocalAddress(fd_); @@ -244,17 +245,22 @@ class TestServer { pfd.events = POLLIN; int ret = poll(&pfd, 1, timeout); if (ret == 0) { - throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, - "test server accept() timed out"); + throw folly::AsyncSocketException( + folly::AsyncSocketException::INTERNAL_ERROR, + "test server accept() timed out"); } else if (ret < 0) { - throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, - "test server accept() poll failed", errno); + throw folly::AsyncSocketException( + folly::AsyncSocketException::INTERNAL_ERROR, + "test server accept() poll failed", + errno); } int acceptedFd = ::accept(fd_, nullptr, nullptr); if (acceptedFd < 0) { - throw AsyncSocketException(AsyncSocketException::INTERNAL_ERROR, - "test server accept() failed", errno); + throw folly::AsyncSocketException( + folly::AsyncSocketException::INTERNAL_ERROR, + "test server accept() failed", + errno); } return acceptedFd; @@ -265,9 +271,10 @@ class TestServer { return std::shared_ptr(new BlockingSocket(fd)); } - std::shared_ptr acceptAsync(EventBase* evb, int timeout=50) { + std::shared_ptr acceptAsync(folly::EventBase* evb, + int timeout = 50) { int fd = acceptFD(timeout); - return AsyncSocket::newSocket(evb, fd); + return folly::AsyncSocket::newSocket(evb, fd); } /** -- 2.34.1