Skip to content

Commit

Permalink
Merge pull request #12 from nobodyisme/feature/flush
Browse files Browse the repository at this point in the history
Implement request flush method
  • Loading branch information
toshic committed Jun 27, 2016
2 parents 04f4e08 + 05121e9 commit 86837b4
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/details/requestimpl.h
Expand Up @@ -158,6 +158,8 @@ class RequestImpl : private boost::noncopyable {

unsigned short status() const;

void flush();

private:
friend class Parser;
void sendHeadersInternal();
Expand Down
2 changes: 2 additions & 0 deletions include/fastcgi2/request.h
Expand Up @@ -119,6 +119,8 @@ class Request : private boost::noncopyable {

unsigned short status() const;

void flush();

private:
std::auto_ptr<RequestImpl> impl_;
};
Expand Down
1 change: 1 addition & 0 deletions include/fastcgi2/request_io_stream.h
Expand Up @@ -26,6 +26,7 @@ class RequestIOStream {
virtual int read(char *buf, int size) = 0;
virtual int write(const char *buf, int size) = 0;
virtual void write(std::streambuf *buf) = 0;
virtual void flush() = 0;
};

} // namespace fastcgi
Expand Down
5 changes: 5 additions & 0 deletions library/request.cpp
Expand Up @@ -314,4 +314,9 @@ Request::status() const {
return impl_->status();
}

void
Request::flush() {
impl_->flush();
}

} // namespace fastcgi
7 changes: 7 additions & 0 deletions library/requestimpl.cpp
Expand Up @@ -851,4 +851,11 @@ RequestImpl::status() const {
return status_;
}

void
RequestImpl::flush() {
if (stream_) {
stream_->flush();
}
}

} // namespace fastcgi
19 changes: 19 additions & 0 deletions main/fcgi_request.cpp
Expand Up @@ -161,4 +161,23 @@ FastcgiRequest::setHandlerDesc(const HandlerSet::HandlerDescription *handler) {
handler_ = handler;
}

void
FastcgiRequest::flush() {
int num = FCGX_FFlush(fcgiRequest_.out);
if (-1 == num) {
std::stringstream str;
int error = FCGX_GetError(fcgiRequest_.out);
if (error > 0) {
char buffer[256];
str << "Cannot flush data to fastcgi socket: " <<
strerror_r(error, buffer, sizeof(buffer)) << ". ";
}
else {
str << "FastCGI error. ";
}
generateRequestInfo(request_.get(), str);
throw std::runtime_error(str.str());
}
}

} // namespace fastcgi
1 change: 1 addition & 0 deletions main/fcgi_request.h
Expand Up @@ -35,6 +35,7 @@ class FastcgiRequest : public RequestIOStream {
void write(std::streambuf *buf);

void setHandlerDesc(const HandlerSet::HandlerDescription *handler);
void flush();
private:
boost::shared_ptr<Request> request_;
Logger *logger_;
Expand Down
2 changes: 2 additions & 0 deletions request-cache/file_cache.cpp
Expand Up @@ -75,6 +75,8 @@ class RequestCacheStream : public RequestIOStream {
void write(std::streambuf *buf) {
(void)buf;
}
void flush() {
}
};

FileRequestCache::FileRequestCache(ComponentContext *context) :
Expand Down
2 changes: 2 additions & 0 deletions tests/test_request.cpp
Expand Up @@ -81,6 +81,8 @@ class TestIOStream : public RequestIOStream {
virtual void write(std::streambuf *buf) {
(*out_) << buf;
}
virtual void flush() {
}
private:
std::istream *in_;
std::ostream *out_;
Expand Down

0 comments on commit 86837b4

Please sign in to comment.