Browse Source

- Fixed issues in timeout management in http-api

- Fixed unit test buffering
- Fixed issue is error handling in http:response
- Cleanup of old code in http-response
master
Artyom Beilis 8 years ago
parent
commit
792f548039
8 changed files with 25 additions and 57 deletions
  1. +2
    -1
      private/cgi_api.h
  2. +5
    -4
      src/cgi_api.cpp
  3. +2
    -1
      src/fastcgi_api.cpp
  4. +10
    -2
      src/http_api.cpp
  5. +1
    -44
      src/http_response.cpp
  6. +2
    -1
      src/scgi_api.cpp
  7. +3
    -1
      tests/dummy_api.h
  8. +0
    -3
      tests/http_timeouts_test.py

+ 2
- 1
private/cgi_api.h View File

@@ -116,7 +116,8 @@ namespace cgi {
virtual void async_write(booster::aio::const_buffer const &buf,bool eof,handler const &h);
virtual bool write(booster::aio::const_buffer const &buf,bool eof,booster::system::error_code &e);

virtual void on_some_output_written() = 0;
virtual void on_async_write_start() = 0;
virtual void on_async_write_progress(bool completed) = 0;
virtual void do_eof() = 0;
virtual booster::aio::const_buffer format_output(booster::aio::const_buffer const &in,bool completed,booster::system::error_code &e) = 0;
virtual bool write_to_socket(booster::aio::const_buffer const &in,booster::system::error_code &e);


+ 5
- 4
src/cgi_api.cpp View File

@@ -563,17 +563,18 @@ struct connection::async_write_handler : public booster::callable<void(booster::
booster::system::error_code e;
conn->socket().set_non_blocking_if_needed(true,e);
size_t n = conn->socket().write_some(output,e);
if(n!=0)
conn->on_some_output_written();
output += n;
if(n!=0) {
conn->on_async_write_progress(output.empty());
}
if(output.empty()) {
h(e);
return;
}
if(e && booster::aio::basic_io_device::would_block(e)) {
conn->socket().on_writeable(self_type(this));
return;
}
h(e);
}
};

@@ -581,10 +582,10 @@ void connection::async_write(booster::aio::const_buffer const &buf,bool eof,hand
{
booster::system::error_code e;
if(nonblocking_write(buf,eof,e) || e) {
if(!e) on_some_output_written();
get_io_service().post(h,e);
return;
}
on_async_write_start();
async_write_handler::self_type p(new async_write_handler(self(),pending_output_,h));
socket().on_writeable(p);
}


+ 2
- 1
src/fastcgi_api.cpp View File

@@ -121,6 +121,8 @@ namespace cgi {
return;
}
}
virtual void on_async_write_start(){}
virtual void on_async_write_progress(bool){}
private:
void on_some_input_recieved(booster::system::error_code const &e,io_handler const &h,void *p,size_t s)
{
@@ -224,7 +226,6 @@ namespace cgi {
}
return packet;
}
virtual void on_some_output_written() {}
virtual booster::aio::stream_socket &socket() { return socket_; }
virtual booster::aio::io_service &get_io_service()
{


+ 10
- 2
src/http_api.cpp View File

@@ -22,6 +22,7 @@
#include <sstream>
#include <algorithm>
#include <cppcms_boost/bind.hpp>
#include <stdio.h>

namespace boost = cppcms_boost;

@@ -383,7 +384,7 @@ namespace cgi {
total += n;
buf += n;
if(e) {
die();
close();
break;
}
}
@@ -424,9 +425,16 @@ namespace cgi {
socket_.async_read_some(io::buffer(&a,1),boost::bind(h));
}

void on_some_output_written()
void on_async_write_start()
{
update_time();
watchdog_->add(self());
}
void on_async_write_progress(bool completed)
{
update_time();
if(completed)
watchdog_->remove(self());
}
virtual booster::aio::stream_socket &socket() { return socket_; }
virtual booster::aio::const_buffer format_output(booster::aio::const_buffer const &in,bool /*completed*/,booster::system::error_code &e)


+ 1
- 44
src/http_response.cpp View File

@@ -146,49 +146,6 @@ namespace details {
};


template<typename Self>
class basic_obuf : public extended_streambuf {
public:
basic_obuf(size_t n = 0)
{
if(n==0)
n=1024;
expected_size_ = n;
}
Self &self()
{
return static_cast<Self &>(*this);
}
int overflow(int c)
{
int r=0;
if(pptr()!=0 && pptr() > pbase()) {
if(self().write(pbase(),pptr()-pbase()) < 0) {
r = EOF;
}
}
if(buf_.empty())
buf_.resize(expected_size_);
char *begin = &buf_[0];
char *end = begin + buf_.size();
setp(begin,end);
if(c!=EOF && r!=EOF)
sputc(c);
return r;
}
int sync()
{
if(overflow(EOF) != 0)
return -1;
if(self().flush() != 0)
return -1;
return 0;

}
private:
size_t expected_size_;
std::vector<char> buf_;
};


#ifndef CPPCMS_NO_GZIP
@@ -346,8 +303,8 @@ namespace details {
}
if(e) {
BOOSTER_WARNING("cppcms") << "Failed to write response:" << e.message();
conn_.reset();
return -1;

}
return 0;
}


+ 2
- 1
src/scgi_api.cpp View File

@@ -115,6 +115,8 @@ namespace cgi {

h(booster::system::error_code());
}
virtual void on_async_write_start() {}
virtual void on_async_write_progress(bool) {}
virtual booster::aio::const_buffer format_output(booster::aio::const_buffer const &in,bool /*comleted*/,booster::system::error_code &/*e*/)
{
return in;
@@ -150,7 +152,6 @@ namespace cgi {
socket_.async_read_some(io::buffer(&a,1),boost::bind(h));
}

virtual void on_some_output_written() {}
virtual booster::aio::stream_socket &socket() { return socket_; }
private:
size_t start_,end_,sep_;


+ 3
- 1
tests/dummy_api.h View File

@@ -42,7 +42,9 @@ public:
}

virtual void do_eof(){}
virtual void on_some_output_written() {}
virtual void on_async_write_start(){}
virtual void on_async_write_progress(bool){}

virtual bool write(booster::aio::const_buffer const &in,bool eof,booster::system::error_code &e)
{
if(*output_ == "$$$ERROR$$$") {


+ 0
- 3
tests/http_timeouts_test.py View File

@@ -47,9 +47,6 @@ def test_unfinished_read(msg,reads,ignore):
print "SO_RCVBUF=%d" % read_size
if read_size < 32768:
read_size = 32768
if read_size > 128*1024:
readsize = 65536
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF,readsize)
s.send(msg + '\r\n\r\n')
for n in xrange(0,reads):
time.sleep(1)


Loading…
Cancel
Save