Comments (5)
Could you please to change also the the server::connection::write_response method.
from websocketpp.
The last commit should fix the problem from a correctness perspective. I am leaving this issue open for the moment because this solution involves an awful lot of copying that I want to try and avoid. I think the protocol processors should be able to return a reference to an appropriate shared buffer rather than returning a value that gets copied into a shared buffer locally.
from websocketpp.
I have done a "homework" and had realized that it's enough to use members strings as a storage for requests and responses. Also I changed the raw method to pass a string reference as input parameter, rather to return the string. It looks not very nice but saves one string copy operation on old STL implementations without the "Rvalue references" feature of C++11 and does not require creating string on the heap using std::shared_ptr inside of the raw method. Here is a patch
File: client.hpp
------------------------------------------------- cut here -------------------------------------------------
-#include "../shared_const_buffer.hpp"
------------------------------------------------- cut here -------------------------------------------------
std::string m_handshake_key;
http::parser::request m_request;
-
------------------------------------------------- cut here -------------------------------------------------
std::string m_request_data; http::parser::response m_response;
// TODO: generating this raw request involves way too much copying in cases
// without string/vector move semantics.
- shared_const_buffer buffer(m_request.raw());
- //std::string raw = m_request.raw();
- //m_endpoint.alog().at(log::alevel::DEBUG_HANDSHAKE) << raw << log::endl;
-
m_request.raw(m_request_data);
-
boost::asio::async_write(
m_connection.get_socket(), -
//boost::asio::buffer(raw),
-
buffer,
-
boost::asio::buffer(m_request_data), boost::bind( &type::handle_write_request, m_connection.shared_from_this(),
------------------------------------------------- cut here -------------------------------------------------
throw http::exception("Could not parse server response.",http::status_code::BAD_REQUEST);
} -
m_endpoint.alog().at(log::alevel::DEBUG_HANDSHAKE) << m_response.raw() << log::endl;
-
std::string response;
-
m_response.raw(response);
-
m_endpoint.alog().at(log::alevel::DEBUG_HANDSHAKE) << response << log::endl; // error checking if (m_response.get_status_code() != http::status_code::SWITCHING_PROTOCOLS) {
------------------------------------------------- cut here -------------------------------------------------
to be continued...
from websocketpp.
File: server.hpp
------------------------------------------------- cut here -------------------------------------------------
-#include "../shared_const_buffer.hpp"
------------------------------------------------- cut here -------------------------------------------------
http::parser::request m_request;
http::parser::response m_response;
-
std::string m_response_data; blank_rng m_rng;
------------------------------------------------- cut here -------------------------------------------------
m_response.replace_header("Server","WebSocket++/0.2.0"); -
std::string raw = m_response.raw();
-
m_response.raw(m_response_data);
// Hack for legacy HyBi
if (m_version == 0) {
-
raw += boost::dynamic_pointer_castprocessor::hybi_legacy<connection_type >(m_connection.m_processor)->get_key3();
-
m_response_data += boost::dynamic_pointer_cast<processor::hybi_legacy<connection_type> >(m_connection.m_processor)->get_key3();
}
-
m_endpoint.alog().at(log::alevel::DEBUG_HANDSHAKE) << raw << log::endl;
-
m_endpoint.alog().at(log::alevel::DEBUG_HANDSHAKE) << m_response_data << log::endl;
boost::asio::async_write(
m_connection.get_socket(),
-
boost::asio::buffer(raw),
-
------------------------------------------------- cut here -------------------------------------------------
boost::asio::buffer(m_response_data), boost::bind( &type::handle_write_response, m_connection.shared_from_this(),
from websocketpp.
Here the last part. A few mistypings are also fixed. Additionally I used to use constant methods where is possible. So I added the const word in a couple of places.
File: Parser.hpp
------------------------------------------------- cut here -------------------------------------------------
-
throw "No Implimented";
-
------------------------------------------------- cut here -------------------------------------------------
throw "Not Implemented";
- std::string raw_headers() {
- std::string raw_headers() const {
std::stringstream raw; -
header_list::iterator it;
-
for (it = m_headers.begin(); it != m_headers.end(); it++) {
-
header_list::const_iterator it;
-
------------------------------------------------- cut here -------------------------------------------------
for (it = m_headers.cbegin(); it != m_headers.cend(); it++) { raw << it->first << ": " << it->second << "\r\n"; }
// TODO: validation. Make sure all required fields have been set? - std::string raw() {
- void raw(std::string &data) const {
std::stringstream raw;
raw << m_method << " " << m_uri << " " << version() << "\r\n";
raw << raw_headers() << "\r\n";
-
return raw.str();
-
}
data = raw.str();
------------------------------------------------- cut here -------------------------------------------------
// TODO: validation. Make sure all required fields have been set? - std::string raw() {
- void raw(std::string &data) const {
std::stringstream raw;
raw << version() << " " << m_status_code << " " << m_status_msg << "\r\n";
@@ -237,7 +237,7 @@ public:
raw << m_body;
-
return raw.str();
-
}
data = raw.str();
------------------------------------------------- cut here -------------------------------------------------
from websocketpp.
Related Issues (20)
- Process multiple websocket clients in one thread
- memory leak
- how to build in centos7.9? HOT 1
- handle_read_http_response error
- websocketpp how to upload a PDF file to server
- Can't compile the echo_client example
- Help getting basic TLS example to work
- Build error
- Build issues on C++20 (around constructor syntax of templated structs)
- How to add some custom key to the http headers HOT 1
- 严重性 代码 说明 项目 文件 行 禁止显示状态 错误(活动) E0283 不允许使用限定名
- How to use websocketpp to process HTTPS requests?
- May I ask how websocketpp uses domain sockets for communication? HOT 1
- asio/connection.hpp 文件的第 318 行遇到了一个类型不匹配的问题,编译出错 HOT 1
- 服务端150路并发,2m码率的音视频数据发送,造成ping消息延时发送8秒
- Cannot reinit asio after .dll shutdown
- Connect one wss succefully but another failed
- Runs fine on Linux, crash on Windows due to boost invalid memory access issue HOT 2
- How can i turn off utf8_validator for incoming ANSI text message
- request server by ip and set host in header
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websocketpp.