[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] unsend data in output buffer when close connection



 
I have used bufferevent to send data to socket
the application use variable length message, the first 4 bytes in message is the length
 
all thing is OK but for socket reconnect
 
if the socket is closed by peer and my app reconnect
peer may receive the wrong msg, the message length is  wrong
 
it seems the unsent data in bufferevent's output buffer will be send when the socket reconnect
but the message boundary is broken in output buffer
 
I guess it is because when I write message use bufferevent_write, one message is splited into two chunks in output buffer
one chunk is send to peer before socket closed
and the  next chunk is sent to peer after socket reconnect, so the message is broken
 
if it is true, can I get the data from output buffer and find the next message begin in data
so I can  discard the broken message and send the message follow it
 
but I find I can't get the data from output buffer, the evbuffer_copyout function return -1
 
and I can't find the function to clear the output buffer to discard all message in buffer
 
the only thing I can do is to free the bufferevent and create a new bufferevent when reconnect socket
 
is it the right way to do such thing?
 
Thank you!
 
2015-01-16

slump