首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

EventBufferEvent (class)

Introduction

(PECL event >= 1.2.6-beta)

代表Libevent的缓冲区事件。

通常应用程序想要执行一些数据缓冲,而不仅仅是响应事件。例如,当我们想写数据时,通常的模式看起来像:

  1. 确定我们想要将一些数据写入连接; 把这些数据放入缓冲区。

2. 等待连接变为可写

3. 尽可能多地写入数据

4. 请记住我们写了多少,如果我们还有更多的数据要写入,请等待连接再次变为可写。

这种缓冲I / O模式非常普遍,Libevent为它提供了一个通用机制。“缓冲区事件”由底层传输(如套接字),读取缓冲区和写入缓冲区组成。当底层传输已准备好被读取或写入时,它会提供回调,而不是常规事件,缓冲区事件在读取或写入足够数据时调用其用户提供的回调。

课程简介

final EventBufferEvent {

/* Constants */

const integer READING = 1 ;

const integer WRITING = 2 ;

const integer EOF = 16 ;

const integer ERROR = 32 ;

const integer TIMEOUT = 64 ;

const integer CONNECTED = 128 ;

const integer OPT_CLOSE_ON_FREE = 1 ;

const integer OPT_THREADSAFE = 2 ;

const integer OPT_DEFER_CALLBACKS = 4 ;

const integer OPT_UNLOCK_CALLBACKS = 8 ;

const integer SSL_OPEN = 0 ;

const integer SSL_CONNECTING = 1 ;

const integer SSL_ACCEPTING = 2 ;

/* Properties */

public integer $fd ;

public integer $priority ;

public readonly EventBuffer $input ;

public readonly EventBuffer $output ;

/* Methods */

代码语言:javascript
复制
public void close ( void )
代码语言:javascript
复制
public bool connect (  string $addr  )
代码语言:javascript
复制
public bool connectHost (  EventDnsBase $dns_base  ,  string $hostname  ,  int $port  [,  int $family  = EventUtil::AF_UNSPEC  ] )
代码语言:javascript
复制
public __construct (  EventBase $base  [,  mixed $socket  = NULL  [,  int $options  = 0  [,  callable $readcb  = NULL  [,  callable $writecb  = NULL  [,  callable $eventcb  = NULL  ]]]]] )
代码语言:javascript
复制
public static array createPair (  EventBase $base  [,  int $options  = 0  ] )
代码语言:javascript
复制
public bool disable (  int $events  )
代码语言:javascript
复制
public bool enable (  int $events  )
代码语言:javascript
复制
public void free ( void )
代码语言:javascript
复制
public string getDnsErrorString ( void )
代码语言:javascript
复制
public int getEnabled ( void )
代码语言:javascript
复制
public EventBuffer getInput ( void )
代码语言:javascript
复制
public EventBuffer getOutput ( void )
代码语言:javascript
复制
public string read (  int $size  )
代码语言:javascript
复制
public bool readBuffer (  EventBuffer $buf  )
代码语言:javascript
复制
public void setCallbacks (  callable $readcb  ,  callable $writecb  ,  callable $eventcb  [,  string $arg  ] )
代码语言:javascript
复制
public bool setPriority (  int $priority  )
代码语言:javascript
复制
public bool setTimeouts (  float $timeout_read  ,  float $timeout_write  )
代码语言:javascript
复制
public void setWatermark (  int $events  ,  int $lowmark  ,  int $highmark  )
代码语言:javascript
复制
public string sslError ( void )
代码语言:javascript
复制
public static EventBufferEvent sslFilter (  EventBase $base  ,  EventBufferEvent $underlying  ,  EventSslContext $ctx  ,  int $state  [,  int $options  = 0  ] )
代码语言:javascript
复制
public string sslGetCipherInfo ( void )
代码语言:javascript
复制
public string sslGetCipherName ( void )
代码语言:javascript
复制
public string sslGetCipherVersion ( void )
代码语言:javascript
复制
public string sslGetProtocol ( void )
代码语言:javascript
复制
public void sslRenegotiate ( void )
代码语言:javascript
复制
public static EventBufferEvent sslSocket (  EventBase $base  ,  mixed $socket  ,  EventSslContext $ctx  ,  int $state  [,  int $options  ] )
代码语言:javascript
复制
public bool write (  string $data  )
代码语言:javascript
复制
public bool writeBuffer (  EventBuffer $buf  )

}

属性

fd

