本文整理汇总了C++中HTTPServer::finishWriting方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServer::finishWriting方法的具体用法?C++ HTTPServer::finishWriting怎么用?C++ HTTPServer::finishWriting使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPServer
的用法示例。
在下文中一共展示了HTTPServer::finishWriting方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_cb
void write_cb(evutil_socket_t evs, short events, void *ptr) {
#ifdef _DEBUG_MODE_
printf("client %d: write_cb\n", evs);
#endif
/* Last parameter is http server object */
HTTPServer *srv = (HTTPServer *)ptr;
bool err_flag = false;
/* Answer with a string from outBuf */
std::string resp = srv->getResponse(evs);
assert(resp.size() > 0);
while (!resp.empty() && !err_flag) {
/* Send response */
ssize_t sent = send(evs, resp.c_str(), resp.size(), 0);
#ifdef _DEBUG_MODE_
printf("server: %zd/%zd bytes sent to client %d\n", sent, resp.size(), evs);
#endif
if (sent > 0) {
/* Decrease string size */
resp = resp.substr(sent);
} else {
err_flag = true;
}
}
if (err_flag) {
if (errno != EAGAIN) {
/* Remove write event for client */
srv->finishWriting(evs);
} else {
srv->pushToOutBuf(evs, resp);
}
} else {
std::string str = srv->getInBuf(evs);
if (str.empty()) {
/* Remove write event for client */
srv->finishWriting(evs);
} else {
srv->setResponse(evs, str);
}
}
}