GithubHelp home page GithubHelp logo

Comments (6)

eidheim avatar eidheim commented on August 20, 2024

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.

fndisme avatar fndisme commented on August 20, 2024

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.

eidheim avatar eidheim commented on August 20, 2024

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.

eidheim avatar eidheim commented on August 20, 2024

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.

fndisme avatar fndisme commented on August 20, 2024

Yes, I agree with you, You are right. use const shared_ptr& is the best one.

from simple-websocket-server.

fndisme avatar fndisme commented on August 20, 2024

O(∩_∩)O, i can safe close this issue.

from simple-websocket-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.