0

我将 C 接口用于 XPC 服务;顺便说一句,除了以下问题,我的 XPC 服务运行得非常好。

前几天我试图通过 XPC 发送一个“大”数组;大约 200,000 个条目。通常,我的应用程序处理几千个条目的数据并且没有问题。对于其他用途,这种大小的数组可能并不特殊。

这是我用于生成数组的 C++ 服务器代码:

  xpc_connection_t remote = xpc_dictionary_get_remote_connection(event);
  xpc_object_t reply = xpc_dictionary_create_reply(event);

  xpc_object_t times;
  times = xpc_array_create(NULL, 0);

  for(unsigned int s = 0; s < data.size(); s++)
  {
    xpc_object_t index = xpc_uint64_create(data[s]);
    xpc_array_append_value(times, index);
  }

  xpc_dictionary_set_value(reply, "times", times);
  xpc_connection_send_message(remote, reply);

  xpc_release(times);
  xpc_release(reply);

这是客户端代码:

  xpc_object_t times = xpc_dictionary_get_value(reply, "times");
  size_t count = xpc_array_get_count(times);
  for(int c = 0; c < count; c++)
  {
    long my_time = xpc_array_get_uint64(times, c);
    local_times.push_back(my_time);
  }

如果我尝试处理大型数组,则会出现段错误(SIGSEGV)

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libxpc.dylib                    0x00007fff90e5cc02 xpc_array_get_count + 0
4

1 回答 1

0

当您说“非常大的阵列”时,您是在说 launchd 可能会视为资源消耗并杀死的东西吗?

XPC 仅适用于短时间快速事务运行,而不是冗长的基于服务的运行。

如果您要拨打使launchd等待的电话,那么我建议您尝试https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html

当服务终止时..除了 SIG_ABORTS 等之外的任何特定事件......被解雇了吗?

您是否收到“xpc 服务无效”(这通常意味着 launchD 将其杀死,或者您是否收到“xpc 服务/过早退出”,这通常是处理程序代码错误。

于 2016-01-13T07:24:06.330 回答