From MAILER-DAEMON Mon Sep 08 12:42:10 2008
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1KcjoX-00060Y-PU
	for mharc-bug-commoncpp@gnu.org; Mon, 08 Sep 2008 12:42:09 -0400
Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
	id 1KciA8-00048S-2Y
	for bug-commoncpp@gnu.org; Mon, 08 Sep 2008 10:56:20 -0400
Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
	id 1KciA5-00046v-2f
	for bug-commoncpp@gnu.org; Mon, 08 Sep 2008 10:56:18 -0400
Received: from [199.232.76.173] (port=39243 helo=monty-python.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1KciA4-00046U-DW
	for bug-commoncpp@gnu.org; Mon, 08 Sep 2008 10:56:16 -0400
Received: from mail.platespin.com ([204.50.186.134]:57536)
	by monty-python.gnu.org with esmtp (Exim 4.60)
	(envelope-from <Howell.Chen@platespin.com>) id 1KciA4-0000Ih-47
	for bug-commoncpp@gnu.org; Mon, 08 Sep 2008 10:56:16 -0400
Received: from it-bex1.platespin.com ([10.99.100.31]) by mail.platespin.com
	with Microsoft SMTPSVC(6.0.3790.3959); 
	Mon, 8 Sep 2008 10:32:29 -0400
Received: from IT-BEX2.platespin.com ([10.99.100.32]) by it-bex1.platespin.com
	with Microsoft SMTPSVC(6.0.3790.3959); 
	Mon, 8 Sep 2008 10:33:58 -0400
X-MimeOLE: Produced By Microsoft Exchange V6.5
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C911BF.E19C9672"
Date: Mon, 8 Sep 2008 10:33:19 -0400
Message-ID: <00C7AEC2785D004FAC718953A40402220DD52ECE@IT-BEX2.platespin.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: bug report: gcount() returns 0 when socket is read into contents
	successfully and then enters half-closed state
Thread-Index: AckRv9ZzEZ+eUBfKSPGReR2aGzoVEw==
From: "Howell Chen" <Howell.Chen@platespin.com>
To: <bug-commoncpp@gnu.org>
X-OriginalArrivalTime: 08 Sep 2008 14:33:58.0849 (UTC)
	FILETIME=[EE235B10:01C911BF]
X-TM-AS-Product-Ver: SMEX-7.0.0.1557-5.5.1027-16144.005
X-TM-AS-Result: No--6.560800-0.000000-31
X-detected-kernel: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+
X-Greylist: delayed 1320 seconds by postgrey-1.27 at monty-python;
	Mon, 08 Sep 2008 10:55:44 EDT
X-Mailman-Approved-At: Mon, 08 Sep 2008 12:42:08 -0400
Subject: bug report: gcount() returns 0 when socket is read into contents
	successfully and then enters half-closed state
X-BeenThere: bug-commoncpp@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Bug reports for Common C++ <bug-commoncpp.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/bug-commoncpp>,
	<mailto:bug-commoncpp-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/pipermail/bug-commoncpp>
List-Post: <mailto:bug-commoncpp@gnu.org>
List-Help: <mailto:bug-commoncpp-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/bug-commoncpp>,
	<mailto:bug-commoncpp-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Sep 2008 14:56:21 -0000

This is a multi-part message in MIME format.



------_=_NextPart_001_01C911BF.E19C9672
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi Commoncpp developer,

=20

Playing around commoncpp 1.6.3 code, I met some behavior under following
scenario, which I believe as buggy:

=20

1.       Peer A and peer B enter a tcp session

2.       A sends some contents to B; if no error is reported (tcp
subsystem agree to take over whatever needs to be done to deliver), A
closes and exit

3.       meanwhile, in a loop, peer B receive byte streams through the
TCPStream::read, after which follows a call of TCPStream::gcount() to
know how many bytes the previous read() has read in - a exit condition
for the loop is gcound() returns 0, indicating tcp stream has nothing to
read and should be closed to release this tcp resource.

=20

Here comes the bug: the last TCPStrteam::read() actually reads some
bytes before its underlying (socket) read returns 0. The 0 return value
would immediately call clear(ios::failbit | rdstate() ) (line 2911,
src/csocket.cpp, commoncpp-1.6.3), which in turn resets gcount internal
data structure _M_gcount to 0, causing the subsequent
TCPStream::gcount() returns the incorrect 0.

=20

For a socket read to return 0 is quite normal and legitimate when the
peer send FIN and enters the so-called half-close state.
TCPStream::read() actually reads correctly all the byte stream that
might be queued, but the TCPStream::gcount returning 0 subsequently is
definitely conflicting what is expected from a read/gcound with an
istream object.

=20

Hope this description serves its purpose well.

=20

Regards,

=20

Howell Chen




------_=_NextPart_001_01C911BF.E19C9672
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:Arial;
	color:windowtext;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 @list l0
	{mso-list-id:440034375;
	mso-list-type:hybrid;
	mso-list-template-ids:-182658792 302044228 67698713 67698715 67698703 =
67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
	{mso-level-tab-stop:.75in;
	mso-level-number-position:left;
	margin-left:.75in;
	text-indent:-.25in;}
ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Hi Commoncpp developer,<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Playing around commoncpp 1.6.3 code, I met some =
behavior
under following scenario, which I believe as =
buggy:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal =
style=3D'margin-left:.75in;text-indent:-.25in;mso-list:l0 level1 =
lfo1'><![if !supportLists]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><span
style=3D'mso-list:Ignore'>1.<font size=3D1 face=3D"Times New =
Roman"><span
style=3D'font:7.0pt "Times New =
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</span></font></span></span></font><![endif]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>Peer A and
peer B enter a tcp session<o:p></o:p></span></font></p>

<p class=3DMsoNormal =
style=3D'margin-left:.75in;text-indent:-.25in;mso-list:l0 level1 =
lfo1'><![if !supportLists]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><span
style=3D'mso-list:Ignore'>2.<font size=3D1 face=3D"Times New =
Roman"><span
style=3D'font:7.0pt "Times New =
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</span></font></span></span></font><![endif]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>A sends some
contents to B; if no error is reported (tcp subsystem agree to take over
whatever needs to be done to deliver), A closes and =
exit<o:p></o:p></span></font></p>

<p class=3DMsoNormal =
style=3D'margin-left:.75in;text-indent:-.25in;mso-list:l0 level1 =
lfo1'><![if !supportLists]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><span
style=3D'mso-list:Ignore'>3.<font size=3D1 face=3D"Times New =
Roman"><span
style=3D'font:7.0pt "Times New =
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</span></font></span></span></font><![endif]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>meanwhile, in
a loop, peer B receive byte streams through the TCPStream::read, after =
which
follows a call of TCPStream::gcount() to know how many bytes the =
previous
read() has read in &#8211; a exit condition for the loop is gcound() =
returns 0,
indicating tcp stream has nothing to read and should be closed to =
release this tcp
resource.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Here comes the bug: the last TCPStrteam::read() =
actually
reads some bytes before its underlying (socket) read returns 0. The 0 =
return
value would immediately call clear(ios::failbit | rdstate() ) (line =
2911,
src/csocket.cpp, commoncpp-1.6.3), which in turn resets gcount internal =
data
structure _<i><span style=3D'font-style:italic'>M</span></i>_gcount to =
0, causing
the subsequent TCPStream::gcount() returns the incorrect =
0.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>For a socket read to return 0 is quite normal and =
legitimate
when the peer send FIN and enters the so-called half-close state.
TCPStream::read() actually reads correctly all the byte stream that =
might be
queued, but the TCPStream::gcount returning 0 subsequently is definitely
conflicting what is expected from a read/gcound with an istream =
object.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Hope this description serves its purpose =
well.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Regards,<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Howell Chen<o:p></o:p></span></font></p>

</div>

</body>

</html>



------_=_NextPart_001_01C911BF.E19C9672--



From MAILER-DAEMON Mon Sep 08 13:11:29 2008
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1KckGv-0005A5-7M
	for mharc-bug-commoncpp@gnu.org; Mon, 08 Sep 2008 13:11:29 -0400
Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
	id 1KckGu-00059c-Bq
	for bug-commoncpp@gnu.org; Mon, 08 Sep 2008 13:11:28 -0400
Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
	id 1KckGt-00058d-Gj
	for bug-commoncpp@gnu.org; Mon, 08 Sep 2008 13:11:27 -0400
Received: from [199.232.76.173] (port=47371 helo=monty-python.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1KckGs-00058P-SM
	for bug-commoncpp@gnu.org; Mon, 08 Sep 2008 13:11:27 -0400
Received: from mail.platespin.com ([204.50.186.134]:8344)
	by monty-python.gnu.org with esmtp (Exim 4.60)
	(envelope-from <Howell.Chen@platespin.com>) id 1KckGs-0001hg-Hf
	for bug-commoncpp@gnu.org; Mon, 08 Sep 2008 13:11:26 -0400
Received: from it-bex1.platespin.com ([10.99.100.31]) by mail.platespin.com
	with Microsoft SMTPSVC(6.0.3790.3959); 
	Mon, 8 Sep 2008 13:10:12 -0400
Received: from IT-BEX2.platespin.com ([10.99.100.32]) by it-bex1.platespin.com
	with Microsoft SMTPSVC(6.0.3790.3959); 
	Mon, 8 Sep 2008 13:11:20 -0400
X-MimeOLE: Produced By Microsoft Exchange V6.5
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C911D5.DD980FAA"
Date: Mon, 8 Sep 2008 13:10:41 -0400
Message-ID: <00C7AEC2785D004FAC718953A40402220DD531B0@IT-BEX2.platespin.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: correction: bug report: gcount() returns 0 when socket is read
	into contents successfully and then enters half-closed state
Thread-Index: AckRv9ZzEZ+eUBfKSPGReR2aGzoVEwAFaksg
From: "Howell Chen" <Howell.Chen@platespin.com>
To: <bug-commoncpp@gnu.org>
X-OriginalArrivalTime: 08 Sep 2008 17:11:20.0802 (UTC)
	FILETIME=[E9FB0C20:01C911D5]
X-TM-AS-Product-Ver: SMEX-7.0.0.1557-5.5.1027-16144.005
X-TM-AS-Result: No--10.276000-0.000000-31
X-detected-kernel: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+
Subject: correction: bug report: gcount() returns 0 when socket is read into
	contents successfully and then enters half-closed state
X-BeenThere: bug-commoncpp@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Bug reports for Common C++ <bug-commoncpp.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/bug-commoncpp>,
	<mailto:bug-commoncpp-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/pipermail/bug-commoncpp>
List-Post: <mailto:bug-commoncpp@gnu.org>
List-Help: <mailto:bug-commoncpp-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/bug-commoncpp>,
	<mailto:bug-commoncpp-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Sep 2008 17:11:28 -0000

This is a multi-part message in MIME format.



------_=_NextPart_001_01C911D5.DD980FAA
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

The problematic line for the specific case is actually 2910:

            Error(errInput, "Could not read from socket", socket_error);

=20

Regards,

=20

Howell

=20

________________________________

From: Howell Chen=20
Sent: Monday, September 08, 2008 10:33 AM
To: 'bug-commoncpp@gnu.org'
Subject: bug report: gcount() returns 0 when socket is read into
contents successfully and then enters half-closed state

=20

Hi Commoncpp developer,

=20

Playing around commoncpp 1.6.3 code, I met some behavior under following
scenario, which I believe as buggy:

=20

1.       Peer A and peer B enter a tcp session

2.       A sends some contents to B; if no error is reported (tcp
subsystem agree to take over whatever needs to be done to deliver), A
closes and exit

3.       meanwhile, in a loop, peer B receive byte streams through the
TCPStream::read, after which follows a call of TCPStream::gcount() to
know how many bytes the previous read() has read in - a exit condition
for the loop is gcound() returns 0, indicating tcp stream has nothing to
read and should be closed to release this tcp resource.

=20

Here comes the bug: the last TCPStrteam::read() actually reads some
bytes before its underlying (socket) read returns 0. The 0 return value
would immediately call clear(ios::failbit | rdstate() ) (line 2911,
src/csocket.cpp, commoncpp-1.6.3), which in turn resets gcount internal
data structure _M_gcount to 0, causing the subsequent
TCPStream::gcount() returns the incorrect 0.

=20

For a socket read to return 0 is quite normal and legitimate when the
peer send FIN and enters the so-called half-close state.
TCPStream::read() actually reads correctly all the byte stream that
might be queued, but the TCPStream::gcount returning 0 subsequently is
definitely conflicting what is expected from a read/gcound with an
istream object.

=20

Hope this description serves its purpose well.

=20

Regards,

=20

Howell Chen




------_=_NextPart_001_01C911D5.DD980FAA
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal;
	font-family:Arial;
	color:windowtext;}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:Arial;
	color:navy;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 @list l0
	{mso-list-id:440034375;
	mso-list-type:hybrid;
	mso-list-template-ids:-182658792 302044228 67698713 67698715 67698703 =
67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
	{mso-level-tab-stop:.75in;
	mso-level-number-position:left;
	margin-left:.75in;
	text-indent:-.25in;}
@list l0:level2
	{mso-level-tab-stop:1.0in;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level3
	{mso-level-tab-stop:1.5in;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level4
	{mso-level-tab-stop:2.0in;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level5
	{mso-level-tab-stop:2.5in;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level6
	{mso-level-tab-stop:3.0in;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level7
	{mso-level-tab-stop:3.5in;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level8
	{mso-level-tab-stop:4.0in;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l0:level9
	{mso-level-tab-stop:4.5in;
	mso-level-number-position:left;
	text-indent:-.25in;}
ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>The problematic line for the =
specific case
is actually 2910:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Error(errInput,
&#8220;Could not read from socket&#8221;, =
socket_error);<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Regards,<o:p></o:p></span></font></p=
>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Howell<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<div>

<div class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font =
size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'>

<hr size=3D2 width=3D"100%" align=3Dcenter tabindex=3D-1>

</span></font></div>

<p class=3DMsoNormal><b><font size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font =
size=3D2
face=3DTahoma><span style=3D'font-size:10.0pt;font-family:Tahoma'> =
Howell Chen <br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Monday, September =
08, 2008
10:33 AM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> =
'bug-commoncpp@gnu.org'<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> bug report: =
gcount()
returns 0 when socket is read into contents successfully and then enters
half-closed state</span></font><o:p></o:p></p>

</div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Hi Commoncpp developer,<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Playing around commoncpp 1.6.3 code, I met some =
behavior
under following scenario, which I believe as =
buggy:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal =
style=3D'margin-left:.75in;text-indent:-.25in;mso-list:l0 level1 =
lfo2'><![if !supportLists]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><span
style=3D'mso-list:Ignore'>1.<font size=3D1 face=3D"Times New =
Roman"><span
style=3D'font:7.0pt "Times New =
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</span></font></span></span></font><![endif]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>Peer A and
peer B enter a tcp session<o:p></o:p></span></font></p>

<p class=3DMsoNormal =
style=3D'margin-left:.75in;text-indent:-.25in;mso-list:l0 level1 =
lfo2'><![if !supportLists]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><span
style=3D'mso-list:Ignore'>2.<font size=3D1 face=3D"Times New =
Roman"><span
style=3D'font:7.0pt "Times New =
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</span></font></span></span></font><![endif]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>A sends some
contents to B; if no error is reported (tcp subsystem agree to take over
whatever needs to be done to deliver), A closes and =
exit<o:p></o:p></span></font></p>

<p class=3DMsoNormal =
style=3D'margin-left:.75in;text-indent:-.25in;mso-list:l0 level1 =
lfo2'><![if !supportLists]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><span
style=3D'mso-list:Ignore'>3.<font size=3D1 face=3D"Times New =
Roman"><span
style=3D'font:7.0pt "Times New =
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</span></font></span></span></font><![endif]><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>meanwhile,
in a loop, peer B receive byte streams through the TCPStream::read, =
after which
follows a call of TCPStream::gcount() to know how many bytes the =
previous
read() has read in &#8211; a exit condition for the loop is gcound() =
returns 0,
indicating tcp stream has nothing to read and should be closed to =
release this
tcp resource.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Here comes the bug: the last TCPStrteam::read() =
actually
reads some bytes before its underlying (socket) read returns 0. The 0 =
return
value would immediately call clear(ios::failbit | rdstate() ) (line =
2911,
src/csocket.cpp, commoncpp-1.6.3), which in turn resets gcount internal =
data
structure _<i><span style=3D'font-style:italic'>M</span></i>_gcount to =
0, causing
the subsequent TCPStream::gcount() returns the incorrect =
0.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>For a socket read to return 0 is quite normal and =
legitimate
when the peer send FIN and enters the so-called half-close state.
TCPStream::read() actually reads correctly all the byte stream that =
might be
queued, but the TCPStream::gcount returning 0 subsequently is definitely
conflicting what is expected from a read/gcound with an istream =
object.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Hope this description serves its purpose =
well.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Regards,<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Howell Chen<o:p></o:p></span></font></p>

</div>

</body>

</html>



------_=_NextPart_001_01C911D5.DD980FAA--



