#35086 [Opn-Fbk]: socket_read() does not return empty string after receiving '\n'

2005-12-05 Thread sniper
 ID:   35086
 Updated by:   [EMAIL PROTECTED]
 Reported By:  jelte dot werkhoven at cruisetravel dot nl
-Status:   Open
+Status:   Feedback
 Bug Type: Sockets related
 Operating System: GNU/Linux (SuSE 10.0)
 PHP Version:  5CVS, 4CVS (2005-11-08) (snap)
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip




Previous Comments:


[2005-11-08 08:49:34] jelte dot werkhoven at cruisetravel dot nl

... 

I expect it to return ACK, then return   because of the '\n' and
break the while loop, which it doesn't. As far as I understand from the
manual it should.



[2005-11-07 15:30:06] [EMAIL PROTECTED]

So what's wrong in this? Of course it's 4 chars. 
ACK\n == 4 chars.




[2005-11-07 09:31:28] jelte dot werkhoven at cruisetravel dot nl

Oh and it doesn't break the while-loop.



[2005-11-07 09:30:21] jelte dot werkhoven at cruisetravel dot nl

CODE:

echo Reading daemon response:\n;
while( $out = socket_read($socket, 2048, PHP_NORMAL_READ) ) {
//if( strncmp( $out, 'ACK', 3 ) == 0 ) break;   
var_dump( $out );
}

RESULT:

OK got socket.
Attempting to connect to '127.0.0.1' on port '8001'...OK got
connection.
OK wrote connection string 'REQ
'.
Reading daemon response:
string(4) ACK


Note the trailing '\n' to the ACK response, also note it's a string(4).



[2005-11-03 22:06:28] [EMAIL PROTECTED]

Try 'var_dump($out);' before those 'if' clauses.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/35086

-- 
Edit this bug report at http://bugs.php.net/?id=35086edit=1


#35086 [Opn-Fbk]: socket_read does not return empty string after receiving '\n'

2005-11-08 Thread sniper
 ID:   35086
 Updated by:   [EMAIL PROTECTED]
 Reported By:  jelte dot werkhoven at cruisetravel dot nl
-Status:   Open
+Status:   Feedback
 Bug Type: Sockets related
 Operating System: GNU/Linux (SuSE 10.0)
 PHP Version:  4.4.1
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip




Previous Comments:


[2005-11-08 08:49:34] jelte dot werkhoven at cruisetravel dot nl

... 

I expect it to return ACK, then return   because of the '\n' and
break the while loop, which it doesn't. As far as I understand from the
manual it should.



[2005-11-07 15:30:06] [EMAIL PROTECTED]

So what's wrong in this? Of course it's 4 chars. 
ACK\n == 4 chars.




[2005-11-07 09:31:28] jelte dot werkhoven at cruisetravel dot nl

Oh and it doesn't break the while-loop.



[2005-11-07 09:30:21] jelte dot werkhoven at cruisetravel dot nl

CODE:

echo Reading daemon response:\n;
while( $out = socket_read($socket, 2048, PHP_NORMAL_READ) ) {
//if( strncmp( $out, 'ACK', 3 ) == 0 ) break;   
var_dump( $out );
}

RESULT:

OK got socket.
Attempting to connect to '127.0.0.1' on port '8001'...OK got
connection.
OK wrote connection string 'REQ
'.
Reading daemon response:
string(4) ACK


Note the trailing '\n' to the ACK response, also note it's a string(4).



[2005-11-03 22:06:28] [EMAIL PROTECTED]

Try 'var_dump($out);' before those 'if' clauses.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/35086

-- 
Edit this bug report at http://bugs.php.net/?id=35086edit=1


#35086 [Opn-Fbk]: socket_read does not return empty string after receiving '\n'

2005-11-07 Thread sniper
 ID:   35086
 Updated by:   [EMAIL PROTECTED]
 Reported By:  jelte dot werkhoven at cruisetravel dot nl
-Status:   Open
+Status:   Feedback
 Bug Type: Sockets related
 Operating System: GNU/Linux (SuSE 10.0)
 PHP Version:  4.4.1
 New Comment:

So what's wrong in this? Of course it's 4 chars. 
ACK\n == 4 chars.



Previous Comments:


[2005-11-07 09:31:28] jelte dot werkhoven at cruisetravel dot nl

Oh and it doesn't break the while-loop.



[2005-11-07 09:30:21] jelte dot werkhoven at cruisetravel dot nl

CODE:

echo Reading daemon response:\n;
while( $out = socket_read($socket, 2048, PHP_NORMAL_READ) ) {
//if( strncmp( $out, 'ACK', 3 ) == 0 ) break;   
var_dump( $out );
}

RESULT:

OK got socket.
Attempting to connect to '127.0.0.1' on port '8001'...OK got
connection.
OK wrote connection string 'REQ
'.
Reading daemon response:
string(4) ACK


Note the trailing '\n' to the ACK response, also note it's a string(4).



[2005-11-03 22:06:28] [EMAIL PROTECTED]

