Unix domain socket

来源:互联网 发布:dem编辑软件 编辑:程序博客网 时间:2024/04/26 22:53

    为了实现dm365中 write 子线程能够向 live555的doGetNextFrame( ) 传递 NALU 。

    dm365中的 encode 程序是基于多线程的,而 live555 是基于 select 查询机制的,为了实现 encode 后的数据传入 live555,并经由 live555 封装 RTP 包发送。实现数据的交互,这成为了自己需要思考的问题。

    在《嵌入式实时流媒体服务器的实现》这篇论文中看到了 Unix_domain_socket 这个东西,作者用它实现了 2 个进程之间的数据传递,情况和我目前遇到的有些相似。

****************************************************************华丽的分割线*************************************************************

    http://en.wikipedia.org/wiki/Unix_domain_socket

    A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing within the same host operating system. While similar in functionality tonamed pipes, Unix domain sockets may be created asbyte streams or asdatagram sequences, while pipes are byte streams only. Processes using Unix domain sockets do not need to share a common ancestry. TheAPI for Unix domain sockets is similar to that of anInternet socket, but does not use an underlying network protocol for communication. The Unix domain socket facility is a standard component ofPOSIXoperating systems.

Unix domain sockets use the file system as address name space. They are referenced by processes as inodes in the file system. This allows two processes to open the same socket in order to communicate. However, communication occurs entirely within the operating system kernel.

In addition to sending data, processes may send file descriptors across a Unix domain socket connection using the sendmsg() andrecvmsg() system calls.

****************************************************************华丽的分割线*************************************************************

    (现在的时间是2012-06-03周日下午15:16)

    对于Unix Domain Socket,我的理解是,它利用套接字实现了Unix下的进程之间的通信,而这种通信方式类似于管道通信,但是,这种通信方式是可以实现双向全双工通信,并且不涉及网络协议栈之类的底层的东西,所以我认为它不会有拆包这种烦人的东西。

    目前,我的方法是,在 live555 的 doGetNextFrame( ) 中创建 Unix Domain Socket 套接字,并将该 socket 加入到 live555 的 select 查询机制中(等待该 socket 可读时,判断是否是 dm365 回送的 NALU 数据),然后向 dm365 的 write 线程发送 NALU请求消息。在 dm365 开发板中的 write 线程中,采用了 select + NonBlocking 机制,侦听是否有从 live555 发来的 NALU 请求信息,如果有,则在 write 线程中等待一个完整的 NALU ,然后发送给 live555。

原创粉丝点击