Skip to content

Commit 2f8a087

Browse files
Dont try to write anything to sockets if there is nothing to write
1 parent 85d15d9 commit 2f8a087

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Crusse/JobServer/EventLoop.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class EventLoop {
1616
private $callbacks = array();
1717
private $sockets = array();
1818
private $stop = false;
19+
private $readBuffer = array();
20+
private $writeBuffer = array();
1921

2022
function __construct( $serverSocketAddr ) {
2123

@@ -141,10 +143,19 @@ function run() {
141143
$readables = $this->sockets;
142144
if ( $this->serverSocket )
143145
$readables[] = $this->serverSocket;
144-
$writables = $this->sockets;
145-
$nullVar = null;
146146

147-
$changedSockets = socket_select( $readables, $writables, $nullVar, $this->acceptTimeout );
147+
$writableSocketKeys = array_keys( array_filter( $this->writeBuffer ) );
148+
149+
if ( $writableSocketKeys ) {
150+
$writables = array();
151+
foreach ( $writableSocketKeys as $key )
152+
$writables[] = $this->sockets[ $key ];
153+
}
154+
else {
155+
$writables = null;
156+
}
157+
158+
$changedSockets = socket_select( $readables, $writables, $except = null, $this->acceptTimeout );
148159

149160
if ( $changedSockets === 0 ) {
150161
$this->log( 'Error: select() timed out' );

0 commit comments

Comments
 (0)