Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Nov 2022 03:42:18 +0000
From:      Muhammad Ali <M.ALI023@hotmail.com>
To:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   SO_SNDLOWAT and write(2) return value
Message-ID:  <DM6PR07MB6074128A7B4A8F8905946731D9049@DM6PR07MB6074.namprd07.prod.outlook.com>

next in thread | raw e-mail | index | archive | help
--_000_DM6PR07MB6074128A7B4A8F8905946731D9049DM6PR07MB6074namp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,
Consider the following scenario:

  1.  Socketpair(2) returns two connected sockets: sp[0] and sp[1]
  2.  Setsockopt(2) the option SO_SNDLOWAT for sp[1] to 10 bytes
  3.  Write(2) to sp[1] with exactly 10 bytes

Is it ever possible for write(2) to return less than 10 bytes in this case?=
 Generally, I would think yes since setting SNDLOWAT only checks if there's=
 enough buffer space for 10 bytes and if there is then we start writing, bu=
t the write may get interrupted and return 6 bytes, for example.

I have read APUE third edition page 624 and the man page for setsockopt(2) =
and it seems the two are conflicting or I am not understanding correctly. T=
o quote APUE: "The minimum amount of data in bytes to transmit in a send ca=
ll", see Page 624, Figure 16.21. As you can see this suggests that less tha=
n 10 bytes will never be returned but the FreeBSD setsockopt(2) man page su=
ggests that less than 10 bytes can be returned.

Which is correct?

BTW, I don't think SAR meant the send(2) call (in the above quote) rather h=
e just wrote send as a generic term to mean write/send/etc...

--_000_DM6PR07MB6074128A7B4A8F8905946731D9049DM6PR07MB6074namp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
Hi,&nbsp;</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
Consider the following scenario:</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
<ol>
<li><span>Socketpair(2) returns two connected sockets: sp[0] and sp[1]</spa=
n></li><li><span>Setsockopt(2) the option SO_SNDLOWAT for sp[1] to 10 bytes=
</span></li><li><span>Write(2) to sp[1] with exactly 10 bytes</span></li></=
ol>
<div><span>Is it ever possible for write(2) to return less than 10 bytes in=
 this case? Generally, I would think yes since setting SNDLOWAT only checks=
 if there's enough buffer space for 10 bytes and if there is then we start =
writing, but the write may get interrupted
 and return 6 bytes, for example.</span></div>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
I have read APUE third edition page 624 and the man page for setsockopt(2) =
and it seems the two are conflicting or I am not understanding correctly. T=
o quote APUE: &quot;The minimum amount of data in bytes to transmit in a se=
nd call&quot;, see Page 624, Figure 16.21.
 As you can see this suggests that less than 10 bytes will never be returne=
d but the FreeBSD&nbsp;<span style=3D"background-color:rgb(255, 255, 255);d=
isplay:inline !important" class=3D"ContentPasted0">setsockopt(2) man page s=
uggests that less than 10 bytes can be returned.</span></div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
Which is correct?</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=3D"eleme=
ntToProof">
BTW, I don't think SAR meant the send(2) call (in the above quote) rather h=
e just wrote
<i>send</i> as a generic term to mean write/send/etc...</div>
</body>
</html>

--_000_DM6PR07MB6074128A7B4A8F8905946731D9049DM6PR07MB6074namp_--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DM6PR07MB6074128A7B4A8F8905946731D9049>