Project

General

Profile

Support #7426

Wt::Response::createContinuation() with streaming

Added by jordan heath almost 3 years ago. Updated almost 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
01/29/2020
Due date:
% Done:

0%

Estimated time:

Description

Hello. I am trying to achieve a never ending streaming server with WResource and ResponseContinuation.

I noticed that `ResponseContinuation::createContinuation()` always returns the same pointer address in during an instance of a `WResource::handleRequest()` where I create a continuation each time.

Is it safe to pass this `ResponseContinuation` pointer to an asynchronous thread?

(The asynchronous thread would put a reference to some data in `ResponseContinuation::setData()` and then call `ResponseContinuation::haveMoreData()` every time that data updated so the `WResource::handleRequest()` could publish the data from it's `ResponseContinuation::data()` to the event-stream)

When the client cuts off the connection, `WResource::handleAbort()` will remove the ResponseContinuation from the asynchronous thread.

#1

Updated by Roel Standaert almost 3 years ago

I believe it is intended that you can use it like that. We've done a streaming resource before, but we're really lacking a streaming resource example.

#2

Updated by Roel Standaert almost 3 years ago

So the data() and setData() is for associating some context information with the continuation, but that is not how you would actually set the data to be sent, since data()/setData() is not synchronized. You will have to devise your own thread safe way of passing data from your asynchronous thread to the handleRequest code.

haveMoreData() should be thread safe, though, and it should be safe to pass the ResponseContinuation to another thread.

#3

Updated by jordan heath almost 3 years ago

Roel Standaert wrote:

So the data() and setData() is for associating some context information with the continuation, but that is not how you would actually set the data to be sent, since data()/setData() is not synchronized. You will have to devise your own thread safe way of passing data from your asynchronous thread to the handleRequest code.

haveMoreData() should be thread safe, though, and it should be safe to pass the ResponseContinuation to another thread.

Awesome, that is what I gathered from reading the open source code, but I just wanted to make sure before I was 100%. Thank you for your response.

Also available in: Atom PDF