Unverified Commit 93f6d810 authored by Nathan Van Overloop's avatar Nathan Van Overloop
Browse files

centralnic/issues#3769: insert context anyhow and add more debug

parent 1425fb3a
......@@ -57,22 +57,32 @@
function connect($host, $port=700, $timeout=1, $ssl=true, $context=NULL) {
debug_log("start connecting");
$target = sprintf('%s://%s:%d', ($ssl === true ? 'tls' : 'tcp'), $host, $port);
if (!$this->socket = @stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT,$context)) {
throw new Exception("Error connecting to $target: $errstr (code $errno)");
if (is_resource($context)) {
$result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);
} else {
debug_log("connection succeeded");
// Set stream timeout
if (!stream_set_timeout($this->socket,$timeout)) {
throw new Exception("Failed to set timeout on socket: $errstr (code $errno)");
}
// Set blocking
if (!stream_set_blocking($this->socket,0)) {
throw new Exception("Failed to set blocking on socket: $errstr (code $errno)");
}
return $this->getFrame();
$result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
}
if ($result === False) {
throw new Exception("Error connecting to $target: $errstr (code $errno)");
}
// Set our socket
$this->socket = $result;
debug_log("connected");
// Set stream timeout
if (!stream_set_timeout($this->socket,$timeout)) {
throw new Exception("Failed to set timeout on socket: $errstr (code $errno)");
}
// Set blocking
if (!stream_set_blocking($this->socket,0)) {
throw new Exception("Failed to set blocking on socket: $errstr (code $errno)");
}
debug_log("trying to get frame from server");
return $this->getFrame();
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment