-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrequest_stream.cpp
More file actions
31 lines (25 loc) · 884 Bytes
/
Copy pathrequest_stream.cpp
File metadata and controls
31 lines (25 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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 (!explictLength_ || position_ < length_) {
if (headerBuffer_.HasData()) {
bytes += headerBuffer_.Copy(reinterpret_cast<HeaderBuffer::value_type*>(buffer + offset), count, peek);
offset += bytes;
count -= bytes;
}
if (count > 0 && bytes == 0) {
auto socketBytes = socket_->Receive(Config::BodyReceiveTimeoutPeriod, buffer + offset, count, peek);
if (socketBytes > 0) {
bytes += socketBytes;
}
}
if (!peek) {
position_ += bytes;
if (!explictLength_) {
length_ += bytes;
}
}
}
return bytes;
}