mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-02-20 15:14:26 +01:00
Removed the namespaces from brynet.
This commit is contained in:
parent
07dcd7774a
commit
679c6d37c1
@ -84,7 +84,7 @@ void HTTPServer::initialize() {
|
||||
if (listenBuilder)
|
||||
delete listenBuilder;
|
||||
|
||||
listenBuilder = new wrapper::HttpListenerBuilder();
|
||||
listenBuilder = new HttpListenerBuilder();
|
||||
listenBuilder->WithService(service);
|
||||
|
||||
listenBuilder->AddSocketProcess([](TcpSocket &socket) {
|
||||
@ -112,7 +112,7 @@ void HTTPServer::main_loop() {
|
||||
//std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
if (brynet::base::app_kbhit()) {
|
||||
if (app_kbhit()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,6 @@
|
||||
#include <brynet/net/wrapper/HttpServiceBuilder.hpp>
|
||||
#include <brynet/net/wrapper/ServiceBuilder.hpp>
|
||||
|
||||
using namespace brynet;
|
||||
using namespace brynet::net;
|
||||
using namespace brynet::net::http;
|
||||
|
||||
class Request;
|
||||
class Application;
|
||||
|
||||
@ -26,7 +22,7 @@ public:
|
||||
int port;
|
||||
int threads;
|
||||
std::shared_ptr<TcpService> service;
|
||||
wrapper::HttpListenerBuilder *listenBuilder;
|
||||
HttpListenerBuilder *listenBuilder;
|
||||
|
||||
void http_callback_handler(Request *response);
|
||||
|
||||
|
@ -9,10 +9,6 @@
|
||||
|
||||
#include "handler_instance.h"
|
||||
|
||||
using namespace brynet;
|
||||
using namespace brynet::net;
|
||||
using namespace brynet::net::http;
|
||||
|
||||
class Application;
|
||||
|
||||
class Request {
|
||||
|
@ -8,9 +8,6 @@
|
||||
#include <cstdint>
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
#ifdef BRYNET_HAVE_LANG_CXX17
|
||||
using BrynetAny = std::any;
|
||||
|
||||
@ -25,6 +22,3 @@ const T *cast(const BrynetAny &ud) {
|
||||
return static_cast<const T *>(&ud);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -14,9 +14,6 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
static bool app_kbhit() {
|
||||
#ifdef BRYNET_PLATFORM_WINDOWS
|
||||
return _kbhit();
|
||||
@ -42,6 +39,3 @@ static bool app_kbhit() {
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -4,9 +4,6 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
struct array_s {
|
||||
void *buffer;
|
||||
size_t buffer_size;
|
||||
@ -102,6 +99,3 @@ static bool array_increase(struct array_s *self, size_t increase_num) {
|
||||
static size_t array_num(const struct array_s *self) {
|
||||
return self->element_num;
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -3,9 +3,6 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
struct buffer_s {
|
||||
char *data;
|
||||
size_t data_len;
|
||||
@ -142,6 +139,3 @@ static bool buffer_write(struct buffer_s *self, const char *data, size_t len) {
|
||||
|
||||
return write_ret;
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
class NonCopyable {
|
||||
public:
|
||||
NonCopyable(const NonCopyable &) = delete;
|
||||
@ -13,5 +10,3 @@ protected:
|
||||
~NonCopyable() = default;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -7,9 +7,6 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
class BasePacketWriter : public NonCopyable {
|
||||
public:
|
||||
BasePacketWriter(char *buffer,
|
||||
@ -62,27 +59,27 @@ public:
|
||||
return writeBuffer((char *)&value, sizeof(value));
|
||||
}
|
||||
bool writeINT16(int16_t value) {
|
||||
value = endian::hostToNetwork16(value, mBigEndian);
|
||||
value = hostToNetwork16(value, mBigEndian);
|
||||
return writeBuffer((char *)&value, sizeof(value));
|
||||
}
|
||||
bool writeUINT16(uint16_t value) {
|
||||
value = endian::hostToNetwork16(value, mBigEndian);
|
||||
value = hostToNetwork16(value, mBigEndian);
|
||||
return writeBuffer((char *)&value, sizeof(value));
|
||||
}
|
||||
bool writeINT32(int32_t value) {
|
||||
value = endian::hostToNetwork32(value, mBigEndian);
|
||||
value = hostToNetwork32(value, mBigEndian);
|
||||
return writeBuffer((char *)&value, sizeof(value));
|
||||
}
|
||||
bool writeUINT32(uint32_t value) {
|
||||
value = endian::hostToNetwork32(value, mBigEndian);
|
||||
value = hostToNetwork32(value, mBigEndian);
|
||||
return writeBuffer((char *)&value, sizeof(value));
|
||||
}
|
||||
bool writeINT64(int64_t value) {
|
||||
value = endian::hostToNetwork64(value, mBigEndian);
|
||||
value = hostToNetwork64(value, mBigEndian);
|
||||
return writeBuffer((char *)&value, sizeof(value));
|
||||
}
|
||||
bool writeUINT64(uint64_t value) {
|
||||
value = endian::hostToNetwork64(value, mBigEndian);
|
||||
value = hostToNetwork64(value, mBigEndian);
|
||||
return writeBuffer((char *)&value, sizeof(value));
|
||||
}
|
||||
|
||||
@ -294,32 +291,32 @@ public:
|
||||
int16_t readINT16() {
|
||||
int16_t value = 0;
|
||||
read(value);
|
||||
return endian::networkToHost16(value, mBigEndian);
|
||||
return networkToHost16(value, mBigEndian);
|
||||
}
|
||||
uint16_t readUINT16() {
|
||||
uint16_t value = 0;
|
||||
read(value);
|
||||
return endian::networkToHost16(value, mBigEndian);
|
||||
return networkToHost16(value, mBigEndian);
|
||||
}
|
||||
int32_t readINT32() {
|
||||
int32_t value = 0;
|
||||
read(value);
|
||||
return endian::networkToHost32(value, mBigEndian);
|
||||
return networkToHost32(value, mBigEndian);
|
||||
}
|
||||
uint32_t readUINT32() {
|
||||
uint32_t value = 0;
|
||||
read(value);
|
||||
return endian::networkToHost32(value, mBigEndian);
|
||||
return networkToHost32(value, mBigEndian);
|
||||
}
|
||||
int64_t readINT64() {
|
||||
int64_t value = 0;
|
||||
read(value);
|
||||
return endian::networkToHost64(value, mBigEndian);
|
||||
return networkToHost64(value, mBigEndian);
|
||||
}
|
||||
uint64_t readUINT64() {
|
||||
uint64_t value = 0;
|
||||
read(value);
|
||||
return endian::networkToHost64(value, mBigEndian);
|
||||
return networkToHost64(value, mBigEndian);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -359,6 +356,3 @@ private:
|
||||
};
|
||||
|
||||
using BigPacket = AutoMallocPacket<32 * 1024>;
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -3,9 +3,6 @@
|
||||
#include <brynet/base/Array.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
struct stack_s {
|
||||
struct array_s *array;
|
||||
size_t element_size;
|
||||
@ -141,6 +138,3 @@ static void *stack_popback(struct stack_s *self) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -8,9 +8,6 @@
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
class TimerMgr;
|
||||
|
||||
class Timer final {
|
||||
@ -140,6 +137,3 @@ private:
|
||||
|
||||
std::priority_queue<Timer::Ptr, std::vector<Timer::Ptr>, CompareTimer> mTimers;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -7,9 +7,6 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
class WaitGroup : public NonCopyable {
|
||||
public:
|
||||
typedef std::shared_ptr<WaitGroup> Ptr;
|
||||
@ -57,5 +54,3 @@ private:
|
||||
std::atomic<int> mCounter;
|
||||
std::condition_variable mCond;
|
||||
};
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -3,10 +3,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
namespace crypto {
|
||||
|
||||
static const std::string base64_chars =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
@ -99,8 +95,4 @@ static std::string base64_decode(std::string const &encoded_string) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace crypto
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
||||
#endif
|
@ -12,9 +12,6 @@
|
||||
#include <sys/_endian.h>
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
namespace endian {
|
||||
|
||||
inline uint64_t hl64ton(uint64_t hostValue) {
|
||||
uint64_t ret = 0;
|
||||
@ -116,7 +113,3 @@ inline uint16_t networkToHost16(uint16_t net16, bool convert = true) {
|
||||
return convert ? ntohs(net16) : net16;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace endian
|
||||
} // namespace base
|
||||
} // namespace brynet
|
@ -2,25 +2,23 @@
|
||||
|
||||
#include <brynet/net/detail/ConnectorDetail.hpp>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
using ConnectOption = ConnectOption;
|
||||
|
||||
using ConnectOption = detail::ConnectOption;
|
||||
class AsyncConnector : public detail::AsyncConnectorDetail,
|
||||
class AsyncConnector : public AsyncConnectorDetail,
|
||||
public std::enable_shared_from_this<AsyncConnector> {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<AsyncConnector>;
|
||||
|
||||
void startWorkerThread() {
|
||||
detail::AsyncConnectorDetail::startWorkerThread();
|
||||
AsyncConnectorDetail::startWorkerThread();
|
||||
}
|
||||
|
||||
void stopWorkerThread() {
|
||||
detail::AsyncConnectorDetail::stopWorkerThread();
|
||||
AsyncConnectorDetail::stopWorkerThread();
|
||||
}
|
||||
|
||||
void asyncConnect(const ConnectOption &option) {
|
||||
detail::AsyncConnectorDetail::asyncConnect(option);
|
||||
AsyncConnectorDetail::asyncConnect(option);
|
||||
}
|
||||
|
||||
static Ptr Create() {
|
||||
@ -32,6 +30,3 @@ public:
|
||||
private:
|
||||
AsyncConnector() = default;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
class EventLoop;
|
||||
|
||||
class Channel {
|
||||
@ -16,6 +13,3 @@ private:
|
||||
|
||||
friend class EventLoop;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -18,10 +18,6 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace current_thread {
|
||||
|
||||
#ifdef BRYNET_PLATFORM_WINDOWS
|
||||
using THREAD_ID_TYPE = DWORD;
|
||||
#elif defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN
|
||||
@ -52,7 +48,3 @@ static THREAD_ID_TYPE &tid() {
|
||||
|
||||
return cachedTid;
|
||||
}
|
||||
|
||||
} // namespace current_thread
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -18,14 +18,11 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
class Channel;
|
||||
class TcpConnection;
|
||||
using TcpConnectionPtr = std::shared_ptr<TcpConnection>;
|
||||
|
||||
class EventLoop : public brynet::base::NonCopyable {
|
||||
class EventLoop : public NonCopyable {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<EventLoop>;
|
||||
using UserFunctor = std::function<void(void)>;
|
||||
@ -54,11 +51,11 @@ public:
|
||||
}
|
||||
#elif defined BRYNET_PLATFORM_LINUX
|
||||
auto eventfd = ::eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
|
||||
mWakeupChannel.reset(new detail::WakeupChannel(eventfd));
|
||||
mWakeupChannel.reset(new WakeupChannel(eventfd));
|
||||
linkChannel(eventfd, mWakeupChannel.get());
|
||||
#elif defined BRYNET_PLATFORM_DARWIN
|
||||
const int NOTIFY_IDENT = 42; // Magic number we use for our filter ID.
|
||||
mWakeupChannel.reset(new detail::WakeupChannel(mKqueueFd, NOTIFY_IDENT));
|
||||
mWakeupChannel.reset(new WakeupChannel(mKqueueFd, NOTIFY_IDENT));
|
||||
//Add user event
|
||||
struct kevent ev;
|
||||
EV_SET(&ev, NOTIFY_IDENT, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, NULL);
|
||||
@ -72,7 +69,7 @@ public:
|
||||
|
||||
reAllocEventSize(1024);
|
||||
mSelfThreadID = -1;
|
||||
mTimer = std::make_shared<brynet::base::TimerMgr>();
|
||||
mTimer = std::make_shared<TimerMgr>();
|
||||
}
|
||||
|
||||
virtual ~EventLoop() BRYNET_NOEXCEPT {
|
||||
@ -247,8 +244,8 @@ public:
|
||||
|
||||
mAfterLoopFunctors.emplace_back(std::move(f));
|
||||
}
|
||||
brynet::base::Timer::WeakPtr runAfter(std::chrono::nanoseconds timeout, UserFunctor &&callback) {
|
||||
auto timer = std::make_shared<brynet::base::Timer>(
|
||||
Timer::WeakPtr runAfter(std::chrono::nanoseconds timeout, UserFunctor &&callback) {
|
||||
auto timer = std::make_shared<Timer>(
|
||||
std::chrono::steady_clock::now(),
|
||||
std::chrono::nanoseconds(timeout),
|
||||
std::move(callback));
|
||||
@ -266,7 +263,7 @@ public:
|
||||
}
|
||||
|
||||
inline bool isInLoopThread() const {
|
||||
return mSelfThreadID == current_thread::tid();
|
||||
return mSelfThreadID == tid();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -345,7 +342,7 @@ private:
|
||||
}
|
||||
void tryInitThreadID() {
|
||||
std::call_once(mOnceInitThreadID, [this]() {
|
||||
mSelfThreadID = current_thread::tid();
|
||||
mSelfThreadID = tid();
|
||||
});
|
||||
}
|
||||
|
||||
@ -363,7 +360,7 @@ private:
|
||||
std::vector<struct kevent> mEventEntries;
|
||||
int mKqueueFd;
|
||||
#endif
|
||||
std::unique_ptr<detail::WakeupChannel> mWakeupChannel;
|
||||
std::unique_ptr<WakeupChannel> mWakeupChannel;
|
||||
|
||||
std::atomic_bool mIsInBlock;
|
||||
std::atomic_bool mIsAlreadyPostWakeup;
|
||||
@ -376,13 +373,10 @@ private:
|
||||
std::vector<UserFunctor> mCopyAfterLoopFunctors;
|
||||
|
||||
std::once_flag mOnceInitThreadID;
|
||||
current_thread::THREAD_ID_TYPE mSelfThreadID;
|
||||
THREAD_ID_TYPE mSelfThreadID;
|
||||
|
||||
brynet::base::TimerMgr::Ptr mTimer;
|
||||
TimerMgr::Ptr mTimer;
|
||||
std::unordered_map<BrynetSocketFD, TcpConnectionPtr> mTcpConnections;
|
||||
|
||||
friend class TcpConnection;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -3,9 +3,6 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
class ConnectException : public std::runtime_error {
|
||||
public:
|
||||
explicit ConnectException(const std::string &message) :
|
||||
@ -27,6 +24,3 @@ public:
|
||||
std::runtime_error(message) {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
#include <brynet/net/detail/ListenThreadDetail.hpp>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
class ListenThread : public detail::ListenThreadDetail,
|
||||
class ListenThread : public ListenThreadDetail,
|
||||
public std::enable_shared_from_this<ListenThread> {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<ListenThread>;
|
||||
@ -13,11 +10,11 @@ public:
|
||||
using TcpSocketProcessCallback = std::function<void(TcpSocket &)>;
|
||||
|
||||
void startListen() {
|
||||
detail::ListenThreadDetail::startListen();
|
||||
ListenThreadDetail::startListen();
|
||||
}
|
||||
|
||||
void stopListen() {
|
||||
detail::ListenThreadDetail::stopListen();
|
||||
ListenThreadDetail::stopListen();
|
||||
}
|
||||
|
||||
public:
|
||||
@ -47,8 +44,5 @@ protected:
|
||||
const AccepCallback &callback,
|
||||
const std::vector<TcpSocketProcessCallback> &processCallbacks,
|
||||
bool enabledReusePort) :
|
||||
detail::ListenThreadDetail(isIPV6, ip, port, callback, processCallbacks, enabledReusePort) {}
|
||||
ListenThreadDetail(isIPV6, ip, port, callback, processCallbacks, enabledReusePort) {}
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -9,9 +9,6 @@
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace base {
|
||||
|
||||
#ifdef BRYNET_PLATFORM_WINDOWS
|
||||
const static int CHECK_READ_FLAG = (POLLIN | POLLRDNORM | POLLRDBAND);
|
||||
const static int CHECK_WRITE_FLAG = (POLLOUT | POLLWRNORM);
|
||||
@ -213,6 +210,3 @@ static bool poller_check(struct poller_s *self, BrynetSocketFD fd, enum CheckTyp
|
||||
}
|
||||
return check_event(pf, type);
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace brynet
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
#include <brynet/net/TcpService.hpp>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
/* binary search in memory */
|
||||
void memsearch(const char *hay, size_t haysize, const char *needle, size_t needlesize, size_t &result, bool &isOK) {
|
||||
size_t haypos, needlepos;
|
||||
@ -121,7 +118,7 @@ private:
|
||||
|
||||
std::shared_ptr<PromiseReceive> setupPromiseReceive(const TcpConnection::Ptr &session) {
|
||||
auto promiseReceive = std::make_shared<PromiseReceive>();
|
||||
session->setDataCallback([promiseReceive](brynet::base::BasePacketReader &reader) {
|
||||
session->setDataCallback([promiseReceive](BasePacketReader &reader) {
|
||||
auto procLen = promiseReceive->process(reader.begin(), reader.size());
|
||||
reader.addPos(procLen);
|
||||
reader.savePos();
|
||||
@ -129,6 +126,3 @@ std::shared_ptr<PromiseReceive> setupPromiseReceive(const TcpConnection::Ptr &se
|
||||
|
||||
return promiseReceive;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -22,9 +22,6 @@ extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
#ifdef BRYNET_USE_OPENSSL
|
||||
|
||||
#ifndef CRYPTO_THREADID_set_callback
|
||||
@ -69,7 +66,7 @@ static void InitCryptoThreadSafeSupport() {
|
||||
}
|
||||
#endif
|
||||
|
||||
class SSLHelper : public brynet::base::NonCopyable,
|
||||
class SSLHelper : public NonCopyable,
|
||||
public std::enable_shared_from_this<SSLHelper> {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<SSLHelper>;
|
||||
@ -152,5 +149,3 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -1,9 +1,6 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
class SendableMsg {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<SendableMsg>;
|
||||
@ -48,5 +45,3 @@ static SendableMsg::Ptr MakeStringMsg(std::string &&buffer) {
|
||||
return std::make_shared<StringSendMsg>(std::move(buffer));
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
@ -7,18 +7,15 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
class TcpConnection;
|
||||
|
||||
class UniqueFd final : public brynet::base::NonCopyable {
|
||||
class UniqueFd final : public NonCopyable {
|
||||
public:
|
||||
explicit UniqueFd(BrynetSocketFD fd) :
|
||||
mFD(fd) {}
|
||||
|
||||
~UniqueFd() {
|
||||
brynet::net::base::SocketClose(mFD);
|
||||
SocketClose(mFD);
|
||||
}
|
||||
|
||||
UniqueFd(const UniqueFd &other) = delete;
|
||||
@ -32,7 +29,7 @@ private:
|
||||
BrynetSocketFD mFD;
|
||||
};
|
||||
|
||||
class TcpSocket : public brynet::base::NonCopyable {
|
||||
class TcpSocket : public NonCopyable {
|
||||
private:
|
||||
class TcpSocketDeleter {
|
||||
public:
|
||||
@ -57,23 +54,23 @@ public:
|
||||
|
||||
public:
|
||||
void setNodelay() const {
|
||||
brynet::net::base::SocketNodelay(mFD);
|
||||
SocketNodelay(mFD);
|
||||
}
|
||||
|
||||
bool setNonblock() const {
|
||||
return brynet::net::base::SocketNonblock(mFD);
|
||||
return SocketNonblock(mFD);
|
||||
}
|
||||
|
||||
void setSendSize(int sdSize) const {
|
||||
brynet::net::base::SocketSetSendSize(mFD, sdSize);
|
||||
SocketSetSendSize(mFD, sdSize);
|
||||
}
|
||||
|
||||
void setRecvSize(int rdSize) const {
|
||||
brynet::net::base::SocketSetRecvSize(mFD, rdSize);
|
||||
SocketSetRecvSize(mFD, rdSize);
|
||||
}
|
||||
|
||||
std::string getRemoteIP() const {
|
||||
return brynet::net::base::GetIPOfSocket(mFD);
|
||||
return GetIPOfSocket(mFD);
|
||||
}
|
||||
|
||||
bool isServerSide() const {
|
||||
@ -87,7 +84,7 @@ protected:
|
||||
}
|
||||
|
||||
virtual ~TcpSocket() {
|
||||
brynet::net::base::SocketClose(mFD);
|
||||
SocketClose(mFD);
|
||||
}
|
||||
|
||||
BrynetSocketFD getFD() const {
|
||||
@ -118,7 +115,7 @@ private:
|
||||
int mErrorCode;
|
||||
};
|
||||
|
||||
class ListenSocket : public brynet::base::NonCopyable {
|
||||
class ListenSocket : public NonCopyable {
|
||||
private:
|
||||
class ListenSocketDeleter {
|
||||
public:
|
||||
@ -132,7 +129,7 @@ public:
|
||||
|
||||
public:
|
||||
TcpSocket::Ptr accept() {
|
||||
const auto clientFD = brynet::net::base::Accept(mFD, nullptr, nullptr);
|
||||
const auto clientFD = Accept(mFD, nullptr, nullptr);
|
||||
if (clientFD == BRYNET_INVALID_SOCKET) {
|
||||
#if defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN
|
||||
if (BRYNET_ERRNO == EMFILE) {
|
||||
@ -141,8 +138,8 @@ public:
|
||||
// accept()ing when you can't" in libev's doc.
|
||||
// By Marc Lehmann, author of libev.
|
||||
mIdle.reset();
|
||||
TcpSocket::Create(brynet::net::base::Accept(mFD, nullptr, nullptr), true);
|
||||
mIdle = brynet::net::TcpSocket::Create(::open("/dev/null", O_RDONLY | O_CLOEXEC), true);
|
||||
TcpSocket::Create(Accept(mFD, nullptr, nullptr), true);
|
||||
mIdle = TcpSocket::Create(::open("/dev/null", O_RDONLY | O_CLOEXEC), true);
|
||||
}
|
||||
#endif
|
||||
if (BRYNET_ERRNO == EINTR) {
|
||||
@ -170,22 +167,20 @@ protected:
|
||||
explicit ListenSocket(BrynetSocketFD fd) :
|
||||
mFD(fd) {
|
||||
#if defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN
|
||||
mIdle = brynet::net::TcpSocket::Create(::open("/dev/null", O_RDONLY | O_CLOEXEC), true);
|
||||
mIdle = TcpSocket::Create(::open("/dev/null", O_RDONLY | O_CLOEXEC), true);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~ListenSocket() {
|
||||
brynet::net::base::SocketClose(mFD);
|
||||
SocketClose(mFD);
|
||||
}
|
||||
|
||||
private:
|
||||
const BrynetSocketFD mFD;
|
||||
#if defined BRYNET_PLATFORM_LINUX || defined BRYNET_PLATFORM_DARWIN
|
||||
brynet::net::TcpSocket::Ptr mIdle;
|
||||
TcpSocket::Ptr mIdle;
|
||||
#endif
|
||||
|
||||
friend class TcpConnection;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -5,10 +5,6 @@
|
||||
#include <brynet/net/SocketLibTypes.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace base {
|
||||
|
||||
static bool InitSocket() {
|
||||
bool ret = true;
|
||||
#ifdef BRYNET_PLATFORM_WINDOWS
|
||||
@ -289,7 +285,3 @@ static bool IsSelfConnect(BrynetSocketFD fd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -34,17 +34,14 @@ extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
class TcpConnection : public Channel,
|
||||
public brynet::base::NonCopyable,
|
||||
public NonCopyable,
|
||||
public std::enable_shared_from_this<TcpConnection> {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<TcpConnection>;
|
||||
|
||||
using EnterCallback = std::function<void(Ptr)>;
|
||||
using DataCallback = std::function<void(brynet::base::BasePacketReader &)>;
|
||||
using DataCallback = std::function<void(BasePacketReader &)>;
|
||||
using DisconnectedCallback = std::function<void(Ptr)>;
|
||||
using PacketSendedCallback = std::function<void(void)>;
|
||||
using HighWaterCallback = std::function<void(void)>;
|
||||
@ -132,7 +129,7 @@ public:
|
||||
send(MakeStringMsg(std::move(buffer)), std::move(callback));
|
||||
}
|
||||
|
||||
// setDataCallback(std::function<void(brynet::base::BasePacketReader&)>)
|
||||
// setDataCallback(std::function<void(BasePacketReader&)>)
|
||||
template <typename Callback>
|
||||
void setDataCallback(Callback &&cb) {
|
||||
verifyArgType(cb, &Callback::operator());
|
||||
@ -280,7 +277,7 @@ private:
|
||||
|
||||
void growRecvBuffer() {
|
||||
if (mRecvBuffer == nullptr) {
|
||||
mRecvBuffer.reset(brynet::base::buffer_new(std::min<size_t>(16 * 1024, mMaxRecvBufferSize)));
|
||||
mRecvBuffer.reset(buffer_new(std::min<size_t>(16 * 1024, mMaxRecvBufferSize)));
|
||||
mRecvBuffOriginSize = buffer_getsize(mRecvBuffer.get());
|
||||
} else {
|
||||
if (buffer_getsize(mRecvBuffer.get()) >= mMaxRecvBufferSize) {
|
||||
@ -293,7 +290,7 @@ private:
|
||||
const auto NewSize = mRecvBuffOriginSize + (maxSizeDiff * newTanh);
|
||||
|
||||
assert(NewSize <= mMaxRecvBufferSize);
|
||||
std::unique_ptr<struct brynet::base::buffer_s, BufferDeleter> newBuffer(brynet::base::buffer_new(NewSize));
|
||||
std::unique_ptr<struct buffer_s, BufferDeleter> newBuffer(buffer_new(NewSize));
|
||||
buffer_write(newBuffer.get(),
|
||||
buffer_getreadptr(mRecvBuffer.get()),
|
||||
buffer_getreadvalidcount(mRecvBuffer.get()));
|
||||
@ -310,8 +307,8 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<struct brynet::base::buffer_s, BufferDeleter>
|
||||
newBuffer(brynet::base::buffer_new(newSize));
|
||||
std::unique_ptr<struct buffer_s, BufferDeleter>
|
||||
newBuffer(buffer_new(newSize));
|
||||
buffer_write(newBuffer.get(),
|
||||
buffer_getreadptr(mRecvBuffer.get()),
|
||||
buffer_getreadvalidcount(mRecvBuffer.get()));
|
||||
@ -328,7 +325,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!brynet::net::base::SocketNonblock(mSocket->getFD()) ||
|
||||
if (!SocketNonblock(mSocket->getFD()) ||
|
||||
!mEventLoop->linkChannel(mSocket->getFD(), this)) {
|
||||
return false;
|
||||
}
|
||||
@ -975,7 +972,7 @@ private:
|
||||
|
||||
void processRecvMessage() {
|
||||
if (mDataCallback != nullptr && buffer_getreadvalidcount(mRecvBuffer.get()) > 0) {
|
||||
auto reader = brynet::base::BasePacketReader(buffer_getreadptr(mRecvBuffer.get()),
|
||||
auto reader = BasePacketReader(buffer_getreadptr(mRecvBuffer.get()),
|
||||
buffer_getreadvalidcount(mRecvBuffer.get()), false);
|
||||
mDataCallback(reader);
|
||||
const auto consumedLen = reader.savedPos();
|
||||
@ -1009,11 +1006,11 @@ private:
|
||||
|
||||
class BufferDeleter {
|
||||
public:
|
||||
void operator()(struct brynet::base::buffer_s *ptr) const {
|
||||
brynet::base::buffer_delete(ptr);
|
||||
void operator()(struct buffer_s *ptr) const {
|
||||
buffer_delete(ptr);
|
||||
}
|
||||
};
|
||||
std::unique_ptr<struct brynet::base::buffer_s, BufferDeleter> mRecvBuffer;
|
||||
std::unique_ptr<struct buffer_s, BufferDeleter> mRecvBuffer;
|
||||
double mCurrentTanhXDiff = 0;
|
||||
size_t mRecvBuffOriginSize = 0;
|
||||
const size_t mMaxRecvBufferSize;
|
||||
@ -1043,8 +1040,5 @@ private:
|
||||
#endif
|
||||
bool mRecvData;
|
||||
std::chrono::nanoseconds mCheckTime{};
|
||||
brynet::base::Timer::WeakPtr mTimer;
|
||||
Timer::WeakPtr mTimer;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -2,15 +2,12 @@
|
||||
|
||||
#include <brynet/net/detail/TCPServiceDetail.hpp>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
|
||||
using ConnectionOption = detail::ConnectionOption;
|
||||
class TcpService : public detail::TcpServiceDetail,
|
||||
using ConnectionOption = ConnectionOption;
|
||||
class TcpService : public TcpServiceDetail,
|
||||
public std::enable_shared_from_this<TcpService> {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<TcpService>;
|
||||
using FrameCallback = detail::TcpServiceDetail::FrameCallback;
|
||||
using FrameCallback = TcpServiceDetail::FrameCallback;
|
||||
|
||||
public:
|
||||
static Ptr Create() {
|
||||
@ -21,24 +18,21 @@ public:
|
||||
|
||||
void startWorkerThread(size_t threadNum,
|
||||
FrameCallback callback = nullptr) {
|
||||
detail::TcpServiceDetail::startWorkerThread(threadNum, callback);
|
||||
TcpServiceDetail::startWorkerThread(threadNum, callback);
|
||||
}
|
||||
|
||||
void stopWorkerThread() {
|
||||
detail::TcpServiceDetail::stopWorkerThread();
|
||||
TcpServiceDetail::stopWorkerThread();
|
||||
}
|
||||
|
||||
bool addTcpConnection(TcpSocket::Ptr socket, ConnectionOption options) {
|
||||
return detail::TcpServiceDetail::addTcpConnection(std::move(socket), options);
|
||||
return TcpServiceDetail::addTcpConnection(std::move(socket), options);
|
||||
}
|
||||
|
||||
EventLoop::Ptr getRandomEventLoop() {
|
||||
return detail::TcpServiceDetail::getRandomEventLoop();
|
||||
return TcpServiceDetail::getRandomEventLoop();
|
||||
}
|
||||
|
||||
private:
|
||||
TcpService() = default;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -3,10 +3,6 @@
|
||||
#include <brynet/net/SSLHelper.hpp>
|
||||
#include <brynet/net/TcpConnection.hpp>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace detail {
|
||||
|
||||
class ConnectionOption final {
|
||||
public:
|
||||
std::vector<TcpConnection::EnterCallback> enterCallback;
|
||||
@ -15,7 +11,3 @@ public:
|
||||
bool forceSameThreadLoop = false;
|
||||
size_t maxRecvBufferSize = 128;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -15,11 +15,7 @@
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace detail {
|
||||
|
||||
class AsyncConnectorDetail : public brynet::base::NonCopyable {
|
||||
class AsyncConnectorDetail : public NonCopyable {
|
||||
protected:
|
||||
void startWorkerThread() {
|
||||
#ifdef BRYNET_HAVE_LANG_CXX17
|
||||
@ -33,7 +29,7 @@ protected:
|
||||
}
|
||||
|
||||
mIsRun = std::make_shared<bool>(true);
|
||||
mWorkInfo = std::make_shared<detail::ConnectorWorkInfo>();
|
||||
mWorkInfo = std::make_shared<ConnectorWorkInfo>();
|
||||
mEventLoop = std::make_shared<EventLoop>();
|
||||
|
||||
auto eventLoop = mEventLoop;
|
||||
@ -42,7 +38,7 @@ protected:
|
||||
|
||||
mThread = std::make_shared<std::thread>([eventLoop, workerInfo, isRun]() {
|
||||
while (*isRun) {
|
||||
detail::RunOnceCheckConnect(eventLoop, workerInfo);
|
||||
RunOnceCheckConnect(eventLoop, workerInfo);
|
||||
}
|
||||
|
||||
workerInfo->causeAllFailed();
|
||||
@ -78,7 +74,7 @@ protected:
|
||||
mThread = nullptr;
|
||||
}
|
||||
|
||||
void asyncConnect(detail::ConnectOption option) {
|
||||
void asyncConnect(ConnectOption option) {
|
||||
#ifdef BRYNET_HAVE_LANG_CXX17
|
||||
std::shared_lock<std::shared_mutex> lck(mThreadGuard);
|
||||
#else
|
||||
@ -97,7 +93,7 @@ protected:
|
||||
}
|
||||
|
||||
auto workInfo = mWorkInfo;
|
||||
auto address = detail::AsyncConnectAddr(std::move(option.ip),
|
||||
auto address = AsyncConnectAddr(std::move(option.ip),
|
||||
option.port,
|
||||
option.timeout,
|
||||
std::move(option.completedCallback),
|
||||
@ -120,7 +116,7 @@ protected:
|
||||
private:
|
||||
std::shared_ptr<EventLoop> mEventLoop;
|
||||
|
||||
std::shared_ptr<detail::ConnectorWorkInfo> mWorkInfo;
|
||||
std::shared_ptr<ConnectorWorkInfo> mWorkInfo;
|
||||
std::shared_ptr<std::thread> mThread;
|
||||
#ifdef BRYNET_HAVE_LANG_CXX17
|
||||
std::shared_mutex mThreadGuard;
|
||||
@ -130,6 +126,3 @@ private:
|
||||
std::shared_ptr<bool> mIsRun;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -16,10 +16,6 @@
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace detail {
|
||||
|
||||
class AsyncConnectAddr final {
|
||||
public:
|
||||
using CompletedCallback = std::function<void(TcpSocket::Ptr)>;
|
||||
@ -74,13 +70,13 @@ private:
|
||||
const std::vector<ProcessTcpSocketCallback> mProcessCallbacks;
|
||||
};
|
||||
|
||||
class ConnectorWorkInfo final : public brynet::base::NonCopyable {
|
||||
class ConnectorWorkInfo final : public NonCopyable {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<ConnectorWorkInfo>;
|
||||
|
||||
ConnectorWorkInfo() BRYNET_NOEXCEPT {
|
||||
mPoller.reset(brynet::base::poller_new());
|
||||
mPollResult.reset(brynet::base::stack_new(1024, sizeof(BrynetSocketFD)));
|
||||
mPoller.reset(poller_new());
|
||||
mPollResult.reset(stack_new(1024, sizeof(BrynetSocketFD)));
|
||||
}
|
||||
|
||||
void checkConnectStatus(int millSecond) {
|
||||
@ -91,7 +87,7 @@ public:
|
||||
std::set<BrynetSocketFD> totalFds;
|
||||
std::set<BrynetSocketFD> successFds;
|
||||
|
||||
poller_visitor(mPoller.get(), brynet::base::WriteCheck, mPollResult.get());
|
||||
poller_visitor(mPoller.get(), WriteCheck, mPollResult.get());
|
||||
while (true) {
|
||||
auto p = stack_popfront(mPollResult.get());
|
||||
if (p == nullptr) {
|
||||
@ -101,7 +97,7 @@ public:
|
||||
const auto fd = *(BrynetSocketFD *)p;
|
||||
totalFds.insert(fd);
|
||||
if (isConnectSuccess(fd, false) &&
|
||||
!brynet::net::base::IsSelfConnect(fd)) {
|
||||
!IsSelfConnect(fd)) {
|
||||
successFds.insert(fd);
|
||||
}
|
||||
}
|
||||
@ -134,7 +130,7 @@ public:
|
||||
}
|
||||
|
||||
bool isConnectSuccess(BrynetSocketFD clientfd, bool willCheckWrite) const {
|
||||
if (willCheckWrite && !poller_check(mPoller.get(), clientfd, brynet::base::WriteCheck)) {
|
||||
if (willCheckWrite && !poller_check(mPoller.get(), clientfd, WriteCheck)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -165,7 +161,7 @@ public:
|
||||
poller_remove(mPoller.get(), fd);
|
||||
mConnectingInfos.erase(it++);
|
||||
|
||||
brynet::net::base::SocketClose(fd);
|
||||
SocketClose(fd);
|
||||
if (cb != nullptr) {
|
||||
//TODO::don't modify mConnectingInfos in cb
|
||||
cb();
|
||||
@ -184,21 +180,21 @@ public:
|
||||
#endif
|
||||
int n = 0;
|
||||
|
||||
brynet::net::base::InitSocket();
|
||||
InitSocket();
|
||||
|
||||
clientfd = brynet::net::base::SocketCreate(AF_INET, SOCK_STREAM, 0);
|
||||
clientfd = SocketCreate(AF_INET, SOCK_STREAM, 0);
|
||||
if (clientfd == BRYNET_INVALID_SOCKET) {
|
||||
goto FAILED;
|
||||
}
|
||||
|
||||
brynet::net::base::SocketNonblock(clientfd);
|
||||
SocketNonblock(clientfd);
|
||||
server_addr.sin_family = AF_INET;
|
||||
inet_pton(AF_INET, addr.getIP().c_str(), &server_addr.sin_addr.s_addr);
|
||||
server_addr.sin_port = static_cast<decltype(server_addr.sin_port)>(htons(addr.getPort()));
|
||||
|
||||
n = connect(clientfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
|
||||
if (n == 0) {
|
||||
if (brynet::net::base::IsSelfConnect(clientfd)) {
|
||||
if (IsSelfConnect(clientfd)) {
|
||||
goto FAILED;
|
||||
}
|
||||
} else if (BRYNET_ERRNO != ExpectedError) {
|
||||
@ -212,7 +208,7 @@ public:
|
||||
ci.processCallbacks = addr.getProcessCallbacks();
|
||||
|
||||
mConnectingInfos[clientfd] = ci;
|
||||
poller_add(mPoller.get(), clientfd, brynet::base::WriteCheck);
|
||||
poller_add(mPoller.get(), clientfd, WriteCheck);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -228,7 +224,7 @@ public:
|
||||
|
||||
FAILED:
|
||||
if (clientfd != BRYNET_INVALID_SOCKET) {
|
||||
brynet::net::base::SocketClose(clientfd);
|
||||
SocketClose(clientfd);
|
||||
clientfd = BRYNET_INVALID_SOCKET;
|
||||
(void)clientfd;
|
||||
}
|
||||
@ -246,7 +242,7 @@ public:
|
||||
auto cb = v.second.failedCB;
|
||||
|
||||
poller_remove(mPoller.get(), fd);
|
||||
brynet::net::base::SocketClose(fd);
|
||||
SocketClose(fd);
|
||||
if (cb != nullptr) {
|
||||
cb();
|
||||
}
|
||||
@ -271,23 +267,23 @@ private:
|
||||
|
||||
class PollerDeleter {
|
||||
public:
|
||||
void operator()(struct brynet::base::poller_s *ptr) const {
|
||||
brynet::base::poller_delete(ptr);
|
||||
void operator()(struct poller_s *ptr) const {
|
||||
poller_delete(ptr);
|
||||
}
|
||||
};
|
||||
class StackDeleter {
|
||||
public:
|
||||
void operator()(struct brynet::base::stack_s *ptr) const {
|
||||
brynet::base::stack_delete(ptr);
|
||||
void operator()(struct stack_s *ptr) const {
|
||||
stack_delete(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<struct brynet::base::poller_s, PollerDeleter> mPoller;
|
||||
std::unique_ptr<struct brynet::base::stack_s, StackDeleter> mPollResult;
|
||||
std::unique_ptr<struct poller_s, PollerDeleter> mPoller;
|
||||
std::unique_ptr<struct stack_s, StackDeleter> mPollResult;
|
||||
};
|
||||
|
||||
static void RunOnceCheckConnect(
|
||||
const std::shared_ptr<brynet::net::EventLoop> &eventLoop,
|
||||
const std::shared_ptr<EventLoop> &eventLoop,
|
||||
const std::shared_ptr<ConnectorWorkInfo> &workerInfo) {
|
||||
eventLoop->loop(std::chrono::milliseconds(10).count());
|
||||
workerInfo->checkConnectStatus(0);
|
||||
@ -303,7 +299,3 @@ public:
|
||||
AsyncConnectAddr::CompletedCallback completedCallback;
|
||||
AsyncConnectAddr::FailedCallback failedCallback;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -5,13 +5,9 @@
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace detail {
|
||||
|
||||
class TcpServiceDetail;
|
||||
|
||||
class IOLoopData : public brynet::base::NonCopyable,
|
||||
class IOLoopData : public NonCopyable,
|
||||
public std::enable_shared_from_this<IOLoopData> {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<IOLoopData>;
|
||||
@ -53,7 +49,3 @@ private:
|
||||
};
|
||||
|
||||
using IOLoopDataPtr = std::shared_ptr<IOLoopData>;
|
||||
|
||||
} // namespace detail
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -14,11 +14,7 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace detail {
|
||||
|
||||
class ListenThreadDetail : public brynet::base::NonCopyable {
|
||||
class ListenThreadDetail : public NonCopyable {
|
||||
protected:
|
||||
using AccepCallback = std::function<void(TcpSocket::Ptr)>;
|
||||
using TcpSocketProcessCallback = std::function<void(TcpSocket &)>;
|
||||
@ -30,7 +26,7 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
const auto fd = brynet::net::base::Listen(mIsIPV6, mIP.c_str(), mPort, 512, mEnabledReusePort);
|
||||
const auto fd = Listen(mIsIPV6, mIP.c_str(), mPort, 512, mEnabledReusePort);
|
||||
if (fd == BRYNET_INVALID_SOCKET) {
|
||||
throw BrynetCommonException(
|
||||
std::string("listen error of:") + std::to_string(BRYNET_ERRNO));
|
||||
@ -77,7 +73,7 @@ protected:
|
||||
connector->startWorkerThread();
|
||||
|
||||
//TODO:: if the listen enable reuse_port, one time connect may be can't wakeup listen.
|
||||
wrapper::SocketConnectBuilder connectBuilder;
|
||||
SocketConnectBuilder connectBuilder;
|
||||
(void)connectBuilder
|
||||
.WithConnector(connector)
|
||||
.WithTimeout(std::chrono::seconds(2))
|
||||
@ -118,7 +114,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
static brynet::net::TcpSocket::Ptr runOnceListen(const std::shared_ptr<ListenSocket> &listenSocket) {
|
||||
static TcpSocket::Ptr runOnceListen(const std::shared_ptr<ListenSocket> &listenSocket) {
|
||||
try {
|
||||
return listenSocket->accept();
|
||||
} catch (const EintrError &e) {
|
||||
@ -142,7 +138,3 @@ private:
|
||||
std::shared_ptr<std::thread> mListenThread;
|
||||
std::mutex mListenThreadGuard;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -13,11 +13,7 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace detail {
|
||||
|
||||
class TcpServiceDetail : public brynet::base::NonCopyable {
|
||||
class TcpServiceDetail : public NonCopyable {
|
||||
protected:
|
||||
using FrameCallback = std::function<void(const EventLoop::Ptr &)>;
|
||||
const static unsigned int sDefaultLoopTimeOutMS = 100;
|
||||
@ -144,7 +140,3 @@ private:
|
||||
std::mutex mServiceGuard;
|
||||
std::mt19937 mRandom;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -8,12 +8,8 @@
|
||||
#include <brynet/net/Channel.hpp>
|
||||
#include <brynet/net/Socket.hpp>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace detail {
|
||||
|
||||
#ifdef BRYNET_PLATFORM_WINDOWS
|
||||
class WakeupChannel final : public Channel, public brynet::base::NonCopyable {
|
||||
class WakeupChannel final : public Channel, public NonCopyable {
|
||||
public:
|
||||
explicit WakeupChannel(HANDLE iocp) :
|
||||
mIOCP(iocp),
|
||||
@ -44,7 +40,7 @@ private:
|
||||
port::Win::OverlappedExt mWakeupOvl;
|
||||
};
|
||||
#elif defined BRYNET_PLATFORM_LINUX
|
||||
class WakeupChannel final : public Channel, public brynet::base::NonCopyable {
|
||||
class WakeupChannel final : public Channel, public NonCopyable {
|
||||
public:
|
||||
explicit WakeupChannel(BrynetSocketFD fd) :
|
||||
mUniqueFd(fd) {
|
||||
@ -77,7 +73,7 @@ private:
|
||||
};
|
||||
|
||||
#elif defined BRYNET_PLATFORM_DARWIN
|
||||
class WakeupChannel final : public Channel, public brynet::base::NonCopyable {
|
||||
class WakeupChannel final : public Channel, public NonCopyable {
|
||||
public:
|
||||
explicit WakeupChannel(int kqueuefd, int ident) :
|
||||
mKqueueFd(kqueuefd),
|
||||
@ -108,6 +104,3 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -5,10 +5,6 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace http {
|
||||
|
||||
class HttpQueryParameter final {
|
||||
public:
|
||||
void add(const std::string &k, const std::string &v) {
|
||||
@ -198,7 +194,3 @@ private:
|
||||
std::map<std::string, std::string> mHeadField;
|
||||
std::string mBody;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -8,10 +8,6 @@
|
||||
|
||||
#include "http_parser.h"
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace http {
|
||||
|
||||
class HttpService;
|
||||
|
||||
class HTTPParser {
|
||||
@ -284,7 +280,3 @@ private:
|
||||
private:
|
||||
friend class HttpService;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -6,14 +6,10 @@
|
||||
#include <brynet/net/http/WebSocketFormat.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace http {
|
||||
|
||||
class HttpService;
|
||||
class HttpSessionHandlers;
|
||||
|
||||
class HttpSession : public brynet::base::NonCopyable {
|
||||
class HttpSession : public NonCopyable {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<HttpSession>;
|
||||
|
||||
@ -172,7 +168,7 @@ private:
|
||||
});
|
||||
|
||||
session->setDataCallback([httpSession, httpParser](
|
||||
brynet::base::BasePacketReader &reader) {
|
||||
BasePacketReader &reader) {
|
||||
size_t retLen = 0;
|
||||
|
||||
if (httpParser->isWebSocket()) {
|
||||
@ -301,6 +297,3 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -8,10 +8,6 @@
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace http {
|
||||
|
||||
class WebSocketFormat {
|
||||
public:
|
||||
enum class WebSocketFrameType {
|
||||
@ -33,7 +29,7 @@ public:
|
||||
unsigned char puDest[20];
|
||||
s1.GetHash(puDest);
|
||||
|
||||
std::string base64Str = brynet::base::crypto::base64_encode((const unsigned char *)puDest, 20);
|
||||
std::string base64Str = base64_encode((const unsigned char *)puDest, 20);
|
||||
|
||||
std::string response =
|
||||
"HTTP/1.1 101 Switching Protocols\r\n"
|
||||
@ -206,7 +202,3 @@ public:
|
||||
isFin);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
#include <brynet/net/SocketLibTypes.hpp>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace port {
|
||||
|
||||
#ifdef BRYNET_PLATFORM_WINDOWS
|
||||
class Win {
|
||||
@ -25,7 +22,3 @@ public:
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace port
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -6,13 +6,9 @@
|
||||
#include <future>
|
||||
#include <utility>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace wrapper {
|
||||
|
||||
using CompletedCallback = detail::AsyncConnectAddr::CompletedCallback;
|
||||
using ProcessTcpSocketCallback = detail::AsyncConnectAddr::ProcessTcpSocketCallback;
|
||||
using FailedCallback = detail::AsyncConnectAddr::FailedCallback;
|
||||
using CompletedCallback = AsyncConnectAddr::CompletedCallback;
|
||||
using ProcessTcpSocketCallback = AsyncConnectAddr::ProcessTcpSocketCallback;
|
||||
using FailedCallback = AsyncConnectAddr::FailedCallback;
|
||||
|
||||
template <typename Derived>
|
||||
class BaseSocketConnectBuilder {
|
||||
@ -179,7 +175,3 @@ private:
|
||||
|
||||
class ConnectionBuilder : public BaseConnectionBuilder<ConnectionBuilder> {
|
||||
};
|
||||
|
||||
} // namespace wrapper
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -4,10 +4,6 @@
|
||||
#include <brynet/net/wrapper/ConnectionBuilder.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace wrapper {
|
||||
|
||||
class HttpConnectionBuilder {
|
||||
public:
|
||||
HttpConnectionBuilder &WithService(TcpService::Ptr service) {
|
||||
@ -35,7 +31,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
HttpConnectionBuilder &WithEnterCallback(http::HttpSession::EnterCallback &&callback) {
|
||||
HttpConnectionBuilder &WithEnterCallback(HttpSession::EnterCallback &&callback) {
|
||||
mHttpEnterCallback = std::move(callback);
|
||||
return *this;
|
||||
}
|
||||
@ -69,16 +65,13 @@ public:
|
||||
auto callback = mHttpEnterCallback;
|
||||
auto builder = mBuilder;
|
||||
builder.AddEnterCallback([callback](const TcpConnection::Ptr &session) {
|
||||
http::HttpService::setup(session, callback);
|
||||
HttpService::setup(session, callback);
|
||||
});
|
||||
builder.asyncConnect();
|
||||
}
|
||||
|
||||
private:
|
||||
http::HttpSession::EnterCallback mHttpEnterCallback;
|
||||
HttpSession::EnterCallback mHttpEnterCallback;
|
||||
ConnectionBuilder mBuilder;
|
||||
};
|
||||
|
||||
} // namespace wrapper
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -4,10 +4,6 @@
|
||||
#include <brynet/net/wrapper/ServiceBuilder.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace wrapper {
|
||||
|
||||
class HttpListenerBuilder {
|
||||
public:
|
||||
HttpListenerBuilder &WithService(TcpService::Ptr service) {
|
||||
@ -15,7 +11,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
HttpListenerBuilder &WithEnterCallback(http::HttpSession::EnterCallback &&callback) {
|
||||
HttpListenerBuilder &WithEnterCallback(HttpSession::EnterCallback &&callback) {
|
||||
mHttpEnterCallback = std::move(callback);
|
||||
return *this;
|
||||
}
|
||||
@ -57,16 +53,12 @@ public:
|
||||
|
||||
auto callback = mHttpEnterCallback;
|
||||
mBuilder.AddEnterCallback([callback](const TcpConnection::Ptr &session) {
|
||||
http::HttpService::setup(session, callback);
|
||||
HttpService::setup(session, callback);
|
||||
});
|
||||
mBuilder.asyncRun();
|
||||
}
|
||||
|
||||
private:
|
||||
http::HttpSession::EnterCallback mHttpEnterCallback;
|
||||
HttpSession::EnterCallback mHttpEnterCallback;
|
||||
ListenerBuilder mBuilder;
|
||||
};
|
||||
|
||||
} // namespace wrapper
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
@ -6,10 +6,6 @@
|
||||
#include <brynet/net/detail/ConnectionOption.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace brynet {
|
||||
namespace net {
|
||||
namespace wrapper {
|
||||
|
||||
template <typename Derived>
|
||||
class BaseListenerBuilder {
|
||||
public:
|
||||
@ -72,7 +68,7 @@ public:
|
||||
mIsIpV6,
|
||||
mListenAddr,
|
||||
mPort,
|
||||
[service, option](brynet::net::TcpSocket::Ptr socket) {
|
||||
[service, option](TcpSocket::Ptr socket) {
|
||||
service->addTcpConnection(std::move(socket), option);
|
||||
},
|
||||
mSocketProcessCallbacks,
|
||||
@ -99,7 +95,3 @@ private:
|
||||
|
||||
class ListenerBuilder : public BaseListenerBuilder<ListenerBuilder> {
|
||||
};
|
||||
|
||||
} // namespace wrapper
|
||||
} // namespace net
|
||||
} // namespace brynet
|
||||
|
Loading…
Reference in New Issue
Block a user