网络更改事件注册在 MAC OS X 10.7 (Lion) 中失败
Network Change event registration failed in MAC OS X 10.7 (Lion)
我试图通过以下代码在MAC OS X 10.7(狮子)中注册network_change事件:
#define kNotifySCNetworkChange "com.apple.system.config.network_change"
void init()
{
status = notify_register_check(kNotifySCNetworkChange, &token);
if (status != NOTIFY_STATUS_OK)
{
cout << "Event Registration failed" <<endl;
}
cout << "Event Registration Success" << endl;
}
.....
如果我在示例程序中使用此代码,它已成功注册。如果我在我的应用程序中使用它,notify_register_check() 函数返回状态为 1000000 (NOTIFY_STATUS_FAILED)。此外,返回的 errno 为 0。
注意:我的应用程序在豹和雪豹中工作,没有任何问题(注册成功)
我在谷歌上搜索了这个状态,但找不到相关信息。谁能告诉我在哪些情况下返回此NOTIFY_STATUS_FAILED?
我最近观察到的另一件事是:我们在我的应用程序中使用了fork()系统调用。当我尝试在父流程中注册时,事件注册成功。但事件注册在子进程中失败。为什么它在子进程 ??? 中失败 有什么想法吗!!
errno为0,因为通知API不是系统调用,而是Mach API调用。 有关更多详细信息,请使用mach_error ()。分叉应该不是问题(在大多数情况下,它还克隆了马赫端口)。事实上,以下代码在 Mountain Lion 上运行良好:
#include <notify.h>
#include <iostream>
#define kNotifySCNetworkChange "com.apple.system.config.network_change"
void init()
{
int token;
int status = notify_register_check(kNotifySCNetworkChange, &token);
if (status != NOTIFY_STATUS_OK)
{
std::cout << "Event Registration failed" <<std::endl;
}
std::cout << "Event Registration Success" << std::endl;
}
int main()
{
int rc = fork();
init();
}
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 生成MRPT库时cmake配置失败
- gem 安装 unf_ext -v '0.0.6' 在 Mountain Lion Mac 上失败
- 网络更改事件注册在 MAC OS X 10.7 (Lion) 中失败