Defines socket transport

@param string $transport
@return $this
545063
public function setTransport($transport)
    {
        if (!in_array($transport,stream_get_transports())) {
            throw new \DomainException(sprintf('Unsupported type of transport "%s"', $transport));
        }

        $this->transport = $transport;
        return $this;
    }
422079
public function setPort($port)
    {
        if ( ! is_null($port)) $port = (int) $port;

        $this->setAttribute('port', $port);

        return $this;
    }
1201968
public function setPort($port)
    {
        if (!is_int($port) || $port < 0 || $port > 65535) {
            throw new InvalidArgumentException(
                sprintf('%s only accepts a port between 0 and 65535 inclusive', __FUNCTION__)
            );
        }

        $this->port = $port;

        return $this;
    }
830879
public function connectTcp($host, $port)
    {
        $this->type = 'tcp';
        $pton = @inet_pton($host);
        $fd = null;
        if ($pton === false) { // dirty check
            \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($this->host, function ($result) use ($host, $port) {
                if (!$result) {
                    Daemon::log(get_class($this) . '->connectTcp : unable to resolve hostname: ' . $host);
                    $this->onStateEv($this->bev, \EventBufferEvent::ERROR);
                    return;
                }
                // @todo stack of addrs
                if (is_array($result)) {
                    if (!sizeof($result)) {
                        return;
                    }
                    srand(Daemon::$process->getPid());
                    $real = $result[rand(0, sizeof($result) - 1)];
                    srand();
                } else {
                    $real = $result;
                }
                $this->connectTcp($real, $port);
            });
            return true;
        }
        $this->hostReal = $host;
        if ($this->host === null) {
            $this->host = $this->hostReal;
        }
        // TCP
        $l = mb_orig_strlen($pton);
        if ($l === 4) {
            $this->addr = $host . ':' . $port;
            if (!$this->bevConnectEnabled) {
                $fd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
            }
        } elseif ($l === 16) {
            $this->addr = '[' . $host . ']:' . $port;
            if (!$this->bevConnectEnabled) {
                $fd = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
            }
        } else {
            return false;
        }
        if (!$this->bevConnectEnabled && !$fd) {
            return false;
        }
        if (!$this->bevConnectEnabled) {
            socket_set_nonblock($fd);
        }
        if (!$this->bevConnectEnabled) {
            $this->fd = $fd;
            $this->setTimeouts(
                $this->timeoutRead !== null ? $this->timeoutRead : $this->timeout,
                $this->timeoutWrite !== null ? $this->timeoutWrite : $this->timeout
            );
            socket_connect($fd, $host, $port);
            socket_getsockname($fd, $this->locAddr, $this->locPort);
        } else {
            $this->bevConnect = true;
        }
        $this->setFd($fd);
        if (!$this->bev) {
            return false;
        }
        return true;
    }
341649
public static function getInstance(HttpClient $transport = null)
    {
        if (is_null(self::$client)) {
            self::$client = new self();
        
            if (! is_null($transport)) {
                self::$client->setTransport($transport);
            }
        }
        
        return self::$client;
    }
481419
public function setTransport(TransportInterface $transport)
    {
        if (!$transport instanceof CurlTransport) {
            throw new \InvalidArgumentException(
                sprintf(
                    '%s only supports %s',
                    get_called_class(),
                    CurlTransport::class
                )
            );
        }

        $this->transport = $transport;

        return $this;
    }
835355
public function setTransport(Transport $transporter)
    {
        $this->transport = $transporter;
        $tao = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao');
        $tao->setConfig(self::CONFIG_KEY, $this->transport);
    }
399905
public function setNetSftpConnection($connection, $sftp)
	{
		$this->connection = $connection;
		$this->sftp = $sftp;

		return $this;
	}
82777
protected function createTransportForType($transportType, array $parameters) {
        if ($transportType === 'null') {
            return $this->createNullTransport($parameters);
        } else if ($transportType === 'sendmail') {
            return $this->createSendmailTransport($parameters);
        } else if ($transportType === 'smtp') {
            return $this->createSmtpTransport($parameters);
        }

        throw new MailerTransportTypeIsNotSupported(s(
            'Transport type "%s" is not supported.',
            $transportType
        ));
    }
24977
public function port($port = null)
    {
        if (func_num_args() === 1) {
            $this->_port = $port;
            return $this;
        }
        if ($this->_port !== null) {
            return $this->_port;
        }
        $scheme = $this->_classes['scheme'];
        $name = $this->scheme();

        if ($scheme::registered($name)) {
            return $scheme::port($name);
        }
    }
997827
public static function create($options = [], TransportInterface $transport = null)
    {
        $transport = $transport ?: static::getTransport();
        $options   = $options ?: static::getOptions();

        switch ($transport) {
            case 'mock':
                $mockOptions = isset($options['mock']) ? $options['mock'] : [];

                $transport = new StreamTransport($mockOptions);
                break;
            case 'stream':
                $streamOptions = isset($options['stream']) ? $options['stream'] : [];

                $transport = new StreamTransport($streamOptions);
                break;

            case 'curl':
            default:
                $curlOptions = isset($options['curl']) ? $options['curl'] : [];

                $transport = new CurlTransport($curlOptions);
                break;
        }

        return new HttpClient($options, $transport);
    }
713279
protected function createProtocol(string $protocol): self
    {
        $this->protocol = Factory::newProtocol($protocol);
        $this->protocol->setServer($this);

        return $this;
    }
1090487
public function useProxy($host = self::DEFAULT_PROXY_HOST, $port = self::DEFAULT_PROXY_PORT, $type = self::DEFAULT_PROXY_TYPE)
    {
        $this->setProxyType($type);
        $this->setProxyHost($host);
        $this->setProxyPort($port);

        return $this;
    }
1216180
public static function createTransport($transport, array $config)
    {
        $config = new Structure($config);

        switch ($transport) {
            case 'smtp':
                $instance = \Swift_SmtpTransport::newInstance(
                    $config->get('smtp.host'),
                    $config->get('smtp.port', 2525),
                    $config->get('smtp.security', 'tls')
                )->setUsername($config->get('smtp.username'))
                    ->setPassword($config->get('smtp.password'));

                if ($config->get('smtp.local')) {
                    $instance->setLocalDomain($config->get('local'));
                }

                if (!$config->get('smtp.verify', true)) {
                    $instance->setStreamOptions(['ssl' => ['allow_self_signed' => true, 'verify_peer' => false]]);
                }

                break;

            case 'sendmail':
                $instance = \Swift_SendmailTransport::newInstance($config->get('sendmail'));

                break;

            default:
                $instance = \Swift_MailTransport::newInstance();
        }

        return $instance;
    }
159318
private function setPort($port)
    {
        $port = (int) $port;

        if ($port < 0 || $port > 65535) {
            throw new \InvalidArgumentException('Port must be between 1 and 65535!');
        }

        if (empty($port)) {
            $port = null;
        }

        $this->port = $port;

        return $this;
    }
1118906
public function setPort($port)
    {
        if (!empty($port)) {
            $this->port = intval($port);
        }
        else {
            $this->port = null;
        }

        return $this;
    }
1000065
private function transport()
    {
        $this->transport = Transport::newInstance($this->smtp->get('host'), $this->smtp->get('port'), $this->smtp->get('encryption'))
            ->setUsername($this->smtp->get('username'))
            ->setPassword($this->smtp->get('password'));

        return $this->transport;
    }