我正在构建一个使用Feather和socketio 的服务器。
我正在尝试使用羽毛通道机制来通知相关用户(连接)相关事件。
用户属于组,因此在连接到服务器后,我将连接添加到适当的通道。
发布后,在 inside 中app.publish,我获得了正确的数据,并看到连接已附加到通道,但无法弄清楚如何在客户端上监听它。
这是一个简化的channels.js:
app.on('connection', async (connection) => {
connection.userGroups.forEach((group) => {
app.channel(`group.groupId`).join(connection);
}
app.channel('1').join(connection); // dummy channel
}
app.publish((data, context) => {
console.log(app.channel('1')); // output shown below
return app.channel('1');
});
Run Code Online (Sandbox Code Playgroud)
我使用 Postman 作为客户端,发送请求patch,并监听名为rooms patched(rooms 是我的服务名称)的事件,如Feathers 文档中所述。没有事件到达。
如果我使用原始的socketio实例并从那里发出,一切似乎都工作正常,并且我在客户端中收到事件
app.io.sockets.in('some room').emit('rooms patched', data);
Run Code Online (Sandbox Code Playgroud)
但据我了解,它凌驾于整个渠道机制之上。
通过检查 app.publish 的输出
Channel {
_events: [Object: null prototype] {
empty: [Function: bound onceWrapper] { listener: [Function …Run Code Online (Sandbox Code Playgroud) 我只是从 C 转向 C++,目前正在通过异常切入我的路径。
我很难弄清楚为什么我会在这个简单的程序中出现内存泄漏:
#include <iostream> /* I/O */
#include <exception> /* exception */
#include <cstdlib> /* stdlib */
using namespace std;
void Bar()
{
throw exception();
}
void Foo()
{
int *ip = new int;
try
{
Bar();
}
catch(exception &e)
{
cerr << "Foo: Exception caught: " << e.what() << endl;
delete ip;
exit(1);
}
delete ip;
}
int main()
{
Foo();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我觉得我在这里遗漏了一些重要的东西,但不能指出它。任何的想法?
Valgrind 的输出:
==21857== Memcheck, a memory error detector
==21857== Copyright (C) …Run Code Online (Sandbox Code Playgroud) 由于我的上一个问题因糟糕的代码风格和拼写错误而被关闭,我对其进行了审查并再次寻求帮助。
我正在尝试解析 PE 格式的 .exe 文件。这是我的代码的一部分
#include "PE_resolve.h"
#define SIZEOF_SECTION_HEADER 0x28
/*load filebuffer into Imagebuffer*/
int Read_2_ImageBuffer(void **p_filebuffer, void **p_Imagebuffer,long filesize);
/*helper function*/
inline void * Get_NT_POS(void **p_filebuffer);
inline void * Get_FileHeader_POS(void **p_filebuffer);
inline void * Get_Opt_FileHeader_POS(void **p_filebuffer);
int main(){
return 0;
}
int Read_2_ImageBuffer(void **p_filebuffer, void **p_Imagebuffer,long filesize){
/*allocate memory for imagebuffer*/
void *Opt_PE_Header = Get_Opt_FileHeader_POS(p_filebuffer); //THE ERROR LINE
DWORD SizeOfImage = *(DWORD*) ((BYTE *)Opt_PE_Header + 0x38);
*p_Imagebuffer = malloc(SizeOfImage);
if(*p_Imagebuffer == NULL){
printf("can't allocate enough heap memory\n");
exit(EXIT_FAILURE); …Run Code Online (Sandbox Code Playgroud) c ×1
c++ ×1
exception ×1
feathersjs ×1
inline ×1
javascript ×1
memory-leaks ×1
postman ×1
socket.io ×1