Archived
1
0

make read buffer size templated

This commit is contained in:
Jeff Becker 2018-05-06 08:17:32 -04:00
parent 242e996ded
commit 9d33a89bc1
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 10 additions and 5 deletions

View File

@ -14,11 +14,12 @@ namespace nntpchan
{ {
namespace ev namespace ev
{ {
template<size_t bufsz>
struct EpollLoop : public Loop struct EpollLoop : public Loop
{ {
size_t conns; size_t conns;
int epollfd; int epollfd;
char readbuf[128]; char readbuf[bufsz];
EpollLoop() : conns(0), epollfd(epoll_create1(EPOLL_CLOEXEC)) EpollLoop() : conns(0), epollfd(epoll_create1(EPOLL_CLOEXEC))
{ {
} }

View File

@ -1,14 +1,17 @@
#include <fcntl.h> #include <fcntl.h>
constexpr size_t ev_buffsz = 512;
#ifdef __linux__ #ifdef __linux__
#include "epoll.hpp" #include "epoll.hpp"
typedef nntpchan::ev::EpollLoop LoopImpl; typedef nntpchan::ev::EpollLoop<ev_buffsz> LoopImpl;
#else #else
#ifdef __freebsd__ #ifdef __freebsd__
#include "kqueue.hpp" #include "kqueue.hpp"
typedef nntpchan::ev::KqueueLoop LoopImpl; typedef nntpchan::ev::KqueueLoop<ev_buffsz> LoopImpl;
#else #else
#ifdef __netbsd__ #ifdef __netbsd__
typedef nntpchan::ev::KqueueLoop LoopImpl; typedef nntpchan::ev::KqueueLoop<ev_buffsz> LoopImpl;
#else #else
#error "unsupported platform" #error "unsupported platform"
#endif #endif

View File

@ -6,11 +6,12 @@ namespace nntpchan
{ {
namespace ev namespace ev
{ {
template<size_t bufsz>
struct KqueueLoop : public Loop struct KqueueLoop : public Loop
{ {
int kfd; int kfd;
size_t conns; size_t conns;
char readbuf[1024]; char readbuf[bufsz];
KqueueLoop() : kfd(kqueue()), conns(0) KqueueLoop() : kfd(kqueue()), conns(0)