eidheim / Simple-WebSocket-Server

A very simple, fast, multithreaded, platform independent WebSocket (WS) and WebSocket Secure (WSS) server and client library implemented using C++11, Boost.Asio and OpenSSL. Created to be an easy way to make WebSocket endpoints in C++.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sharing the same io_service

mikealeonetti opened this issue · comments

Big fan of the Simle-Web-Server, excited to try this library also. Is there a way to have it share the same io_service as another thread?

Thank you, but not quite sure what you mean with "same io_service as another thread". Could you please elaborate?

Yes, my apologies. In my program, an io_service is already running on a thread. This thread also handles TCP clients that can message each other. I'd like to add this websocket library onto that thread to also message the same clients without having to do threadsafe stuff. Am I misguided?

That is a good point, either the io_service should be accessable for reuse (you can currently subclass the server to do this now though I think), or you should be able to set the io_service to use when starting the server. I'll think some more on this next week when I have time.

Okay. That makes sense. I'll look into subclassing it if you don't have time.

Currently, I'm leaning towards making io_service a public ´shared_ptr` member. If set, no attempts will be done to start io_service in this library, and if not set, the behaviour would be like it is now depending on the number of threads set.

I'm thinking about making some additional changes that will break backward compatibility:

  • shared_ptr arguments should be const shared_ptr... &
  • number of threads should be set in config and not in constructor