与缓冲区事件关联的数字文件描述符。通常表示一个绑定的套接字。等同于NULL,如果没有与缓冲区事件关联的文件描述符(套接字)。

优先

用于实现缓冲区事件的事件的优先级。

输入

底层输入缓冲区对象(EventBuffer)

产量

底层输出缓冲区对象(EventBuffer)

预定义的常量

EventBufferEvent::READING

在bufferevent的读取操作期间发生的事件。查看其他标志,了解它是哪个事件。

EventBufferEvent::WRITING

在bufferevent的写入操作期间发生的事件。查看其他标志,了解它是哪个事件。

EventBufferEvent::EOF

缓冲区事件得到文件结束指示。

EventBufferEvent::ERROR

在bufferevent操作期间发生错误。有关错误的更多信息,请调用EventUtil :: getLastSocketErrno()和/或EventUtil :: getLastSocketError()。

EventBufferEvent::TIMEOUTEventBufferEvent::CONNECTED

Finished a requested connection on the bufferevent.

EventBufferEvent::OPT_CLOSE_ON_FREE

当缓冲区事件被释放时,关闭底层传输。这将关闭底层套接字,释放底层缓冲区事件等。

EventBufferEvent::OPT_THREADSAFE

自动为bufferevent分配锁,以便在多个线程中使用它是安全的。

EventBufferEvent::OPT_DEFER_CALLBACKS

当这个标志被设置时,bufferevent延迟它的所有回调。请参阅»使用Libevent进行快速便携式无阻塞网络编程,延迟回调

EventBufferEvent::OPT_UNLOCK_CALLBACKS

默认情况下,当bufferevent设置为线程安全时,只要调用任何用户提供的回调,就会保持缓冲区事件的锁定。设置此选项使Libevent在调用回调时释放缓冲区事件的锁定。

EventBufferEvent::SSL_OPEN

SSL握手完成

EventBufferEvent::SSL_CONNECTING

SSL当前正在执行作为客户端的协商

EventBufferEvent::SSL_ACCEPTING

SSL当前正在作为服务器执行协商

目录

  • EventBufferEvent :: close - 关闭与当前缓冲区事件关联的文件描述符
  • EventBufferEvent :: connect - 将缓冲区事件的文件描述符连接到给定的地址或UNIX套接字
  • EventBufferEvent :: connectHost - 通过可选的异步DNS解析连接到主机名
  • EventBufferEvent :: __构造 - 构造EventBufferEvent对象
  • EventBufferEvent::createPair — Creates two buffer events connected to each other
  • EventBufferEvent::disable — Disable events read, write, or both on a buffer event.
  • EventBufferEvent::enable — Enable events read, write, or both on a buffer event.
  • EventBufferEvent::getDnsErrorString — Returns string describing the last failed DNS lookup attempt
  • EventBufferEvent::getEnabled — Returns bitmask of events currently enabled on the buffer event
  • EventBufferEvent::getInput — Returns underlying input buffer associated with current buffer event
  • EventBufferEvent::getOutput — Returns underlying output buffer associated with current buffer event
  • EventBufferEvent::readBuffer — Drains the entire contents of the input buffer and places them into buf
  • EventBufferEvent::setCallbacks — Assigns read, write and event(status) callbacks
  • EventBufferEvent::setPriority — Assign a priority to a bufferevent
  • EventBufferEvent::setTimeouts — Set the read and write timeout for a buffer event
  • EventBufferEvent::setWatermark — Adjusts read and/or write watermarks
  • EventBufferEvent::sslError — Returns most recent OpenSSL error reported on the buffer event
  • EventBufferEvent::sslFilter — Create a new SSL buffer event to send its data over another buffer event
  • EventBufferEvent::sslGetCipherInfo — Returns a textual description of the cipher.
  • EventBufferEvent::sslGetCipherName — Returns the current cipher name of the SSL connection.
  • EventBufferEvent::sslGetCipherVersion — Returns version of cipher used by current SSL connection.
  • EventBufferEvent::sslGetProtocol — Returns the name of the protocol used for current SSL connection.
  • EventBufferEvent::sslRenegotiate — Tells a bufferevent to begin SSL renegotiation.
  • EventBufferEvent::sslSocket — Creates a new SSL buffer event to send its data over an SSL on a socket
  • EventBufferEvent::write — Adds data to a buffer event's output buffer
  • EventBufferEvent::writeBuffer — Adds contents of the entire buffer to a buffer event's output buffer

← EventBuffer::write

EventBufferEvent::close →

代码语言:txt
复制
 © 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券