Handle given message protocol.

@param string $sender
@param ProtocolInterface $protocol
@param int $flags
@param callable|null $success
@param callable|null $failure
@param callable|null $cancel
@param float $timeout
@return bool
339615
public function handle($sender, ProtocolInterface $protocol, $flags, callable $success = null, callable $failure = null, callable $cancel = null, $timeout = 0.0)
    {
        $callback = $this->handler;
        $callback($sender, $protocol, $flags, $success, $failure, $cancel, $timeout);

        if ($this->limit > 0)
        {
            $this->limit--;
            if ($this->limit === 0)
            {
                $this->cancel();
            }
        }

        return $this->propagate;
    }
594105
public function log($message, $flag)
    {
        $headers = [
            'token' => $this->token,
        ];

        $query = $this->processLog($message, $flag);

        $response = $this->curl::post($this->missionControlUrl, $headers, $query);

        if ($response->code != 200) {
            $this->error('Unable to message Mission Control, please confirm your token');
        }

        return true;
    }
1097527
public static function HeadRequest ($url, $timeout = 30, $protocol_version = self::VERSION_1_1) {
		$parsed_url = parse_url($url);

		$host = $parsed_url['host'];
		if (!isset($parsed_url['port'])) {
			$port = $parsed_url['scheme'] === 'https' ? 443 : 80;
		}
		$path = $parsed_url['path'];

		$request_headers = [
			sprintf('HEAD %s HTTP/%s', $path, $protocol_version),
			'User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)',
			sprintf('Host: %s', $host),
			'Connection: Close',
		];
		$request_header = implode("\r\n", $request_headers) . "\r\n\r\n";

		$schema = $parsed_url['scheme'] === 'https' ? 'ssl://' : '';

		$fp = fsockopen($schema . $host, $port, $errno, $errstr, $timeout);
		if (!$fp) {
			CoreException::ScrubbedThrow(Status::SystemError(sprintf('%s (%s)', $errstr, $errno)));
		}

		fwrite($fp, $request_header);

		$return_data = [];
		while (!feof($fp)) {
			$return_data[] = trim(fgets($fp, 4000));
		}
		fclose($fp);

		$result = [];
		foreach ($return_data as $row) {
			if (preg_match("/^HTTP\/(\d+.\d+) (\d+) (.+)$/", $row, $matches) === 1) {
				$result['http'] = [
					'version'	=> $matches[1],
					'status'	=> [
						'code'		=> $matches[2],
						'message'	=> $matches[3],
					],
				];
				continue;
			}
			if (preg_match("/^([^:]+): (.+)/", $row, $matches) === 1) {
				$result[$matches[1]] = $matches[2];
				continue;
			}
		}
		return $result;
	}
979270
protected function fireEvent($event, $payload = [ ], $halt = false)
    {
        if (! isset($this->dispatcher)) {
            $this->initEventDispatcher();
        }

        $dispatcher = $this->dispatcher;
        $status     = $this->dispatcherStatus;
        if (! $dispatcher || $status === false) {
            return;
        }
        $method = $halt ? 'until' : 'fire';

        return $dispatcher->{$method}($event, $payload);
    }
747119
public function fireOff(string $event, $sender, array $arguments = null) {
        $arguments = (array)$arguments;
        array_unshift($arguments, $sender);
        return $this->fire($event, $arguments);
    }
721396
function _append_log($protocol_flags, $message)
    {
        switch (NET_SSH1_LOGGING) {
            // useful for benchmarks
            case self::LOG_SIMPLE:
                $this->protocol_flags_log[] = $protocol_flags;
                break;
            // the most useful log for SSH1
            case self::LOG_COMPLEX:
                $this->protocol_flags_log[] = $protocol_flags;
                $this->_string_shift($message);
                $this->log_size+= strlen($message);
                $this->message_log[] = $message;
                while ($this->log_size > self::LOG_MAX_SIZE) {
                    $this->log_size-= strlen(array_shift($this->message_log));
                    array_shift($this->protocol_flags_log);
                }
                break;
            // dump the output out realtime; packets may be interspersed with non packets,
            // passwords won't be filtered out and select other packets may not be correctly
            // identified
            case self::LOG_REALTIME:
                echo "<pre>\r\n" . $this->_format_log(array($message), array($protocol_flags)) . "\r\n</pre>\r\n";
                @flush();
                @ob_flush();
                break;
            // basically the same thing as self::LOG_REALTIME with the caveat that self::LOG_REALTIME_FILE
            // needs to be defined and that the resultant log file will be capped out at self::LOG_MAX_SIZE.
            // the earliest part of the log file is denoted by the first <<< START >>> and is not going to necessarily
            // at the beginning of the file
            case self::LOG_REALTIME_FILE:
                if (!isset($this->realtime_log_file)) {
                    // PHP doesn't seem to like using constants in fopen()
                    $filename = self::LOG_REALTIME_FILE;
                    $fp = fopen($filename, 'w');
                    $this->realtime_log_file = $fp;
                }
                if (!is_resource($this->realtime_log_file)) {
                    break;
                }
                $entry = $this->_format_log(array($message), array($protocol_flags));
                if ($this->realtime_log_wrap) {
                    $temp = "<<< START >>>\r\n";
                    $entry.= $temp;
                    fseek($this->realtime_log_file, ftell($this->realtime_log_file) - strlen($temp));
                }
                $this->realtime_log_size+= strlen($entry);
                if ($this->realtime_log_size > self::LOG_MAX_SIZE) {
                    fseek($this->realtime_log_file, 0);
                    $this->realtime_log_size = strlen($entry);
                    $this->realtime_log_wrap = true;
                }
                fputs($this->realtime_log_file, $entry);
        }
    }
