/** 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);