c++ - Why SO_RCVTIMEO is inherited from listening socket to accepted socket? -


i couldn't find documentation on except python documentation

18.1.4.2. timeouts , accept method

if getdefaulttimeout() not none, sockets returned accept() method inherit timeout. otherwise, behaviour depends on settings of listening socket:

if listening socket in blocking mode or in timeout mode, socket returned accept() in blocking mode;

if listening socket in non-blocking mode, whether socket returned accept() in blocking or non-blocking mode operating system-dependent. if want ensure cross-platform behaviour, recommended manually override setting.

i have read [question]: are socket options inherited across accept() listening socket? , think in end verdict still implementation defined. guess testing on platform easier reading sources each kernel.

here says timeout option inherited. on manpage of accept(2), there's no mention of this. found quite shocking when debugged c++ code on 1 of box ( embedded linux box). expected accepted socket not inherit option.

where can find definitive answer question?

if c question, rather python question, wouldn't draw conclusions regarding so_rcvtimeo being inherited accept(2) based on python docs. think may have misinterpreted python docs anyway, since they...

  1. never explicitly mention so_rcvtimeo option
  2. never timeout value inherited listening socket, rather global timeout value set setdefaulttimeout()

looking @ source code socketmodule.c, python doesn't use so_rcvtimeo socket option. instead, stores timeout value in own internal representation of socket object, , uses in calls select(2) , poll(2).

i suspect rationale python's bizarre implementation designed run on many platforms, of don't support so_rcvtimeo option. reference so_rcvtimeo on line 4773...

#ifdef so_rcvtimeo pymodule_addintconstant(m, "so_rcvtimeo", so_rcvtimeo); #endif 

...where it's surrounded pre-processor directives, in case so_rcvtimeo isn't defined on platform on it's compiled.

as why python docs say...

...sockets returned accept() method inherit timeout...

...that's because python's internal implementation of accept() explicitly sets internal timeout value of new socket default timeout value on line 732...

s->sock_timeout = defaulttimeout; 

as original question...

where can find definitive answer question?

...i guess you'll have hunt through kernel source code until find it, it's simpler make no assumptions inherited, , explicitly override options changed defaults on parent socket fd on new socket fd returned accept(2).


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -