[haiku-gsoc] Re: Queries regarding the current code for tcp

  • From: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
  • To: haiku-gsoc@xxxxxxxxxxxxx
  • Date: Mon, 5 Jun 2017 23:19:07 +0200

Am 04/06/2017 um 20:38 schrieb Ayush Agrawal:

Sorry I didn't complete the mail..

*Q3. *tcp.cpp, checking the argument "level" in two different ways:
line 525 @ tcp_control: (level & LEVEL_MASK) == IPPROTO_TCP
                   line 541 @ tcp_getsockopt: (level == IPPROTO_TCP)
Why the difference?

The ioctl() level also embeds information like "get option" in the level, see [1] -- getsockopt() doesn't, and therefore doesn't use the mask.

*Q4. *tcp.cpp, line 291 @ get_endpoint_manager. First it makes a call to /endpoint_manager_for/. If that returns NULL, it makes a call to /endpoint_manager_for_locked/. Why does it do that when /endpoint_manager_for/ itself internally calls /endpoint_manager_for_locked/?

The only difference I could spot out was that when /get_endpoint_manger/ itself calls /endpoint_manager_for_locked/ it beforehand acquires a WriteLocker on sEndpointManagersLock while /endpoint_manager_for /beforehand acquires a ReadLocker.

Exactly, and that's the difference: it first tries to get an existing endpoint manager (using the read lock). If that fails, it grabs the write lock, but checks if maybe some other thread did create the endpoint manager in the mean time -- if that's the case, it'll just return that new manager.
Otherwise, it will create the manager, and, since it holds the write lock, and is therefore allowed to write to the structure, store it in there, for the next caller to retrieve.

Bye,
   Axel.

[1] http://xref.plausible.coop/source/xref/haiku/headers/private/net/net_protocol.h#20

Other related posts: