我的应用程序的一个功能是每2秒检索一次实时数据(JSON对象)并显示它(仅当app在前台时).由于服务器的限制,我无法使用推送通知服务.你能否告诉我在内部监督办公室进行民意调查的有效方法?
我正在为Linux上的套接字编写C++包装器.我可以将读/写连接到http服务器,我的poll函数可以完美地用于读取,但由于某种原因它不能用于写入.我尝试过使用gdb,fd.revents当fd.events为时,看起来轮询设置为0POLLOUT
民意调查码:
/**
*@brief assigns request.reply based on fd.revents
*/
static void translate_request(mizaru::PollRequest &request, pollfd &fd)
{
assert( (fd.revents & POLLHUP) == 0);
assert( (fd.revents & POLLERR) == 0);
assert( (fd.revents & POLLNVAL) == 0);
switch(fd.revents)
{
case (POLLIN | POLLOUT) :
request.reply = mizaru::POLL_REPLY_RW;
break;
case POLLIN :
request.reply = mizaru::POLL_REPLY_READ;
break;
case POLLOUT :
request.reply = mizaru::POLL_REPLY_WRITE;
default :
request.reply = 0;
}
}
/**
* @fills in fd.events based on request.request
* and fd.fd …Run Code Online (Sandbox Code Playgroud) 我正在用 C 语言编写一个小 Linux 实用程序,它将监视公开基本数据(例如温度传感器)的虚拟设备。我想避免轮询文件(例如通过连续cat /sys/devices/virtual/thermal/thermal_zone0/temp),而是注册一个回调来执行该文件的更改。需求根本不是实时的。
如何避免尽可能快地连续读取该文件?
我有一项服务,每 3 秒从服务器获取一次数据。有时服务器很慢,许多响应在 5 或 6 秒后出现。发生这种情况时,我的服务开始取消每个请求,而不是等待挂起的请求。我怎样才能防止这种情况?
public getCallDiagnostic():Observable<IRespWidgets>{
let body = JSON.stringify({manager:"CallDiagnosticServiceManager",
action:"GetCallDiagnostic",
WEB_USER_TOKEN:this._authenticationService.getUserToken()});
let options = new RequestOptions({headers: new Headers({'Content-Type': 'application/json'})});
return Observable.timer(0,3000)
.switchMap(()=>this._http.post(this._apiUrl,body,options))
.map(res => <IRespWidgets>res.json().data)
.catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud) 我执行了以下服务,
export class UploadPollingService {
constructor(private http: Http, private appConfig: AppConfigService) { }
checkUploadInfo(term: string, ): Observable<Event[]> {
return this.http
.get(this.appConfig.getAPIUrl() + `/checkStatus?processId=${term}`)
.map(this.extractData)
.catch(this.handleErrors);
}
Run Code Online (Sandbox Code Playgroud)
我在组件内部使用它,我想每1秒调用一次此服务并检查状态,基本上是进行轮询。怎么做?
this.uploadPollingService.checkUploadInfo()
Run Code Online (Sandbox Code Playgroud) 我最近开始使用黑暗启动(LD)。我正在探索 LD 如何更新其功能标志。
正如这里提到的,有两种方法。
我只是在想在什么情况下哪种实现会更好。经过一番研究streaming vs polling,发现Streaming有以下优点polling。
我很确定上述所有优势都是有代价的。所以,
我有一些由开发人员编写的python代码.它将UDP消息发送到P2P网络中的节点.我正在编写该代码的并行版本.该代码将多个并行消息发送到P2P网络.不幸的是,代码消耗了太多的CPU.我假设这是因为所有的网络I/O轮询.如果我使用异步I/O(扭曲框架),这是一个好主意吗?
我使用串行编程与GPS设备通信我正在使用二进制协议与它通信.它以这样的方式工作:当写入设备时,我每1秒接收一个数据流.我的问题是,当我轮询这些数据并将其打印出来时,我会接收ASCII字符而不是HEX数据.我需要查看十六进制数据,以便我可以解析它.这是我写的代码
int Open_UBX()
{
unsigned char PollPOSLLH[11] = {0xB5,0x62,0x06,0x01,0x03,0x00,0x01,0x02,0x01,0x0E,0x47};
write(fd,&PollPOSLLH,11);
}
int main(){
Open_UBX();
while (c!='q')
{
if (read(fd,&data,1)>0)
{
write(STDOUT_FILENO,&data,1); // if new data is available on the serial port, print it out
}
if (read(STDIN_FILENO,&c,1)>0)
{
write(STDOUT_FILENO,&c,1); // if new data is available on the console, send it to the serial port
}
}
close(fd);
return(0);
}
Run Code Online (Sandbox Code Playgroud)
当然端口是打开的,设置已配置,但我的问题是数据不显示十六进制所以我无法解析它我只得到我不明白的字符
信号SIGTERM和SIGINT的信号处理程序在接收到任何一个信号时会导致轮询错误.我不确定为什么会这样做,我想我不知道我错过了一些sigaction的行为.
while(!signalHandler.gotExitSignal()) {
switch (poll(&ufds[0], NUM_FDS, POLL_TIMEOUT)) {
case -1: {
throw std::runtime_error("poll error (-1)"); /* ABORT */
}
.
.
Run Code Online (Sandbox Code Playgroud)
我的signalHandler是一个包含sigaction处理的类.
struct sigaction killAction, termAction;
memset(&killAction, 0, sizeof(struct sigaction));
killAction.sa_handler = SignalHandler::ExitHandler;
sigemptyset(&killAction.sa_mask);
killAction.sa_flags = 0;
if(sigaction(SIGTERM, &killAction, NULL) < 0)
throw SignalException("sigaction failed for killAction");
memset(&termAction, 0, sizeof(struct sigaction));
termAction.sa_handler = SignalHandler::ExitHandler;
sigemptyset(&termAction.sa_mask);
termAction.sa_flags = 0;
if(sigaction(SIGTERM, &termAction, NULL) < 0)
throw SignalException("sigaction failed for termAction");
Run Code Online (Sandbox Code Playgroud)
所以我给出的片段循环的预期行为应该是:
我使用python,ndb和数据存储区.我的模型("事件")有一个属性:
created = ndb.DateTimeProperty(auto_now_add = True).
事件会不时被保存,有时会在一秒钟内保存.
我想"轮询新事件",而不是两次获得相同的事件,并且如果没有任何新事件则获得空结果.但是,再次轮询可能会给我带来新的事件.
我见过游标,但我不知道是否可以以某种方式使用它来轮询新事件,如果第一个查询到达终点?当我到达数据的(当前)末尾时,"next_cursor"为None.
保持最后一个"创建"的DateTime属性,并使用它来获得下一个批处理工作,但这只是使用秒的分辨率,所以排序可能搞砸了..
我必须在Event中为此创建自己的事务性递增计数器吗?
server.c-> 总是接收客户端数据(使用 poll() 确认是否发生错误\xef\xbc\x89
client.c-> 总是向服务器发送数据
我执行server.c,client.c然后我尝试终止client.c进程。
但 POLLERR 标志永远不会被设置。
\n\n手册页只说
\n\n\n\n\nPOLLERR 错误条件(仅输出)
\n
Poll() 什么时候返回 POLLERR?
\n\n我错过了什么?
\n\n谢谢。
\n\n服务器.c
\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <sys/poll.h>\n#include <sys/socket.h>\n#include <sys/time.h>\n#include <netinet/in.h>\n#include <errno.h>\n\nint main()\n{\n int rc = 0;\n char str[100];\n char test[5];\n int listen_fd, comm_fd;\n struct sockaddr_in servaddr;\n struct pollfd fds[200];\n listen_fd = socket(AF_INET, SOCK_STREAM, 0);\n\n servaddr.sin_family = AF_INET;\n servaddr.sin_addr.s_addr = htons(INADDR_ANY);\n servaddr.sin_port = htons(22000);\n\n bind(listen_fd, …Run Code Online (Sandbox Code Playgroud) 我正在使用gcc版本5.4.0的Ubuntu 16.04。我在C中有一个相当简单的套接字示例,当我使用优化(-O)进行编译时,该示例失败了(它没有进行优化)。我将原始代码修剪为:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
int main() {
struct addrinfo *ai, hints;
memset(&hints, 0, sizeof hints);
getaddrinfo(NULL, "7471", &hints, &ai);
int listen_fd = socket(ai->ai_family, SOCK_STREAM, 0);
bind(listen_fd, ai->ai_addr, ai->ai_addrlen);
freeaddrinfo(ai);
listen(listen_fd, 128);
struct pollfd fds;
fds.fd = listen_fd;
fds.events = POLLIN;
poll(&fds, -1, -1);
}
Run Code Online (Sandbox Code Playgroud)
编译器在调用poll()时遇到问题。警告消息是
in function ‘poll’,
inlined from ‘main’ at simplecode.c:25:5:
/usr/include/x86_64-linux-gnu/bits/poll2.h:43:9: warning: call to ‘__poll_chk_warn’ declared with attribute warning: poll called …Run Code Online (Sandbox Code Playgroud) 例如,我想每 10 秒更新一次列表。我使用了运算符“timer”,但 api 没有在 Chrome -> Network 选项卡上第二次显示。
我的流程:调度加载操作 - 我的 api - 方法 GET - 仅在“网络”选项卡中调用一次。但是,如果我创建了一个带有函数调度该操作的按钮,则每次我单击时,我的 api 都会在“网络”选项卡/Chrome 中被调用多次
我的环境:ngrx 7.4、rxjs 6.5.2、Angular 7 所以我不知道服务器自动阻止重复调用 api 或 Angular 和 ngrx 是否正在使用缓存
// 我的效果
load$: Observable<Action> = this.action$.pipe(
ofType<Load>(NotificationActionTypes.load),
switchMap(() => timer(0, 10000)),
switchMap((action) => {
return this.notiService.getNotifications().pipe(map((res: any) => {
return new LoadSuccess({
result: res,
});
}));
})
);```
[![enter image description here][1]][1]
See my image, 20/125 request, 125 continue increasing, 20/130, 20/145, but number 20 didn't increase
[1]: …Run Code Online (Sandbox Code Playgroud) polling ×13
angular ×3
c ×3
c++ ×3
sockets ×3
linux ×2
python ×2
rxjs ×2
asynchronous ×1
hex ×1
ios ×1
launchdarkly ×1
networking ×1
ngrx ×1
signals ×1
streaming ×1
tcp ×1
timer ×1
twisted ×1
typescript ×1