Permalink
Browse files

use blocking io in workers

  • Loading branch information...
1 parent f52d4ee commit 3d0e17aa0ab717f361d0b7a6736fa4f89d4890f3 @luciferous committed Jul 23, 2010
Showing with 4 additions and 8 deletions.
  1. +0 −2 pip/http.php
  2. +4 −6 pip/io.php
View
@@ -101,7 +101,6 @@ function _process_client($conn, $env) {
$buf = '';
$request = NULL;
while (is_null($request)) {
- if (!$conn->can_read()) continue;
$buf .= $conn->recv();
if (false === ($end = strpos($buf, "\r\n\r\n"))) continue;
$request = parse_request(substr($buf, 0, $end));
@@ -115,7 +114,6 @@ function _process_client($conn, $env) {
$bytes_left -= $stat[7];
while ($bytes_left > 0) {
logging\debug("$bytes_left bytes left");
- if (!$conn->can_read()) continue;
$buf = $conn->recv();
$bytes_left -= fwrite($env['pip.input'], $buf);
}
View
@@ -106,7 +106,6 @@ function accept() {
class Connection extends Socket {
function __construct($socket) {
$this->socket = $socket;
- socket_set_nonblock($this->socket);
}
/**
@@ -130,14 +129,13 @@ function can_read($timeout = NULL) {
/**
* Wrapper for socket_recv().
*/
- function recv() {
- $len = socket_recv($this->socket, $data, RECVBUF, MSG_DONTWAIT);
- if (false === $len) {
+ function recv($len = RECVBUF, $flags = NULL) {
+ $bytes = socket_recv($this->socket, $data, $len, $flags);
+ if (0 === $bytes) throw new ConnectionClosed();
+ if (false === $bytes) {
$code = $this->error();
- logging\error($code);
throw new SocketError(socket_strerror($code), $code);
}
- else if ($data == '') throw new ConnectionClosed();
return $data;
}

0 comments on commit 3d0e17a

Please sign in to comment.