Try 'var_dump($out);' before those 'if' clauses.




[2005-11-03 14:41:00] jelte dot werkhoven at cruisetravel dot nl

Description:

This seems to be a replica of bug #21880, but I can replicate it each
time. I've got a proxy daemon written in C that terminates data with a
line break (linux '\n'). As I understand it, this should cause
socket_read to return an empty string, if called with the
PHP_NORMAL_READ flag. However, it doesn't and just hangs. BTW, version
is PHP 4.4.0 CLI. Connecting to said proxy daemon with either netcat or
telnet works as expected.

Reproduce code:
---
/* Get the port for the WWW service. */
$service_port = 8001;

/* Get the IP address for the target host. */
$address = gethostbyname('localhost');

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket  0) {
   echo socket_create() failed: reason:  . socket_strerror($socket) .
\n;
} else {
   echo OK got socket.\n;
}

echo Attempting to connect to '$address' on port '$service_port'...;

$result = @socket_connect($socket, $address, $service_port);

if (!$result) {
   die(socket_connect() failed.\nReason:  .
socket_strerror(socket_last_error()) . \n);
} else {
   echo OK got connection.\n;
}

$in = REQ\n;

$out = '';

socket_write($socket, $in, strlen($in));
echo OK wrote connection string '$in'.\n;

echo Reading daemon response:\n;
while( $out = socket_read($socket, 2048, PHP_NORMAL_READ) ) {
//if( strncmp( $out, 'ACK', 3 ) == 0 ) break;   
if( $out === false ) echo FALSE!;
if( $out == '' ) echo ZILCH!;
}



Expected result:

Commented out strncmp line is workaround, without it, it never breaks
out of the while loop which I think it should. I figure it should echo
either ZILCH on receiving '\n' which is prepended to the ACK reply of
the daemon, or FALSE as the daemon disconnects after sending the ACK
string.
If I use it with the workaround I can actually see that the line
terminator is sent because PHP echo's it when I echo the $out string.



Actual result:
--
OK got socket.
Attempting to connect to '127.0.0.1' on port '8001'...OK got
connection.
OK wrote connection string 'REQ
'.
Reading daemon response:


And it hangs indefinately.





-- 
Edit this bug report at http://bugs.php.net/?id=35086edit=1


#35086 [Opn-Fbk]: socket_read does not return empty string after receiving '\n'

2005-11-03 Thread sniper
 ID:   35086
 Updated by:   [EMAIL PROTECTED]
 Reported By:  jelte dot werkhoven at cruisetravel dot nl
-Status:   Open
+Status:   Feedback
 Bug Type: Sockets related
 Operating System: GNU/Linux (SuSE 10.0)
 PHP Version:  4.4.1
 New Comment:

Try 'var_dump($out);' before those 'if' clauses.



Previous Comments:


[2005-11-03 14:41:00] jelte dot werkhoven at cruisetravel dot nl

Description:

This seems to be a replica of bug #21880, but I can replicate it each
time. I've got a proxy daemon written in C that terminates data with a
line break (linux '\n'). As I understand it, this should cause
socket_read to return an empty string, if called with the
PHP_NORMAL_READ flag. However, it doesn't and just hangs. BTW, version
is PHP 4.4.0 CLI. Connecting to said proxy daemon with either netcat or
telnet works as expected.

Reproduce code:
---
/* Get the port for the WWW service. */
$service_port = 8001;

/* Get the IP address for the target host. */
$address = gethostbyname('localhost');

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket  0) {
   echo socket_create() failed: reason:  . socket_strerror($socket) .
\n;
} else {
   echo OK got socket.\n;
}

echo Attempting to connect to '$address' on port '$service_port'...;

$result = @socket_connect($socket, $address, $service_port);

if (!$result) {
   die(socket_connect() failed.\nReason:  .
socket_strerror(socket_last_error()) . \n);
} else {
   echo OK got connection.\n;
}

$in = REQ\n;

$out = '';

socket_write($socket, $in, strlen($in));
echo OK wrote connection string '$in'.\n;

echo Reading daemon response:\n;
while( $out = socket_read($socket, 2048, PHP_NORMAL_READ) ) {
//if( strncmp( $out, 'ACK', 3 ) == 0 ) break;   
if( $out === false ) echo FALSE!;
if( $out == '' ) echo ZILCH!;
}



Expected result:

Commented out strncmp line is workaround, without it, it never breaks
out of the while loop which I think it should. I figure it should echo
either ZILCH on receiving '\n' which is prepended to the ACK reply of
the daemon, or FALSE as the daemon disconnects after sending the ACK
string.
If I use it with the workaround I can actually see that the line
terminator is sent because PHP echo's it when I echo the $out string.



Actual result:
--
OK got socket.
Attempting to connect to '127.0.0.1' on port '8001'...OK got
connection.
OK wrote connection string 'REQ
'.
Reading daemon response:


And it hangs indefinately.





-- 
Edit this bug report at http://bugs.php.net/?id=35086edit=1