- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我已经使用 AsyncProgressWorker 线程制作了一个 Node 插件来处理我的套接字消息。这是我的代码:
class ProgressWorker : public AsyncProgressWorker {
public:
ProgressWorker(
Callback *callback
, Callback *progress)
: AsyncProgressWorker(callback), progress(progress) {}
~ProgressWorker() {}
void Execute (const AsyncProgressWorker::ExecutionProgress& progress) {
char response[4096];
int result;
int connected = 1;
int timeout = 0;
int pending = 0;
while(connected) {
result = sctp_recvmsg(sock, (void *)&response, (size_t)sizeof(response), NULL, 0, 0, 0);
if (result > 0 && result < 4095) {
if (debug) {
printf("Server replied (size %d)\n", result);
}
pending = 0;
progress.Send((const char *)response, size_t(result));
result = 0;
}
else {
// Don't mind my timeout mechanism. :))
if ((result == -1 && errno != EWOULDBLOCK) || pending) {
if (timeout == 0) {
printf("Can't receive from other end. Waiting for 3 seconds. Error code: %d\n", errno);
pending = 1;
}
if (timeout >= 3000) {
connected = 0;
close(sock);
}
else {
timeout += 5;
usleep(5000);
}
}
else {
usleep(5000);
}
}
}
}
void HandleProgressCallback(const char *data, size_t count) {
HandleScope scope;
v8::Local<v8::Value> argv[] = {
CopyBuffer(const_cast<char*>(data), count).ToLocalChecked()
};
progress->Call(1, argv); // This is the callback to nodejs
}
private:
Callback *progress;
};
直到今晚我才对此进行压力测试,然后我注意到有些消息不会返回到 Node 。它将打印我的“服务器回复”调试日志,但不会记录我放在进度回调中的调试日志。我在这里错过了什么吗?提前致谢。
最佳答案
AsyncProgressWorker
基于uv_async_t
,它允许任何线程唤醒主线程。但是,如 documentation 中所述:
libuv will coalesce calls to uv_async_send(), that is, not every call to it will yield an execution of the callback. For example: if uv_async_send() is called 5 times in a row before the callback is called, the callback will only be called once. If uv_async_send() is called again after the callback was called, it will be called again.
^^ 这就是当您的应用程序处于压力下时,您有时可能无法收到某些事件的原因。这条线上方是问题的答案。以下是我处理您的问题的“超越”可能的解决方案:
碰巧我正在为 AsyncProgressWorker
添加一个新的替代品 promise 传递每个事件,就像AsyncProgressWorker
一样确实如此,但使用队列。此功能最近已合并到 NAN 中。如果您想测试它,请尝试位于 https://github.com/nodejs/nan 的 git 存储库。 , 然后替换你的 AsyncProgressWorker
与 AsyncProgressQueueWorker<char>
重新运行您的测试,所有事件都将被传送。
添加此新功能的拉取请求在这里:https://github.com/nodejs/nan/pull/692 - 2017 年 10 月 6 日合并。
此新功能已在 NAN 2.8.0 版本中发布
您可以通过更改 package.json
来使用这个新的类模板使用 nan 2.8.0 或更高版本:
"dependencies": {
"nan": "^2.8.0"
},
关于c++ - 一些进展。发送调用没有到达 nodejs 土地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46031901/
我正在创建一个必须使用system(const char*)函数来完成一些“繁重工作”的应用程序,并且我需要能够为用户提供粗略的进度百分比。例如,如果操作系统正在为您移动文件,它会为您提供一个进度条,
你好,我正在使用 post_controller 钩子(Hook)来验证用户是否登录但是当验证失败时,我将用户重定向到登录 Controller ....现在的问题是当它重定向到默认 Controll
你好,我正在使用 post_controller 钩子(Hook)来验证用户是否登录但是当验证失败时,我将用户重定向到登录 Controller ....现在的问题是当它重定向到默认 Controll
是否可以显示页面加载需要多长时间。 @ 当我向服务器发送 post 请求时,我使用 post 通过 $ajax 发送它,并且 beforeSend 显示一条消息说我们正在加载您的页面。但是有时它会卡在
我有一个案例,我可能需要通过 WebSockets 向客户端发送 500KB - 1MB 的数据。因此,我想知道是否可以跟踪客户端接收到多少数据的进度。这样,当通过较慢的连接进行连接时,应用程序不会出
在我的应用程序中,我使用 LZMA SDK 压缩了大约 400Mb 的数据。当然,这需要一些时间。即使在大量谷歌搜索之后,我也无法找到任何有关如何获取压缩过程实时进度信息的信息。这是通过一些回调函数还
是否可以在 Jupyter Notebook 中看到 GridSearchCV 的进度?我正在 python 中运行这个脚本: param_grid = {'learning_rate': [0.05
我有一个工作文件上传表单,它使用 XMLHttpRequest 2 将文件上传到 Transloadit(一种文件处理服务)。进度事件在 Firefox 和 Chrome 中正确触发,适用于桌面和 A
这里很沮丧。我不是数据库管理员,但可以绕过。我正在针对 Progress OpenEdge 数据库编写一些 ODBC 查询,我们只能查看该数据库。很长一段时间以来都没有出现任何问题,直到最近他们更改了
如何获取 AFHTTPRequest 的进度?我试过在网上搜索。 我正在使用: AFHTTPRequestOperationManager *manager = [AFHTTPRequestO
有人知道这是否可行,或者有使用 Node.js 连接到 SonicMQ 代理的示例吗?我无法在网上找到任何信息或示例。 最佳答案 我建议使用 Sonic Connect 公开休息服务(需要 ESB)或
我是一名优秀的程序员,十分优秀!