【无标题】

本文详细介绍了如何使用bufferevent_socket_new()函数创建基于现有socket的事件驱动程序,包括参数解析、功能概述,并提到了与evhttp_connection_base_bufferevent_new()的对比。重点讲解了事件基础、文件描述符设置和可选选项。

bufferevent_socket_new()

EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_socket_new(struct event_base * base,
evutil_socket_tfd,
int options 
)

Create a new socket bufferevent over an existing socket.

Parameters

basethe event base to associate with the new bufferevent.
fdthe file descriptor from which data is read and written to. This file descriptor is not allowed to be a pipe(2). It is safe to set the fd to -1, so long as you later set it with bufferevent_setfd or bufferevent_socket_connect().
optionsZero or more BEV_OPT_* flags

Returns

a pointer to a newly allocated bufferevent struct, or NULL if an error occurred

See also

bufferevent_free()

evhttp_connection_base_bufferevent_new()

EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_connection_base_bufferevent_new(struct event_base * base,
struct evdns_base * dnsbase,
struct bufferevent * bev,
const char * address,
ev_uint16_t port 
)

Create and return a connection object that can be used to for making HTTP requests.

The connection object tries to resolve address and establish the connection when it is given an http request object.

Connection also has default timeouts for the following events:

  • connect HTTP_CONNECT_TIMEOUT, which is 45 seconds
  • read HTTP_READ_TIMEOUT which is 50 seconds
  • write HTTP_WRITE_TIMEOUT, which is 50 seconds

Parameters

basethe event_base to use for handling the connection
dnsbasethe dns_base to use for resolving host names; if not specified host name resolution will block.
beva bufferevent to use for connecting to the server; if NULL, a socket-based bufferevent will be created. This bufferevent will be freed when the connection closes. It must have no fd set on it.
addressthe address to which to connect
portthe port to connect to

Returns

an evhttp_connection object that can be used for making requests or NULL on error

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值