diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-05-16 07:13:45 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-05-16 07:13:45 +0000 |
commit | cebb21facc2e2219f1d498def8ee19bbb4b72f7e (patch) | |
tree | 17c779f616c63ab8bc552ea2e4ce8a66a6f7e460 /modules/mpd | |
parent | 8046e377bcb7a83b8966e7a2809b905071f7f08a (diff) | |
download | ampache-cebb21facc2e2219f1d498def8ee19bbb4b72f7e.tar.gz ampache-cebb21facc2e2219f1d498def8ee19bbb4b72f7e.tar.bz2 ampache-cebb21facc2e2219f1d498def8ee19bbb4b72f7e.zip |
fixed mpd timeout issues and a stupid little theme config load issue
Diffstat (limited to 'modules/mpd')
-rw-r--r-- | modules/mpd/mpd.class.php | 82 |
1 files changed, 51 insertions, 31 deletions
diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php index 2556f01b..2fe297f6 100644 --- a/modules/mpd/mpd.class.php +++ b/modules/mpd/mpd.class.php @@ -120,7 +120,7 @@ class mpd { $this->host = $srv;
$this->port = $port;
$this->password = $pwd;
-
+ $resp = $this->Connect();
if ( is_null($resp) ) {
$this->errStr = "Could not connect";
@@ -142,36 +142,56 @@ class mpd { $this->connected = FALSE;
$this->errStr = "Password required to access server";
return;
- }
- }
- }
- }
-
- /* Connect()
- *
- * Connects to the MPD server.
- *
- * NOTE: This is called automatically upon object instantiation; you should not need to call this directly.
- */
- function Connect() {
- if ( $this->debugging ) echo "mpd->Connect() / host: ".$this->host.", port: ".$this->port."\n";
- $this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,10);
- if (!$this->mpd_sock) {
- $this->errStr = "Socket Error: $errStr ($errNo)";
- return NULL;
- } else {
- while(!feof($this->mpd_sock)) {
- $response = fgets($this->mpd_sock,1024);
- if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) {
- $this->connected = TRUE;
- return $response;
- break;
- }
- if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) {
- $this->errStr = "Server responded with: $response";
- return NULL;
- }
- }
+ } + } + } + } + + /* Connect() + * + * Connects to the MPD server. + * + * NOTE: This is called automatically upon object instantiation; you should not need to call this directly. + */ + function Connect() { + if ( $this->debugging ) echo "mpd->Connect() / host: ".$this->host.", port: ".$this->port."\n"; + $this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,3); + /* Vollmerize this bizatch, if we've got php4.3+ we should + * have these functions and we need them + */ + if (function_exists('stream_set_timeout')) { + + /* Set the timeout on the connection */ + stream_set_timeout($this->mpd_sock,2); + + /* We want blocking, cause otherwise it doesn't + * timeout, and feof just keeps on spinning + */ + stream_set_blocking($this->mpd_sock,TRUE); + $status = socket_get_status($this->mpd_sock); + } + + if (!$this->mpd_sock) { + $this->errStr = "Socket Error: $errStr ($errNo)"; + return NULL; + } else { + while(!feof($this->mpd_sock) && !$status['timed_out']) { + $response = fgets($this->mpd_sock,1024); + if (function_exists('socket_get_status')) { + $status = socket_get_status($this->mpd_sock); + } + if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) { + $this->connected = TRUE; + return $response; + break; + } + if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) { + $this->errStr = "Server responded with: $response"; + return NULL; + } + + + } // end while // Generic response
$this->errStr = "Connection not available";
return NULL;
|