libevent源码bufferevent_socket_connect,bufferevent_socket_new


/**
   Launch a connect() attempt with a socket-based bufferevent.
  使用一个socket-based bufferevent来启动connect() When the connect succeeds, the eventcb will be invoked with BEV_EVENT_CONNECTED set.当连接成功,事件回调会被置为BEV_EVENT_CONNECTED并进行调用 If the bufferevent does not already have a socket set, we allocate a new socket here and make it nonblocking before we begin.
  在开始前,如果bufferevent没有配置套接字,将会在这里分配一个新的套接字,并设置为非阻塞的 If no address is provided, we assume that the socket is already connecting, and configure the bufferevent so that a BEV_EVENT_CONNECTED event will be yielded when it is done connecting.
  如果未提供地址,则假设套接字已处于连接中(进行时),并配置了bufferevent,这样当连接完成时,会产生一个BEV_EVENT_CONNECTED事件 @param bufev an existing bufferevent allocated with bufferevent_socket_new(). 通过bufferevetn_socket_new()分配的bufferevent @param addr the address we should connect to 将要连接的地址(服务端地址) @param socklen The length of the address 地址的长度 @return 0 on success, -1 on failure. 0成功,-1失败
*/

int bufferevent_socket_connect(struct bufferevent *, const struct sockaddr *, int);
/**
  Create a new socket bufferevent over an existing socket.
  基于一个已存在的套接字,创建一个新的socket bufferevent @param base the event base to associate with the new bufferevent. 和新bufferevent关联到一起的base @param fd the file descriptor from which data is read and written to. 数据将被读取和写入的描叙符 This file descriptor is not allowed to be a pipe(2). 这个文件描叙符不能是一个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().文件描叙符可以设置为-1,只要稍后用bufferevent_setfd或者bufferevent_socket_connect()来设置它 @param options Zero or more BEV_OPT_* flags 0或者其它的标识 @return a pointer to a newly allocated bufferevent struct, or NULL if an error occurred 一个指向新分配的bufferevent的指针,或者NULL(当有错误发生) @see bufferevent_free() */ struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, int options);

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM