我正在编写一个基于Facebooks的HTTP视频流服务器。没有任何寻求的计划。使用proxygen::ResponseBuilder,我可以将webm编码的视频块作为HTTP发送,即分组传输编码正在工作。我的问题是,Proxygen甚至在发送响应头之前都要等待proxygen::ResponseBuilder::sendWithEOM()。我希望它能够在每次调用proxygen::ResponseBuilder::send()之后尽快发送数据。
我尝试使用ResponseBuilder和evb->runInEventBaseThread()运行从EventBaseThread执行的lambda中的evb->runInLoop()调用。
using namespace folly;
using namespace proxygen;
std::thread t([&](){
EventBase* evb = EventBaseManager::get()->getExistingEventBase();
// send headers ...
while ( chunks avail. ) {
//...
evb->runInLoop([&](){
ResponseBuilder(downstream_)
.body(std::move(chunk))
.send();
});
//...
}
// sendWithEOM ...
});
t.detach();此代码是从我的onRequest()方法RequestHandler调用的。我试图调用ResponseBuilder::send()而不将它包装到evb->runInLoop()中,但是Proxygenv0.25.0与FollyV0.42.0一起禁止使用断言从另一个线程调用ResponseBuilder::send()。我从这里删除了这个断言:https://github.com/facebook/folly/blob/v0.42.0/folly/io/async/EventBase.cpp#L491。
现在模拟的流正在工作,但是如果有并行请求,它就会崩溃。我想它不应该像这样使用,这就是断言的意义所在。但是,也许有人知道如何正确地使用Proxygen基础设施来实现我的使用呢?
发布于 2015-11-26 19:50:18
同样的问题。我让它和这样的东西一起工作。
folly::EventBase* eventBase = folly::EventBaseManager::get()->getExistingEventBase();
thread t([&, eventBase]() {
while( chunks exist ) {
auto chunk = getChunk();
eventBase->runInEventBaseThread([&, chunk=chunk]() mutable {
ResponseBuilder(downstream_).body(move(chunk)).send();
});
}
});
// sendWithEOM ...
t.detach();发布于 2015-08-11 12:11:56
using namespace folly;
using namespace proxygen;
//Get Event Base in worker thread and pass it to new thread. If you call this inside new thread then you won't get worker thread's event base.
EventBase* evb = EventBaseManager::get()->getExistingEventBase();
std::thread t([&, evb](){
// send headers ...
while ( chunks avail. ) {
//...
evb->runInLoop([&](){
ResponseBuilder(downstream_)
.body(std::move(chunk))
.send();
});
//...
}
// sendWithEOM ...
});
t.detach();因此,不需要在EventBase源代码中评论断言。
https://stackoverflow.com/questions/30847200
复制相似问题