Comments (6)
Thank you, the header_stream
could actually be std::unique_ptr
instead of std::shared_ptr
, and move would then be needed. Although, if move is used on message_stream
, one would not be able to reuse the SendStream
object when calling SocketServer::send
, if that is what the user of the library wants.
from simple-websocket-server.
I think it's safe for user to call send with move. for example
we has std::shared_ptr<message_stream> stream;
I call send(stream); // we can use move in send to build SendData
it's safe to call stream->
I call send(std::move(stream)); // we can use move in send to build SendData
it's undefined to call stream-> // but we know it's not ok
SimpleWebsocketServer is very easy to use. I use it in my company application, so I wish it runs more faster and stronger.
Thinks
from simple-websocket-server.
You are right, it should be safe to use std::move
in this case. One concern I have though, is that performing a move is not thread safe, while copying a shared_ptr is thread safe. However, we could do this:
diff --git a/server_ws.hpp b/server_ws.hpp
index d7e4854..4f0c554 100644
--- a/server_ws.hpp
+++ b/server_ws.hpp
@@ -56,7 +56,7 @@ namespace SimpleWeb {
class SendData {
public:
- SendData(std::shared_ptr<SendStream> header_stream, std::shared_ptr<SendStream> message_stream,
+ SendData(const std::shared_ptr<SendStream> &header_stream, const std::shared_ptr<SendStream> &message_stream,
const std::function<void(const boost::system::error_code)> &callback) :
header_stream(header_stream), message_stream(message_stream), callback(callback) {}
std::shared_ptr<SendStream> header_stream;
What do you think?
from simple-websocket-server.
When I think about it, all the functions that have shared_ptr
as parameters should be changed to const &
parameters to avoid unnecessary shared_ptr
copies (http://stackoverflow.com/questions/8385457/should-i-pass-a-shared-ptr-by-reference).
from simple-websocket-server.
Yes, I agree with you, You are right. use const shared_ptr& is the best one.
from simple-websocket-server.
O(∩_∩)O, i can safe close this issue.
from simple-websocket-server.
Related Issues (20)
- [suggest] Send/Broadcast and Text/BinaryMode HOT 1
- Standalone Asio not found - but asio.hpp is present HOT 4
- re again WssClient::start causes on_error HOT 10
- When I use Google Chrome it happend a error. HOT 3
- exception thrown in server start (boost related) HOT 4
- Connection Timeout HOT 2
- Create example on how to stream data to a client HOT 1
- Unable to compile against standalone asio HOT 1
- How to stop the server? HOT 3
- Installed but ws_examples throws an error HOT 1
- Support for the Sec-WebSocket-Protocol field HOT 3
- fatal error C1083: Cannot open include file : 'pthread.h': No such file or directory HOT 1
- Messages split among frames aren't reasembled HOT 25
- Openssl wants void* instead of char* in 0x1000115fL HOT 1
- how to initiate send message from client HOT 3
- Client request error: End of file
- Access violation exeption HOT 3
- gdiplus
- Can't use wss client HOT 5
- Integration with Simple-Web-Server HOT 2
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 simple-websocket-server.