Exemple #1
0
 /**
  * @param array ...$args
  * @return mixed
  */
 public function bufferEventSsl(...$args)
 {
     return \EventBufferEvent::sslSocket($this->base, ...$args);
 }
Exemple #2
0
 /**
  * Sets fd
  * @param  resource $fd  File descriptor
  * @param  object   $bev EventBufferEvent
  * @return void
  */
 public function setFd($fd, $bev = null)
 {
     $this->fd = $fd;
     if ($this->fd === false) {
         $this->finish();
         return;
     }
     if ($bev !== null) {
         $this->bev = $bev;
         $this->bev->setCallbacks([$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv']);
         if (!$this->bev) {
             return;
         }
         $this->ready = true;
         $this->alive = true;
     } else {
         $flags = !is_resource($this->fd) ? \EventBufferEvent::OPT_CLOSE_ON_FREE : 0;
         $flags |= \EventBufferEvent::OPT_DEFER_CALLBACKS;
         /* buggy option */
         if ($this->ctx) {
             if ($this->ctx instanceof \EventSslContext) {
                 $this->bev = \EventBufferEvent::sslSocket(Daemon::$process->eventBase, $this->fd, $this->ctx, $this->ctxMode, $flags);
                 if ($this->bev) {
                     $this->bev->setCallbacks([$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv']);
                 }
                 $this->ssl = true;
             } else {
                 $this->log('unsupported type of context: ' . ($this->ctx ? get_class($this->ctx) : 'undefined'));
                 return;
             }
         } else {
             $this->bev = new \EventBufferEvent(Daemon::$process->eventBase, $this->fd, $flags, [$this, 'onReadEv'], [$this, 'onWriteEv'], [$this, 'onStateEv']);
         }
         if (!$this->bev) {
             return;
         }
     }
     if ($this->priority !== null) {
         $this->bev->priority = $this->priority;
     }
     $this->setTimeouts($this->timeoutRead !== null ? $this->timeoutRead : $this->timeout, $this->timeoutWrite !== null ? $this->timeoutWrite : $this->timeout);
     if ($this->bevConnect && $this->fd === null) {
         //$this->bev->connectHost(Daemon::$process->dnsBase, $this->hostReal, $this->port);
         $this->bev->connect($this->addr);
     }
     if (!$this->bev) {
         $this->finish();
         return;
     }
     if (!$this->bev->enable(\Event::READ | \Event::WRITE | \Event::TIMEOUT | \Event::PERSIST)) {
         $this->finish();
         return;
     }
     $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark);
     init:
     if ($this->keepalive) {
         $this->setKeepalive(true);
     }
     if (!$this->inited) {
         $this->inited = true;
         $this->init();
     }
 }
Exemple #3
0
<?php

error_reporting(E_ALL);
$curr_stat = -1;
$sub_stat = [];
$stat = ['STAT_READY' => 1, 'STAT_AUTH' => 2, 'STAT_USER' => 3, 'STAT_PASSWD' => 4, 'STAT_FROM' => 5, 'STAT_TO' => 6, 'STAT_DATA' => 7, 'STAT_MAIL' => 8, 'STAT_QUIT' => 9, 'STAT_END' => 10, 'STAT_INIT' => -1];
$CRLF = "\r\n";
$timeout = 3;
$resp = '';
$args = ['host' => "mail.eyou.net:465", 'passwd' => "eYouGaoJing!nb", 'email' => "*****@*****.**"];
$fd = stream_socket_client($args['host'], $errno, $errstr, 3, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
$opt = EventBufferEvent::OPT_CLOSE_ON_FREE | EventBufferEvent::OPT_DEFER_CALLBACKS;
$base = new EventBase();
if (false !== strpos($args['host'], '465')) {
    $ctx = new EventSslContext(EventSslContext::SSLv3_CLIENT_METHOD, []);
    $bev = EventBufferEvent::sslSocket($base, $fd, $ctx, EventBufferEvent::SSL_CONNECTING, $opt);
} else {
    $bev = new EventBufferEvent($base, $fd, $opt);
}
$bev->setCallbacks('readcb', null, null, $base);
$bev->enable(Event::READ | Event::WRITE);
$bev->setTimeouts($timeout, $timeout);
$base->dispatch();
$i = 0;
function readcb($bev, $base)
{
    global $curr_stat, $stat, $sub_stat, $resp, $args;
    global $i;
    $resp = '';
    while (null !== ($msg = $bev->read(512))) {
        $resp .= $msg;