Let’s take an example of my doubt with this server code:
/* 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;
}
/* other code */
and this client code:
/* 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 */
My question is: if the server is on a x86 machine (little endian) and the client is on a x64 machine (little endian) could the pointer different size (4-8 byte) lead to a problem?
If yes, how can i solve?
No it won’t be a problem, as you actually don’t send pointers over the socket, just a stream of bytes. The only problem I see is if the file is a binary data and have 64-bit integers in it, and the receiving platform is 32 bit without support for 64 bit integers (e.g.
long long), however, that is very unlikely unless you are receiving on an embedded system.PS.
In your receiving loop you check for read errors, but not for the socket to be closed by the other end (when
readreturns0.)