Browse Source

Added support of snd/rcv buf options for all protocols

master
Artyom Beilis 6 years ago
parent
commit
02d07bf629
3 changed files with 26 additions and 1 deletions
  1. +19
    -1
      private/cgi_acceptor.h
  2. +2
    -0
      private/cgi_api.h
  3. +5
    -0
      src/service.cpp

+ 19
- 1
private/cgi_acceptor.h View File

@@ -43,7 +43,9 @@ namespace impl {
srv_(srv), srv_(srv),
acceptor_(srv_.get_io_service()), acceptor_(srv_.get_io_service()),
stopped_(false), stopped_(false),
tcp_(true)
tcp_(true),
sndbuf_(-1),
rcvbuf_(-1)
{ {
io::endpoint ep(ip,port); io::endpoint ep(ip,port);
acceptor_.open(ep.family()); acceptor_.open(ep.family());
@@ -133,12 +135,27 @@ namespace impl {
acceptor_.cancel(); acceptor_.cancel();
} }


void sndbuf(int v)
{
sndbuf_ = v;
}
void rcvbuf(int v)

{
rcvbuf_ = v;
}

private: private:
void on_accept(booster::system::error_code const &e) void on_accept(booster::system::error_code const &e)
{ {
if(!e) { if(!e) {
if(tcp_) if(tcp_)
asio_socket_->set_option(io::basic_socket::tcp_no_delay,true); asio_socket_->set_option(io::basic_socket::tcp_no_delay,true);
if(sndbuf_!=-1)
asio_socket_->set_option(io::basic_socket::send_buffer_size,sndbuf_);
if(rcvbuf_!=-1)
asio_socket_->set_option(io::basic_socket::receive_buffer_size,rcvbuf_);
booster::shared_ptr< ::cppcms::http::context> cnt(new ::cppcms::http::context(api_)); booster::shared_ptr< ::cppcms::http::context> cnt(new ::cppcms::http::context(api_));
api_.reset(); api_.reset();
cnt->run(); cnt->run();
@@ -152,6 +169,7 @@ namespace impl {
booster::aio::acceptor acceptor_; booster::aio::acceptor acceptor_;
bool stopped_; bool stopped_;
bool tcp_; bool tcp_;
int sndbuf_,rcvbuf_;
Factory factory_; Factory factory_;
}; };




+ 2
- 0
private/cgi_api.h View File

@@ -58,6 +58,8 @@ namespace cgi {
#ifndef CPPCMS_WIN32 #ifndef CPPCMS_WIN32
virtual booster::shared_ptr<cppcms::http::context> accept(int fd) = 0; virtual booster::shared_ptr<cppcms::http::context> accept(int fd) = 0;
#endif #endif
virtual void sndbuf(int v) = 0;
virtual void rcvbuf(int v) = 0;
virtual void stop() = 0; virtual void stop() = 0;
virtual ~acceptor(){} virtual ~acceptor(){}
}; };


+ 5
- 0
src/service.cpp View File

@@ -768,6 +768,8 @@ std::auto_ptr<cppcms::impl::cgi::acceptor> service::setup_acceptor(json::value c


std::string api=v.get<std::string>("api"); std::string api=v.get<std::string>("api");
std::string socket=v.get("socket",""); std::string socket=v.get("socket","");
int sndbuf = v.get("sndbuf",-1);
int rcvbuf = v.get("rcvbuf",-1);
std::string ip; std::string ip;
int port=0; int port=0;


@@ -835,6 +837,9 @@ std::auto_ptr<cppcms::impl::cgi::acceptor> service::setup_acceptor(json::value c
if(!a.get()) if(!a.get())
throw cppcms_error("Unknown api: " + api); throw cppcms_error("Unknown api: " + api);


a->sndbuf(sndbuf);
a->rcvbuf(rcvbuf);

return a; return a;
} }




Loading…
Cancel
Save