我尝试通过freeDiameter库设置一个具有特定IP地址和端口号的服务器。另一方面,有一个客户端通过freeDiameter库成功发送字符串消息;我在Wireshark上查过了。
所以,问题来了;当我开始从服务器端侦听时,它没有问题,直到客户端发送连接请求;如果你看下面的代码;fd_cnx_serv_accept(监听器("正在侦听名为"strong>"的套接字;听众"绑定到特定的IP地址和端口号。
uint8_t * rcv_buf;
size_t rcv_size;
struct cnxctx * listener_side = NULL;
int ret;
listener_side = fd_cnx_serv_accept(listener);
ret = fd_cnx_start_clear(listener_side, 0);
if(ret != 0){
std::cout<<side<<" is unable to accept connections."<<std::endl;
return -1;
}
ret = fd_cnx_receive(listener_side, NULL, &rcv_buf, &rcv_size);
if(ret == 0){
std::cout<<"Message received."<<std::endl;
listener_side = NULL;
free(rcv_buf);
}
程序运行良好,直到收到客户端请求;当"时;fd_cnx_serv_accept">接受客户端,程序尝试通过"strong>"接收消息;cnx_receive";但是程序停止并显示错误"strong>";分段故障(堆芯倾倒("。然后,我用gdb测试程序,它表明"的309行有问题;hook.c">。这是gdb显示的错误图像。
错误屏幕截图
转录本
multi-thre Thread 0x7fffff72a77 In: fd_hook_call
[New Thread 0x7fffff72a7700 (LWP 1612914)
Thread 2 "server" received signal SIGSEGEV, Segmentation Fault
[Switching to Thread 0x7fffff72a7700 (LWP 1612914)
--Type <RET> for more, q to quit, c to continue without paging --c
0x00007ffff7f2cefc in fd_hook_call (type=HOOD_DATA_RECEIVED, msg=0x0, peer=0x0, other=0x7ffff72a6be0, pmdl=0x7ffff0000ba8 at /root/projects/start_cnx_free/third-party/libfdcore/hooks.c:309
值得一提的是,我正在尝试编写一个c++程序。我该如何解决这个问题?
我自己解决了这个问题。在程序开始时,我忘记使用fd_hooks_init((来初始化必要的库和对象。这是修改后的代码:
/* Initialize the library -- must come first since it initializes the debug facility */
int ret = fd_libproto_init();
if (ret != 0) {
fprintf(stderr, "Unable to initialize libfdproto: %sn", strerror(ret));
return ret;
}
ret = fd_hooks_init();
if(ret != 0){
std::cout<<"Unable to initialize the hooks."<<std::endl;
return ret;
}
/* Initialize the config with default values */
memset(&g_conf, 0, sizeof(struct fd_config));
fd_g_config = &g_conf;
ret = fd_conf_init();
if (ret != 0) {
printf("Unable to initialize the config with default values.");
return ret;
}
/* Add definitions of the base protocol */
ret = fd_dict_base_protocol(fd_g_config->cnf_dict);
if (ret != 0) {
printf("Unable to add definitions of the base protocol.");
return ret;
}