Antwort: Bug #1695 Updated: fgets read to few data (1 byte)

From: Date: Mon, 12 Jul 1999 15:45:36 +0000
Subject: Antwort: Bug #1695 Updated: fgets read to few data (1 byte)
Groups: php.dev 
Request: Send a blank email to php-dev+get-8390@lists.php.net to get a copy of this message
Hello Again, fgets - bug (reading and writing data from blocket socket without LF and EOF) OK, sorry - the problem is more difficult. I am reading and writing binary data from a socket based server (no LF and no EOF between the requests). The latest version doing it was php3.0.6. Then we try php3.0.9 where this application did not work. Before i try to find out whats going wrong there is php3.0.11 available and we test it. same problem. Now we have to read n+1 byte (this has changed) in fgets. This work fine for the first m requests, but the last request sleep forever. So i start debugging (its not easy to find a small example to send you). The problem is the buffered io in blocked sockets. If we want to read the last x < 512 bytes, from socket and the bytes are always in the buffer, php try to wait for data with funktion _php_sock_wait_for_data() ! In funktion _php3_sock_fgets the nr_toread did cause the bug. Firs it try _php3_sock_read_limited( sock, 0) whitch return zero. Next it try _php3_sock_read_limited( sock, 512). This end in _php_sock_wait_for_data(). But all data are available in the buffer and the server will not send any more bytes! there is no need for nr_toread. replace line 600 in file functions/fsock.c: < nr_read += _php3_sock_read_limited( sock, nr_toread); > nr_read += _php3_sock_read_limited( sock, maxlen); i am no nativ speaker, but i hope you will understand the problem. If not, i try to make a sample. Andreas (Embedded image moved Bug Database <php-dev@lists.php.net> to file: 12.07.99 08:43 pic23645.pcx) An: andreas rieber Kopie: Thema: Bug #1695 Updated: fgets read to few data (1 byte) ID: 1695 Updated by: sas Reported By: andreas.rieber@tlc.de Status: Closed Bug Type: Other Assigned To: Comments: The observed behaviour is correct. From the Single Unix Specification: char *fgets(char *s, int n, FILE *stream); The fgets() function reads bytes from stream into the array pointed to by s, until n-1 bytes are read, or a newline character is read and transferred to s, or an end-of-file condition is encountered. The string is then terminated with a null byte. Full Bug description available at: http://bugs.php.net/?id=1695

Attachment: [application/octet-stream] pic23645.pcx
« previous php.dev (#8390) next »