【发布时间】:2011-06-17 01:17:42
【问题描述】:
我正在使用 epoll 工作一个 linux 服务器。我有这段代码来读取缓冲区
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 是这样声明的
buf[BUF_SIZE]
这样声明的pushWork函数
pushWork(char *pdata){
push pdata to the thread pool's queue
}
首先,我认为 char *pdata = buf 有问题,因为它只是指向缓冲区,并且每当有新数据进入时,缓冲区都会被覆盖。所以我需要 memcpy 吗?
另外,在 c++ 中有没有其他好方法来处理这个问题?这段代码是一种 c 风格,我认为我有更好的方法在 c++ 中执行此操作。
【问题讨论】:
-
你到底想在这里实现什么?将数据读入缓冲区?
标签: c++ networking