-1

I have a client-server application in c which is using unix domain socket.

Here server is reading a integer from client. Client successfully sends a 4 bytes to server.

but at the server end I could see that the read system call is reading 0 bytes from socket.

I am pretty much sure that the data is available for read on server since the select call before read operation is succeeding.

Any idea why this is happenning?

Cracken
  • 306
  • 2
  • 5
  • 17
  • 1
    please create a [mcve] – phuclv Feb 10 '21 at 10:49
  • Maybe add parentheses to the `if(rc=read(fd,buff, sizeof buff) == 0)` ? ;-) – wildplasser Feb 10 '21 at 11:03
  • > tcp client-server application in c which is using unix domain socket This does not make sense. TCP is one protocol and lives in AF_INET address family, so can be on top of IP. Unix Domain socket is another address family. You cannot have TCP on top of Unix Domain socket. – Seppo Takalo Feb 10 '21 at 11:10
  • `I am pretty much sure that the` ... error is in the part of the code that you did not show us – wildplasser Feb 10 '21 at 13:14

1 Answers1

2

Without any code, it's hard to guess what exactly happens, but select() succeeding does not necessarily mean that some data are ready to be read.

select() just makes the promise that if you try one read from this file-descriptor you will not be blocked. The reason might be any of these:

  • the kernel stores in an internal buffer some data to be delivered through the file-descriptor you read (it's what you are expecting here),
  • or the other end of the file-descriptor is closed, then no new data will ever be delivered (the EOF you observe),
  • or the file-descriptor is in an invalid state for a read operation and any read attempt will immediately fail (see errno after read).
prog-fh
  • 13,492
  • 1
  • 15
  • 30