I have a libev write callback function, which checks for pending data to be sent to client. The pending data buffer looks like
struct PendingData{
unsigned short data_size;
char data[4096];
};
typedef std::list<PendingData*> PendingBuf;
class Client{
private:
int sock;
PendingBuf data_list;
public:
ev::io cl_io;
void write_cb(ev::io &watcher, int events);
};
and the callback function checks if there is any data in the container in the following manner:
void Client::write_cb(ev::io &watcher, int events){
PendingData* pd = NULL;
int ires = 0;
if(!data_list.empty()){
pd = data_list.front();
ires = send(sock, pd->data, pd->data_size, 0);
if(ires == pd->data_size){
delete pd;
data_list.pop_front();
return;
}
// .... additional checking here
}
}
the program crashes with Segmentation fault on
if(!data_list.empty())
and sometimes on
pd = data_list.front();
in second case the empty() returnes false, but debugger shows, that list has no data members
it runs in separate thread (buffer is read and written from the same thread) I also tried to move this to the main thread without starting any additional threads at all, but with the same effect.
OS is Ubuntu 12.04, compiler is g++ 4.6 i also have c++0x enabled in my project