899495
protected function redirectWithMessages( $flag, $successMessage, $failedMessage ) {
        if ( $flag ) {
            Yii::$app->session->setFlash( 'success', $successMessage );
            return $this->controller->redirect( $this->successUrl );
        } else {
            Yii::$app->session->setFlash( 'warning', $failedMessage );
            return $this->controller->redirect( $this->failedUrl );
        }
    }
536892
public function send($msg, $timeout=NULL) {

		if (is_null($timeout)) {
			$secs = NULL;
			$usecs = NULL;
		} else if ($timeout == 0) {
			$secs = 0;
			$usecs = 0;
		} else {
			$maximum = $timeout * 1000000;
			$usecs = $maximum % 1000000;
			$secs = floor(($maximum - $usecs) / 1000000);
		}

		$read = array();
		$write = array($this->socket);
		$except = array();

		$select = @stream_select($read, $write, $except, $secs, $usecs);

		if($select === False) {
			$this->log->log("ERROR sending message; reconnecting.");
			$this->doReconnect();
			# TODO: retry send here
			return false;
		} elseif ($select > 0) {
			$this->log->log("Socket is ready; send it.", Net_XMPP_XMPPHP_Log::LEVEL_VERBOSE);
		} else {
			$this->log->log("Socket is not ready; break.", Net_XMPP_XMPPHP_Log::LEVEL_ERROR);
			return false;
		}
		$sentbytes = @fwrite($this->socket, $msg);
		$this->log->log("SENT: " . mb_substr($msg, 0, $sentbytes, '8bit'), Net_XMPP_XMPPHP_Log::LEVEL_VERBOSE);
		if($sentbytes === FALSE) {
			$this->log->log("ERROR sending message; reconnecting.", Net_XMPP_XMPPHP_Log::LEVEL_ERROR);
			$this->doReconnect();
			return false;
		}
		$this->log->log("Successfully sent $sentbytes bytes.", Net_XMPP_XMPPHP_Log::LEVEL_VERBOSE);
		return $sentbytes;
	}
740589
public function send(MessageInterface $message, $skipErrors = true) {
        $this->clearErrors();

        $command = $this->prepareCommand($message->getText());

        foreach ($message->getRecipient() as $recipient) {
            // execute command
            $command = str_replace('#RECIPIENT#', $recipient, $command);

            $return = 0;
            $output = [];
            exec($command, $output, $return);

            if ($return !== 0) {
                $errorMsg = sprintf("Error while sending message to \"%s\".", $recipient);
                $this->addError(new SendingError($recipient, self::ERROR_NOT_SAVED, $errorMsg));
                if (!$skipErrors) {
                    throw new RuntimeException($errorMsg, self::ERROR_NOT_SAVED);
                }
            }
        }
        return $this->getErrors()->count() === 0;
    }
1000637
public function execute($callable = null)
    {
        $this->checkBeforeExecution($callable);

        $execResponse = null;
        $attempts = $this->attempts;

        do {
            if ($callable) {
                $this->executeTransactionBlock($callable);
            }

            if ($this->commands->isEmpty()) {
                if ($this->state->isWatching()) {
                    $this->discard();
                }

                return;
            }

            $execResponse = $this->call('EXEC');

            if ($execResponse === null) {
                if ($attempts === 0) {
                    throw new AbortedMultiExecException(
                        $this, 'The current transaction has been aborted by the server.'
                    );
                }

                $this->reset();

                continue;
            }

            break;
        } while ($attempts-- > 0);

        $response = array();
        $commands = $this->commands;
        $size = count($execResponse);

        if ($size !== count($commands)) {
            $this->onProtocolError('EXEC returned an unexpected number of response items.');
        }

        for ($i = 0; $i < $size; ++$i) {
            $cmdResponse = $execResponse[$i];

            if ($cmdResponse instanceof ErrorResponseInterface && $this->exceptions) {
                throw new ServerException($cmdResponse->getMessage());
            }

            $response[$i] = $commands->dequeue()->parseResponse($cmdResponse);
        }

        return $response;
    }
