让我们以下面的服务器代码为例来说明我的疑问:
/* some code */
void *filebuffer = NULL;
/* some other code */
for (size_to_send = fsize; size_to_send > 0; ){
rc = sendfile(f_sockd, fd, &offset, size_to_send);
if (rc <= 0){
perror("sendfile");
onexit(f_sockd, m_sockd, fd, 3);
}
size_to_send -= rc;
}/*其他代码*/
和下面的客户端代码:
/* some code */
void *filebuffer;
/*some other code */
for(size_to_receive = fsize; size_to_receive > 0;){
nread = read(f_sockd, filebuffer, size_to_receive);
if(nread < 0){
perror("read error on retr");
onexit(f_sockd, 0, 0, 1);
}
if(write(fd, filebuffer, nread) != nread){
perror("write error on retr");
onexit(f_sockd, 0, 0, 1);
}
size_to_receive -= nread;
}
/* other code */我的问题是:如果服务器在x86机器上(小端),而客户端在x64机器上(小端),指针大小不同(4-8字节)会导致问题吗?
如果是,我如何解决?
发布于 2012-09-03 14:07:48
不,这不是问题,因为您实际上不会通过套接字发送指针,而只是一个字节流。我看到的唯一问题是,如果文件是二进制数据并且其中包含64位整数,而接收平台是32位而不支持64位整数(例如long long),那么这是非常不可能的,除非您是在嵌入式系统上接收。
PS。在接收循环中,您将检查读取错误,但不会检查要由另一端关闭的套接字(当read返回0时)。
https://stackoverflow.com/questions/12242739
复制相似问题