Vitaliy Makkoveev <[email protected]> wrote:

> The reworked diff for `so_snd' SS_CANTSENDMORE state bit. As proposed by
> deraadt@, SS_CANTSENDMORE definition left as is, but used with newly
> introduced socket's buffer state `sb_state'. `sb_state' ored with
> original `so_state' when socket's data exported to the userland, so the
> ABI left as it was.
> 
> The `so_rcv' related SS_CANTRCVMORE and SS_RCVATMARK bits left to the
> following diff.

That looks better.  I didn't run it yet.

I think there should be a comments which says where each of the SS_* bits
are put and found.

Some go into so_state, some are in sb_state.

In the future, someone carelessly put a SS_* bit into the wrong variable,
and thus not satisfy a read condition on the other side.

        u_int   so_state;               /* internal state flags SS_*, below */

See this becomes somewhat innaccurate, someone might put one of the SS_
bits you moved into here based upon the comment.  Maybe it should say
"some of the SS_* flags */, and use the same comment for the new sb_state.

It should be something subtle and small, to avoid line-wrapping the
#define SS_* lines.

Maybe like this, killing a tab also, one line is more than 80... perhaps
that's just how it has to be?

 * Socket state bits.
 * B - in sb_state, S - in so_state
 */
#define SS_NOFDREF              0x001 /* [S] no file table ref any more */
#define SS_ISCONNECTED          0x002 /* [S] socket connected to a peer */
#define SS_ISCONNECTING         0x004 /* [S] in process of connecting to peer */
#define SS_ISDISCONNECTING      0x008 /* [S] in process of disconnecting */
#define SS_CANTSENDMORE         0x010 /* [B] can't send more data to peer */
#define SS_CANTRCVMORE          0x020 /* [S] can't receive more data from peer 
*/
#define SS_RCVATMARK            0x040 /* [S] at mark on input */
#define SS_ISDISCONNECTED       0x800 /* [S] socket disconnected from peer */

and same for the further bits...


> Index: sys/sys/socketvar.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/socketvar.h,v
> retrieving revision 1.114
> diff -u -p -r1.114 socketvar.h
> --- sys/sys/socketvar.h       12 Dec 2022 08:30:22 -0000      1.114
> +++ sys/sys/socketvar.h       17 Dec 2022 16:43:17 -0000
> @@ -121,6 +121,7 @@ struct socket {
>               short   sb_flags;       /* flags, see below */
>  /* End area that is zeroed on flush. */
>  #define      sb_endzero      sb_flags
> +             short   sb_state;       /* socket state on sockbuf */
>               uint64_t sb_timeo_nsecs;/* timeout for read/write */
>               struct  selinfo sb_sel; /* process selecting read/write */
>       } so_rcv, so_snd;
> @@ -237,7 +238,7 @@ sowriteable(struct socket *so)
>       return ((sbspace(so, &so->so_snd) >= so->so_snd.sb_lowat &&
>           ((so->so_state & SS_ISCONNECTED) ||
>           (so->so_proto->pr_flags & PR_CONNREQUIRED)==0)) ||
> -         (so->so_state & SS_CANTSENDMORE) || so->so_error);
> +         (so->so_snd.sb_state & SS_CANTSENDMORE) || so->so_error);
>  }
>  
>  /* adjust counters in sb reflecting allocation of m */

Reply via email to