Ugh, you don't need this wrapper, since evbuffer_get_length() will use bufferevent's lock automatically.
bufferevent_lock(bev_) and bufferevent_unlock(bev_) should not be used????
How about bufferevent_write()???
// Add data to write buff
bool Connection::AddToWriteBuffer(char *buffer, int len) {
//status_ = SENDING;
/*
* Locking the bufferevent with this function will
* lock its associated evbuffersas well
*/
// bufferevent_lock(bev_);
// struct evbuffer *output = bufferevent_get_output(bev_);
// int re = evbuffer_add(output, buffer, len);
// bufferevent_unlock(bev_);
bufferevent_lock(bev_);
int re = bufferevent_write(bev_, buffer, len);
bufferevent_unlock(bev_);
if (re == 0) {
return true;
} else {
return false;
}
}
On 03/20/2016 10:57 AM, Azat Khuzhin wrote:
On Sun, Mar 20, 2016 at 10:36:02AM -0400, Michael wrote:Thanks Azat, I got the problem. It is the lock and unlock. In my code I return before unlock (as follows). And an interesting thing is when I call bufferevent_lock(bev_) again it doesn't block and can return. It seems theBecause it uses recursive locking.blocking happens inside libevent. So I take a long time to find it out. Thanks! // Get the lengh a write buf int Connection::GetWriteBufferLen() { /* * Locking the bufferevent with this function will * lock its associated evbuffersas well */ bufferevent_lock(bev_); struct evbuffer *output = bufferevent_get_output(bev_); return evbuffer_get_length(output); bufferevent_unlock(bev_); }Ugh, you don't need this wrapper, since evbuffer_get_length() will use bufferevent's lock automatically. Cheers, Azat. *********************************************************************** To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with unsubscribe libevent-users in the body.
*********************************************************************** To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with unsubscribe libevent-users in the body.