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: Peng Yu
Subject: Re: How to know /dev/tcp/host/port is closed?
Date: Thu, 1 Apr 2021 16:46:21 -0500

On Thu, Apr 1, 2021 at 10:30 AM Leonid Isaev (ifax)
<leonid.isaev@ifax.com> wrote:
>
> 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}<&-").

So if I sent "Connection: close" a server must respect it? Will there
be a case a server just ignores it and pretend the connection is still
open and accepts new requests?

If the server closes, must it return "Connection: close" in the
response header? Or in a rare case, it may just close on its end, but
doesn't not sent "Connection: close" in the response header, so that
the client has no way to know whether the connection is actually
closed by the server or not?

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

Yes. But I guess it is not possible as this information is not in fd?

-- 
Regards,
Peng



reply via email to

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