Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 31 Jul 2019 16:36:08 -0400
From:      Dheeraj Kandula <dkandula@gmail.com>
To:        freebsd-net@freebsd.org
Subject:   Socket Sleep and Wakeup clarification
Message-ID:  <CA%2BqNgxS3V2cTQP8iFNfPT53G4VvHTi-VJBo=ZHgqjNmhBxCdNA@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi All,
      I am reading through the socket code in uipc_socket.c file of FreeBSD
12.

The code invokes wakeup with the channel as so->so_timeo in the following
functions:
soisconnected
soisdisconnected
soisdisconnecting and
soshutdown

The callers of soconnect invoke sleep so that the thread that invokes
soconnect wakes up when the TCP 3 way handshake is done. The soconnect in
kernel returns immediately unlike user space connect which sleeps.

I also see tsleep in soclose when the socket's state is SS_ISCONNECTED.

My questions:
       1. Is it possible to close a socket when the application is sleeping
after the application invokes soconnect. Basically I am trying to figure
out how multiple threads can access the same socket for soconnect and
soclose to happen at the same time.
        2. soshutdown also invokes wakeup. This wakeup again corresponds to
the sleep by soconnect. Isn't it? How can we have two threads accessing the
same socket with one thread sleeping on a socket for the soconnect, while
another shuts down the same socket in either the RD or WR or RW direction.

Dheeraj



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2BqNgxS3V2cTQP8iFNfPT53G4VvHTi-VJBo=ZHgqjNmhBxCdNA>