Socket Sleep and Wakeup clarification
Dheeraj Kandula
dkandula at gmail.com
Wed Jul 31 20:36:22 UTC 2019
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
More information about the freebsd-net
mailing list