【发布时间】:2013-04-19 22:31:55
【问题描述】:
在接收整数数组时,需要检查接收数据的字节数。 比如接收长度为100的整数数组时:
int count = 0;
int msg[100];
while(count < 100 * sizeof(int)){
count += read(fd, msg + count / sizeof(int), 100 * sizeof(int) - count);
}
这是正确的方法吗? read() 会返回一个不是 sizeof(int) 倍数的值吗? 如果这不正确,那么接收整数数组的正确方法是什么?
【问题讨论】: