[Patch] Fix Socket read returns EOF when count == 0...

David Daney ddaney@avtrex.com
Tue Mar 15 00:04:00 GMT 2005

For POSIX, a call to read(byte[] b, int off, int count)  with count of 
zero on a Socket's InputStream returns -1 signaling EOF.

This is because the count is propagated the the ::recv() system call 
which returns the number of bytes read or zero to signal EOF.  Since 
zero bytes were requested we report EOF when we should report zero bytes 

Before recent fixes to BufferedInputStream, some HTTP URLConnections 
were being broken because of this behavior.  Since the 
BufferedInputStream was fixed I have not experienced any problems, but 
this is a latent bug waiting to bite someone else.

FWIW: FileInputStream has similar handling for the count == 0 case.

Tested on the HEAD on i686-pc-linux with make check in libjava with no 
regressions.  No regressions in mauve in the 4.0 branch (HEAD not tested 
in mauve due to ICE in mauve)

2005-03-14  David Daney  <ddaney@avtrex.com>

	* gnu/java/net/natPlainSocketImplPosix.cc (read_helper): Handle
	count == 0 case.

O.K to commit to HEAD?

How about the 4.0 branch for good measure?

David Daney.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: net.patch
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20050315/296301ef/attachment.ksh>

More information about the Java-patches mailing list