I am working a linux server using epoll. I have this code to read buffer
int str_len = read(m_events[i].data.fd, buf, BUF_SIZE);
if (str_len == 0) {
if (!removeClient(m_events[i].data.fd))
break;
close(m_events[i].data.fd);
} else {
char *pdata = buf;
pushWork(pdata);
}
buf is declared like this
buf[BUF_SIZE]
pushWork function declared like this
pushWork(char *pdata){
push pdata to the thread pool's queue
}
Firt of all, I think char *pdata = buf has a problem since it just points to the buffer and the buffer will be overriden whenever a new data comes in. So do I need to memcpy?
Also, is there any other nice way to handle this in c++ ? This code is kind of c style I think I have a better way to do this in c++.