Project

General

Profile

Actions

Support #7426

open

Wt::Response::createContinuation() with streaming

Added by jordan heath about 4 years ago. Updated about 4 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.

Actions #1

Updated by Roel Standaert about 4 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.

Actions #2

Updated by Roel Standaert about 4 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.

Actions #3

Updated by jordan heath about 4 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.

Actions

Also available in: Atom PDF