Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c5e6d7
commit 988c9db
Showing
17 changed files
with
240 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
#include "header_buffer.h" | ||
#include <algorithm> | ||
|
||
#include "header_buffer.h" | ||
#include "socket.h" | ||
#include "stream.h" | ||
|
||
std::size_t rs::httpserver::HeaderBuffer::Receive(rs::httpserver::socket_ptr socket) { | ||
auto bytes = socket->Receive(reinterpret_cast<rs::httpserver::Stream::byte*>(&data_[0]) + dataLength_, data_.size() - dataLength_); | ||
if (bytes > 0) { | ||
dataLength_ += bytes; | ||
} | ||
|
||
return bytes; | ||
} | ||
|
||
std::size_t rs::httpserver::HeaderBuffer::Receive(rs::httpserver::socket_ptr socket, int timeout) { | ||
auto bytes = socket->Receive(timeout, reinterpret_cast<rs::httpserver::Stream::byte*>(&data_[0]) + dataLength_, data_.size() - dataLength_); | ||
if (bytes > 0) { | ||
dataLength_ += bytes; | ||
} | ||
|
||
return bytes; | ||
} | ||
|
||
int rs::httpserver::HeaderBuffer::Copy(value_type* buffer, int count) { | ||
auto length = std::min(dataLength_ - position_, count); | ||
auto start = cbegin() + position_; | ||
std::copy(start, start + length, buffer); | ||
position_ += length; | ||
return length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "request_stream.h" | ||
#include "config.h" | ||
|
||
int rs::httpserver::RequestStream::Read(Stream::byte* buffer, int offset, int count, bool peek) { | ||
auto bytes = 0; | ||
|
||
if (headerBuffer_.HasData()) { | ||
bytes += headerBuffer_.Copy(reinterpret_cast<HeaderBuffer::value_type*>(buffer + offset), count); | ||
offset += bytes; | ||
count -= bytes; | ||
} | ||
|
||
if (count > 0 && (bytes == 0 || socket_->Available())) { | ||
auto socketBytes = socket_->Receive(Config::BodyReceiveTimeoutPeriod, buffer + offset, count, peek); | ||
if (socketBytes > 0) { | ||
bytes += socketBytes; | ||
} | ||
} | ||
|
||
position_ += bytes; | ||
length_ += bytes; | ||
|
||
return bytes; | ||
} |
Oops, something went wrong.