940309
public function handleMessage(ThreadCommunicator $communicator, $messagePayload)
    {
        $action = $messagePayload['action'];
        $parameters = $messagePayload['parameters'];

        if (method_exists($this, $action)) {
            return call_user_func_array(array($this, $action), $parameters);
        }

        return false;
    }
939983
public function setSender(Apns\Sender $sender)
	{
		$this->sender = $sender;
		$this->sender->setLogger($this->logger);
	}
344477
public function send(RequestDescriptor $request, $flags = 0)
    {
        if (!empty($this->getAuthorization())) {
            $request->addHeader(self::OPTION_HEADER_AUTHORIZATION, $this->getAuthorization());
        }

        if ($this->delayNext || $this->isDelayed) {
            if (!$this->forceNext) {
                $this->delayedRequests[] = array($request, $flags | ApiRequestOption::NO_RESPONSE);

                // reset stackNext flag
                $this->delayNext = false;

                return true;
            } else {
                // reset forceNext flag
                $this->forceNext = false;
            }
        }

        $transport = $this->getAppropriateTransport($flags);

        if (is_null($transport)) {
            throw new ApiClientException(sprintf('No transport has been set on "%s"', get_class()));
        }

        try {
            $response = $transport->send($request, $flags);
        } catch (TransportException $e) {
            // fallback?
            if ($fallback = $this->getFallbackTransport()) {
                $response = $fallback->send($request, $flags);
            } else {
                throw $e;
            }
        }

        $this->resetFallbackTransport();

        return $response;
    }
334897
public function Base_ConnectData_Handler($Sender, $Args) {
      if (GetValue(0, $Args) != 'openid')
         return;

      $Mode = $Sender->Request->Get('openid_mode');
      if ($Mode != 'id_res')
         return; // this will error out

      $this->EventArguments = $Args;
      
      // Check session before retrieving
      $Session = Gdn::Session();
      $OpenID = $Session->Stash('OpenID', '', FALSE);
      if (!$OpenID)
         $OpenID = $this->GetOpenID();
      
      if ($Session->Stash('OpenID', '', FALSE) || $OpenID->validate()) {
         $Attr = $OpenID->getAttributes();

         $Form = $Sender->Form; //new Gdn_Form();
         $ID = $OpenID->identity;
         $Form->SetFormValue('UniqueID', $ID);
         $Form->SetFormValue('Provider', self::$ProviderKey);
         $Form->SetFormValue('ProviderName', 'OpenID');
         $Form->SetFormValue('FullName', GetValue('namePerson/first', $Attr).' '.GetValue('namePerson/last', $Attr));
         
         if ($Email = GetValue('contact/email', $Attr)) {
            $Form->SetFormValue('Email', $Email);
         }
         
         $Sender->SetData('Verified', TRUE);
         $Session->Stash('OpenID', $OpenID);
      }
   }
527749
public function send(RequestDescriptor $requestDescriptor, $flags = 0)
    {
        try {
            $request = $this->getRequestFactory()->create($requestDescriptor);
            $response = $this->getClient()->send($request);
        } catch (\Exception $exception) {
            throw new ApiClientException('An error occurred while transporting a request', $exception->getCode(), $exception);
        }

        $responseDescriptor = new ResponseDescriptor();
        $responseDescriptor->setBody($response->getBody());
        $responseDescriptor->setCode($response->getStatusCode());
        $responseDescriptor->setHeaders($response->getHeaders());

        return $responseDescriptor;
    }
465081
public static function badRequest(string $message, string $protocol = Protocol::HTTP): self
    {
        return new static(sprintf('Bad Request: `%s`', $message), $protocol, 400);
    }
771808
public static function register(string $protocol, string $root = null, int $flags = 0): bool
    {
        $wrappers = stream_get_wrappers();
        if (in_array($protocol, $wrappers)) {
            throw new Exception(
                "Protocol '$protocol' has been already registered"
            );
        }
        $wrapper = stream_wrapper_register($protocol, get_called_class(), $flags);

        if ($wrapper) {
            if (null !== $root) {
                $content = Entity::newInstance($root);
            } else {
                $content = null;
            }

            $partition = new Partition($content);

            self::$partitions[$protocol] = $partition;
        }

        return $wrapper;
    }