Server::send response parameter changed to const. Some cleanup of examples related to this.
This commit is contained in:
parent
c934c9aefe
commit
a69e32290f
3 changed files with 18 additions and 14 deletions
|
|
@ -21,7 +21,8 @@ typedef SimpleWeb::Server<SimpleWeb::HTTPS> HttpsServer;
|
|||
typedef SimpleWeb::Client<SimpleWeb::HTTPS> HttpsClient;
|
||||
|
||||
//Added for the default_resource example
|
||||
void default_resource_send(const HttpsServer &server, shared_ptr<HttpsServer::Response> &response, shared_ptr<ifstream> &ifs);
|
||||
void default_resource_send(const shared_ptr<HttpsServer> &server,
|
||||
const shared_ptr<HttpsServer::Response> &response, const shared_ptr<ifstream> &ifs);
|
||||
|
||||
int main() {
|
||||
//HTTPS-server at port 8080 using 1 thread
|
||||
|
|
@ -181,7 +182,7 @@ int main() {
|
|||
|
||||
header.emplace("Content-Length", to_string(length));
|
||||
response->write(header);
|
||||
default_resource_send(*server, response, ifs);
|
||||
default_resource_send(server, response, ifs);
|
||||
}
|
||||
else
|
||||
throw invalid_argument("could not read file");
|
||||
|
|
@ -191,7 +192,7 @@ int main() {
|
|||
}
|
||||
};
|
||||
|
||||
server->on_error = [](std::shared_ptr<HttpsServer::Request> & /*request*/, const SimpleWeb::error_code & /*ec*/) {
|
||||
server->on_error = [](shared_ptr<HttpsServer::Request> & /*request*/, const SimpleWeb::error_code & /*ec*/) {
|
||||
// handle errors here
|
||||
};
|
||||
|
||||
|
|
@ -216,7 +217,7 @@ int main() {
|
|||
cout << r2->content.rdbuf() << endl;
|
||||
|
||||
// asynchronous request example
|
||||
client->request("POST", "/json", json_string, [](std::shared_ptr<HttpsClient::Response> &response, const SimpleWeb::error_code &ec) {
|
||||
client->request("POST", "/json", json_string, [](shared_ptr<HttpsClient::Response> &response, const SimpleWeb::error_code &ec) {
|
||||
if(!ec)
|
||||
cout << response->content.rdbuf() << endl;
|
||||
});
|
||||
|
|
@ -226,14 +227,15 @@ int main() {
|
|||
server_thread.join();
|
||||
}
|
||||
|
||||
void default_resource_send(const HttpsServer &server, shared_ptr<HttpsServer::Response> &response, shared_ptr<ifstream> &ifs) {
|
||||
void default_resource_send(const shared_ptr<HttpsServer> &server,
|
||||
const shared_ptr<HttpsServer::Response> &response, const shared_ptr<ifstream> &ifs) {
|
||||
//read and send 128 KB at a time
|
||||
static vector<char> buffer(131072); // Safe when server is running on one thread
|
||||
streamsize read_length;
|
||||
if((read_length = ifs->read(&buffer[0], buffer.size()).gcount()) > 0) {
|
||||
response->write(&buffer[0], read_length);
|
||||
if(read_length == static_cast<streamsize>(buffer.size())) {
|
||||
server.send(response, [&server, response, ifs](const SimpleWeb::error_code &ec) mutable {
|
||||
server->send(response, [server, response, ifs](const SimpleWeb::error_code &ec) {
|
||||
if(!ec)
|
||||
default_resource_send(server, response, ifs);
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue