0

I have seen these question on descriptor passing on SO.

i wrote following two programs to work with Unix domain socket

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.

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 i.e. Select() is keeps on waiting . 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 .

How to resolve this error ?

Community
  • 1
  • 1
sonus21
  • 5,178
  • 2
  • 23
  • 48
  • Please note that `recv()` not necessarily receives as much data as it was told to, but few. **Always** check the value returned, if the amount of bytes matters. – alk Mar 08 '15 at 10:43
  • It's ok but at least it should recv few bytes <=MAX given . – sonus21 Mar 08 '15 at 10:44
  • Also the code does not always test whether `recvmsg()` return `0`. – alk Mar 08 '15 at 10:46
  • @alk I have all three functions none of them work . You can see first function do this too . – sonus21 Mar 08 '15 at 10:49

1 Answers1

0

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.

sonus21
  • 5,178
  • 2
  • 23
  • 48