socket behavior is implementation dependent. In general, when you send (), there is no guarantee how many bytes will be loaded into the socket. Because the kernel controls this, it can be any number, usually in the range of 1500 or less. So, you need to check the return code () and keep pushing the data into the socket until you are done. This example assumes that you have already set the socket to non-blocking with:
fcntl(s, F_SETFL, O_NONBLOCK); int sendall(int s, char *buf, int *len) { int total = 0; int bytesleft = *len; int n=0; int retries=0; struct timespec tp={0,500}; while(total < *len) { n = send(s, buf+total, bytesleft, 0); if (n == -1) { } total += n; bytesleft -= n; }
To answer your question - there are no restrictions; you simply cannot send all your data with a single call to send ().
source share