le process a l'autre bout de la socket recoit bien ce que le send lui envoie. et une trace sniffer le confirme.
la longueur du buffer correspond bien a l'argument length (meme plus grand en fin de boucle --> voir code). et 8192 doit tenir dans size_t !
voila le code... je l'ai un peu elague car il y a des portions optionnelles que je n'utilises pas dans le test dont je parle en debut de ce thread...
void client_task (int len)
{
int sockfd;
struct sockaddr_in srv;
struct sockaddr_in where;
int where_len;
char *buf;
int i;
uint64_t total_len = 0;
if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
perror ("client_task(): socket()");
exit (errno);
}
memset (&srv, 0, sizeof (srv));
srv.sin_family = AF_INET;
srv.sin_addr.s_addr = server_addr.s_addr;
srv.sin_port = htons (mtcp_port);
if (connect (sockfd, (struct sockaddr *) &srv, sizeof (srv)) < 0) {
perror ("client_task(): connect()");
close (sockfd);
exit (errno);
}
where_len = sizeof (where);
if (getsockname (sockfd,
(struct sockaddr *) &where,
(socklen_t *) &where_len) < 0) {
perror ("client_task(): getsockname()");
exit (errno);
}
printf ("[%4d] Local %s port %d connected to remote %s port %d\n",
sockfd,
inet_ntoa (where.sin_addr),
ntohs (where.sin_port),
inet_ntoa (srv.sin_addr),
ntohs (srv.sin_port));
buf = (char *) malloc (buf_len);
memset (buf, 0, buf_len);
for (i = 0; i < len; i+= buf_len) {
int sz;
sz = MIN (buf_len, (len - i));
if (send (sockfd, buf, sz, 0) != sz) {
perror ("client_task(): send()");
close (sockfd);
free (buf);
exit (errno);
} else {
total_len += sz;
}
}
[...]
[^] # Re: Documentation incorrecte
Posté par donaldo78 . En réponse au message Appel systeme send (). Évalué à 1.
void client_task (int len) { int sockfd; struct sockaddr_in srv; struct sockaddr_in where; int where_len; char *buf; int i; uint64_t total_len = 0; if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) { perror ("client_task(): socket()"); exit (errno); } memset (&srv, 0, sizeof (srv)); srv.sin_family = AF_INET; srv.sin_addr.s_addr = server_addr.s_addr; srv.sin_port = htons (mtcp_port); if (connect (sockfd, (struct sockaddr *) &srv, sizeof (srv)) < 0) { perror ("client_task(): connect()"); close (sockfd); exit (errno); } where_len = sizeof (where); if (getsockname (sockfd, (struct sockaddr *) &where, (socklen_t *) &where_len) < 0) { perror ("client_task(): getsockname()"); exit (errno); } printf ("[%4d] Local %s port %d connected to remote %s port %d\n", sockfd, inet_ntoa (where.sin_addr), ntohs (where.sin_port), inet_ntoa (srv.sin_addr), ntohs (srv.sin_port)); buf = (char *) malloc (buf_len); memset (buf, 0, buf_len); for (i = 0; i < len; i+= buf_len) { int sz; sz = MIN (buf_len, (len - i)); if (send (sockfd, buf, sz, 0) != sz) { perror ("client_task(): send()"); close (sockfd); free (buf); exit (errno); } else { total_len += sz; } } [...]