1

我想要多播 AF_UNIX 数据报套接字(类似的低级)。

Linux内核中是否已经为此实现了一些东西?我希望它将发布/订阅逻辑保留在内核中,而不是任何用户空间守护进程中。一个系统调用——我们发布——N 个唤醒线程——他们通知了。

/* in publisher: */
send(fd, "first\n", 6, TO_ALL_THREADS_PLEASE);
send(fd, "second\n", 7, TO_ALL_THREADS_PLEASE);

/* in the first subscriber thread: */
sleep(1);
recv(fd, buf, 100, 0); /* receive "first" */
recv(fd, buf, 100, 0); /* receive "second" */

/* meanwhile in the second subscriber thread: */
recv(fd, buf, 100, 0); /* receive "first" */
sleep(1);
recv(fd, buf, 100, 0); /* receive "second" */
4

0 回答 0