If you are using a connection-oriented Socket, the Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the Socket connection with the Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.
The ReceiveHandler will just spin if the remote closes the connection as Socket.Receive() just returns immediately with 0 bytes instead of blocking.
https://github.com/jellyfin/jellyfin-plugin-tvheadend/blob/5c29b9907d74e6b47a940fc61ea26a7888cd52db/TVHeadEnd/HTSP/HTSConnectionAsync.cs#L387
https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.receive?view=net-6.0#system-net-sockets-socket-receive(system-byte())
If you are using a connection-oriented Socket, the Receive method will read as much data as is available, up to the size of the buffer. If the remote host shuts down the Socket connection with the Shutdown method, and all available data has been received, the Receive method will complete immediately and return zero bytes.