-4

What does return 0(or -1) mean when i write(or read) socket in C on linux?

And Under what circumstances will these things happen?

and how to deal with errno==EINTR?

using write() and read() functions.

Chinna
  • 3,930
  • 4
  • 25
  • 55
cola
  • 691
  • 1
  • 6
  • 15

2 Answers2

3
  1. 0 = means that the connection has been closed (EOF).
  2. < 0 means an error (check errno for details)
  3. > 0 means bytes read/written.

If you encounter an EINTR you can usually ignore it and keep on reading.

Devolus
  • 21,661
  • 13
  • 66
  • 113
  • 1
    If you have a singal handler you might want to do something (depends on your code), but in the general case you can ignore it. I.e. if you have a timer, or want to interrupt your wait, shutdown, etc.. – Devolus Jan 06 '14 at 10:37
1

EINTR indicates that operation is interrupted by a signal. You can ignore it and continue read/write. You can find more information Here.

Community
  • 1
  • 1
Chinna
  • 3,930
  • 4
  • 25
  • 55