简体   繁体   English

Unix域套接字:发送文件描述符和select()

[英]Unix domain socket : sending file descriptor and select()

I have seen these question on descriptor passing on SO. 我已经看到了关于描述符传递的这些问题。

i wrote following two programs to work with Unix domain socket 我写了以下两个程序来使用Unix域套接字

which are intended to work as 旨在作为

Main program accepts all client connections and send those descriptors to running service program (Descriptor receiver) .Descriptor receiver recvs descriptor and set them to fd_set and use select to check whether a descriptor is readable or not if it's ready to read then read the descriptor into buffer and send string length to client. 主程序接受所有客户端连接,并将这些描述符发送到正在运行的服务程序(描述符接收器)。描述符接收器接收描述符,并将它们设置为fd_set and use select检查是否可以读取描述符,然后准备将其读入描述符。缓冲并发送字符串长度给客户端。

Note : I am testing using telnet on ubuntu 14.10

Major problem with this program is that FD_ISSET() return false even though descriptor is ready to read ie Select() is keeps on waiting . 该程序的主要问题是,即使描述符已准备好读取, FD_ISSET() return false ,即Select()仍在等待。 Some of the time it works , in this case it recvs few message and hang . 在某些情况下,它可以正常工作,在这种情况下,它几乎没有消息并挂起。

I have tried all three flavor of send and recv descriptor functions but none of them work perfectly . 我已经尝试了所有三种send和recv描述符函数,但是它们都不完美

How to resolve this error ? 如何解决此错误?

I spend many hours to find bug in the above code . 我花了很多时间来查找上述代码中的错误。 It was in descriptor receiver on line no 153 , Where i forgot to calculate maximum value of recvd descriptor. 它在第153行的描述符接收器中 ,在这里我忘记了计算recvd描述符的最大值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM