Comments (5)
Is process with updates performed on another thread or async task? If not it will run synchronously, producing and queuing all the update messages before ever returning control back to the library to write.
connection-write_frame definitely shouldn’t be called here.
not directly related to this issue, but I’d recommend just setting tcp no delay once, either in the open handler or socket unit handler, it applies for the duration of the connection.
if you use a thread or async task to run your processing function I’d also recommend capturing the connection hdl rather than the full connection pointer and using endpoint::send (this helps ensure proper behavior when multiple threads are in use)
from websocketpp.
It is difficult for me to multithread the task without significant cross thread access violations. Is there an async send?
from websocketpp.
Send is async, which basically is the problem. There isn't a sync send, because Asio and Websocket++ generally are designed to be used in an async environment.
To use this pattern (single thread cooperative multitasking) without threads you would do something like...
message handler
- store the details of the request somewhere
- start an async task (using the interrupt handler or timer handler) that will read request details and completion state and perform one chunk of work, send a status update, and then queue the next chunk of work
- yield (allow the message handler to return)
this returns control to the Asio event loop and allows it to process incoming and outgoing messages asyncronously and periodically call your async task (again, via the interrupt or timer handlers) to progress that task. When the task is complete the final invocation simply declines to re-queue a timer/interrupt and the task ends.
from websocketpp.
(followup)
The telemetry_server
bundled example shows a pattern similar to this that uses timers. Your message handler would queue request details and yield. The timer handler would process some work, send a status update and yield. If there were no outstanding requests the timer would yield immediately. The pattern with the interrupt handler is similar, except instead of setting up a persistent timer you request an immediate interrupt via connection::interrupt()
, which will call that connection back shortly at its interrupt handler. You can set the interrupt handler for a specific connection in the message handler. Do keep in mind though that unless your handler (be it the message handler, timer handler, or interrupt handler) yields control back to the single threaded event loop no WebSocket data will be processed (new data in or out) so it is best to keep the work processing tasks short and yielding somewhat frequently.
Finally: keep in mind that you don't need to multi-thread the processing task itself. It is fine for the task to run in a single thread as long as the Asio event loop processing all the network traffic is in a different thread.
from websocketpp.
Okay. Actually, converting captures for lambdas from reference to non reference took care of most of it. It wasn't that much after that. Problem solved for now.
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.