Commit 957fdaadc380d8fc18f47f2495a7853b99ca0401

Authored by Georg Hopp
1 parent 3289d758

added some thoughts about socket states while reading and writing. This is not h…

…andled very well right now in my code which result in connections to be closed to early.
Showing 1 changed file with 53 additions and 0 deletions
  1 +each socket can have 4 states while reading or writing...well as far as i can
  2 +say....assuming is is nonblocking.
  3 +These can be checked via errno and return value.
  4 +
  5 + recv send errno
  6 +OK >0 >0 NOT SET
  7 +CLOSED REMOTELY 0 -1 (write)ECONNRESET
  8 +E_AGAIN -1 -1 EAGAIN|EWOULDBLOCK
  9 +ERROR OTHER -1 -1 AMYTHING ELSE
  10 +
  11 +This means we need a slightly different handling for reading and writing.
  12 +It might be neccessary to distinguish other streams from sockets albeit I
  13 +would like to prevent this...
  14 +This might be tested with small test programs. Well, the only special thing
  15 +is ECONNRESET in write mode...because this is something that would not
  16 +happen to files open for writing.
  17 +We need to be more selective when to close the socket. In fact there are
  18 +some errors, as EINTR which does not mean our socket is closed at all.
  19 +
  20 +Error which does not cause us to close the socket while writing:
  21 +
  22 +EAGAIN - go to poll
  23 +EINTR - try again
  24 +ENOBUFS - try again (maybe only a few times....)
  25 +ENOMEM - try again (maybe only a few times....)
  26 +
  27 +All other errors will cause us to close the socket while writing to it.
  28 +
  29 +Error which does not cause us to close the socket while reading:
  30 +
  31 +EAGAIN - go to poll
  32 +EINTR - try again
  33 +ENOMEM - try again (maybe only a few times....)
  34 +
  35 +All other errors will cause us to close the socket while reading from it.
  36 +
  37 +From a server view...
  38 +- read or write a socket as long as OK
  39 +- close if either indicated by read or write...maybe read or write themself
  40 + could do the close.
  41 +- poll if all socket get EAGAIN on read and write.
  42 +
  43 +So...read and write must be able to notify about 3 states at least.
  44 +
  45 +1. I am fine...continue operation on me
  46 +2. I could not continue right now...please poll me
  47 +3. Don't do any further operation on me...please close me.
  48 +
  49 +This could be simply done with return values...
  50 +
  51 +for 1. Return value >= 0
  52 +for 2. Return -1 STREAM_DO_POLL
  53 +for 3. Return -2 STREAM_DO_CLOSE
... ...
Please register or login to post a comment