Skip to content

Commit

Permalink
Handle unconnected connection resource consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Jun 5, 2014
1 parent d89f8c2 commit b1cb86a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions class.smtp.php
Expand Up @@ -210,7 +210,7 @@ public function connect($host, $port = null, $timeout = 30, $options = array())
$socket_context
);
// Verify we connected properly
if (empty($this->smtp_conn)) {
if (is_resource($this->smtp_conn)) {
$this->error = array(
'error' => 'Failed to connect to server',
'errno' => $errno,
Expand Down Expand Up @@ -426,7 +426,7 @@ protected function hmac($data, $key)
*/
public function connected()
{
if (!empty($this->smtp_conn)) {
if (is_resource($this->smtp_conn)) {
$sock_status = stream_get_meta_data($this->smtp_conn);
if ($sock_status['eof']) {
// the socket is valid but we are not connected
Expand Down Expand Up @@ -454,13 +454,12 @@ public function close()
{
$this->error = array();
$this->helo_rply = null;
if (!empty($this->smtp_conn)) {
if (is_resource($this->smtp_conn)) {
// close the connection and cleanup
fclose($this->smtp_conn);
if ($this->do_debug >= 3) {
$this->edebug('Connection: closed');
}
$this->smtp_conn = null;
}
}

Expand Down

0 comments on commit b1cb86a

Please sign in to comment.