40 $status = $this->manager->get( $this->key );
41 if ( !$status->isOK() ) {
44 $this->conn = $status->value[
'conn'];
45 $this->hostName = $status->value[
'hostName'];
49 stream_set_timeout( $this->conn, 0, (
int)( $this->timeout * 1e6 * 1.5 ) );
52 return Status::newGood( $this->conn );
60 $args = str_replace(
' ',
'%20', $args );
61 $cmd = implode(
' ', $args );
62 $status = $this->getConn();
63 if ( !$status->isOK() ) {
66 $conn = $status->value;
67 $this->logger->debug(
"Sending pool counter command: $cmd" );
68 if ( fwrite( $conn,
"$cmd\n" ) ===
false ) {
69 return Status::newFatal(
'poolcounter-write-error', $this->hostName );
71 $response = fgets( $conn );
72 if ( $response ===
false ) {
73 return Status::newFatal(
'poolcounter-read-error', $this->hostName );
75 $response = rtrim( $response,
"\r\n" );
76 $this->logger->debug(
"Got pool counter response: $response" );
77 $parts = explode(
' ', $response, 2 );
78 $responseType = $parts[0];
79 switch ( $responseType ) {
94 $parts = explode(
' ', $parts[1], 2 );
95 $errorMsg = $parts[1] ??
'(no message given)';
96 return Status::newFatal(
'poolcounter-remote-error', $errorMsg, $this->hostName );
98 return Status::newGood( constant(
"PoolCounter::$responseType" ) );