help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to know /dev/tcp/host/port is closed?


From: Leonid Isaev (ifax)
Subject: Re: How to know /dev/tcp/host/port is closed?
Date: Thu, 1 Apr 2021 15:30:21 +0000

On Thu, Apr 01, 2021 at 10:02:42AM -0500, Peng Yu wrote:
> I see an explanation on how to close a TCP connection above. There two
> steps. So in this slide, there are two packets sent (the first one
> with ACK set, the second one with FIN set)?
> 
> - 2 Send ACK
> - 3 Send FIN
> 
> The slide is different from what is actually happening in this bash
> example as FIN+ACK are sent in one packet?

It is allowed to set multiple TCP flags in a single packet...

> So once bash sees FIN (whether it is a combination of both FIN and ACK
> or just a FIN), bash will return an EOF when reading from the socket
> (after reading all the stream before the end)?

Bash doesn't see FIN, it only works with fd's. All TCP flags are handled and
interpreted by the kernel (Linux in my case).

So, coming back to your example, you should transmit headers with "Connection:
close" right before closing fd pointing to /dev/tcp/... (with "exec {fd}<&-").

Are you asking how to detect a half-closed TCP connection in your program?

HTH,

-- 
Leonid Isaev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]