* TIOCOUTQ implementation for sockets vs. tty
@ 2021-03-10 18:16 Henneberg - Systemdesign
2021-03-10 18:29 ` Willy Tarreau
0 siblings, 1 reply; 3+ messages in thread
From: Henneberg - Systemdesign @ 2021-03-10 18:16 UTC (permalink / raw)
To: netdev
Hi,
I have a question regarding the implementation of ioctl TIOCOUTQ for
various sockets compared to the tty implementation.
For several sockets, e. g. AF_BLUETOOTH it is done like this
af_bluetooth.c:
case TIOCOUTQ:
if (sk->sk_state == BT_LISTEN)
return -EINVAL;
amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
if (amount < 0)
amount = 0;
err = put_user(amount, (int __user *)arg);
break;
so the ioctl returns the available space in the send queue if I
understand the code correctly (this is also what I observed from tests).
The tty does this:
n_tty.c:
case TIOCOUTQ:
return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
so it returns the used space in the send queue. This is also what I
would expect from the manpage description.
Is this mismatch intentional?
Regards
-Jochen
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: TIOCOUTQ implementation for sockets vs. tty
2021-03-10 18:16 TIOCOUTQ implementation for sockets vs. tty Henneberg - Systemdesign
@ 2021-03-10 18:29 ` Willy Tarreau
2021-03-10 20:15 ` Henneberg - Systemdesign
0 siblings, 1 reply; 3+ messages in thread
From: Willy Tarreau @ 2021-03-10 18:29 UTC (permalink / raw)
To: Henneberg - Systemdesign; +Cc: netdev
Hi,
On Wed, Mar 10, 2021 at 07:16:34PM +0100, Henneberg - Systemdesign wrote:
> Hi,
>
> I have a question regarding the implementation of ioctl TIOCOUTQ for
> various sockets compared to the tty implementation.
>
> For several sockets, e. g. AF_BLUETOOTH it is done like this
>
> af_bluetooth.c:
> case TIOCOUTQ:
> if (sk->sk_state == BT_LISTEN)
> return -EINVAL;
>
> amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
> if (amount < 0)
> amount = 0;
> err = put_user(amount, (int __user *)arg);
> break;
>
> so the ioctl returns the available space in the send queue if I
> understand the code correctly (this is also what I observed from tests).
>
> The tty does this:
>
> n_tty.c:
> case TIOCOUTQ:
> return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
>
> so it returns the used space in the send queue. This is also what I
> would expect from the manpage description.
>
> Is this mismatch intentional?
At least both man pages (tty_ioctl and tcp(7)) mention that TIOCOUTQ
should return the number of byte in queue.
What I suspect for sockets is that sk_sndbuf grows with allocations
and that sk_wmem_alloc_get() in fact returns the number of unused
allocations thus the difference would be the amount queued. But I
could be wrong and I would tend to read the code the same way as you
did.
Willy
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: TIOCOUTQ implementation for sockets vs. tty
2021-03-10 18:29 ` Willy Tarreau
@ 2021-03-10 20:15 ` Henneberg - Systemdesign
0 siblings, 0 replies; 3+ messages in thread
From: Henneberg - Systemdesign @ 2021-03-10 20:15 UTC (permalink / raw)
To: Willy Tarreau; +Cc: netdev
Willy Tarreau <w@1wt.eu> writes:
> Hi,
>
> On Wed, Mar 10, 2021 at 07:16:34PM +0100, Henneberg - Systemdesign wrote:
>> Hi,
>>
>> I have a question regarding the implementation of ioctl TIOCOUTQ for
>> various sockets compared to the tty implementation.
>>
>> For several sockets, e. g. AF_BLUETOOTH it is done like this
>>
>> af_bluetooth.c:
>> case TIOCOUTQ:
>> if (sk->sk_state == BT_LISTEN)
>> return -EINVAL;
>>
>> amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
>> if (amount < 0)
>> amount = 0;
>> err = put_user(amount, (int __user *)arg);
>> break;
>>
>> so the ioctl returns the available space in the send queue if I
>> understand the code correctly (this is also what I observed from tests).
>>
>> The tty does this:
>>
>> n_tty.c:
>> case TIOCOUTQ:
>> return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
>>
>> so it returns the used space in the send queue. This is also what I
>> would expect from the manpage description.
>>
>> Is this mismatch intentional?
>
> At least both man pages (tty_ioctl and tcp(7)) mention that TIOCOUTQ
> should return the number of byte in queue.
>
> What I suspect for sockets is that sk_sndbuf grows with allocations
> and that sk_wmem_alloc_get() in fact returns the number of unused
> allocations thus the difference would be the amount queued. But I
> could be wrong and I would tend to read the code the same way as you
> did.
I am quite sure that my assumption is right. When I call the ioctl right
before and after writing data to an AF_BLUETOOTH socket the returned
value decreases where it should increase.
-Jochen
>
> Willy
--
Henneberg - Systemdesign
Jochen Henneberg
Loehnfeld 26
21423 Winsen (Luhe)
--
Fon: +49 172 160 14 69
www: www.henneberg-systemdesign.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-10 20:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-10 18:16 TIOCOUTQ implementation for sockets vs. tty Henneberg - Systemdesign
2021-03-10 18:29 ` Willy Tarreau
2021-03-10 20:15 ` Henneberg - Systemdesign
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).