1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| int sendPaquet(int sock, char *paquet, int longueurPaquet)
{
int nbRecu = 0;
int retval;
fd_set readfds;
fd_set writefds;
fd_set exceptfds;
struct timeval timeout;
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
FD_SET(sock, &readfds);
FD_SET(sock, &writefds);
FD_SET(sock, &exceptfds);
timeout.tv_sec = TIMEOUT;
timeout.tv_sec = 10;
timeout.tv_usec = 0;
retval = select(sock+1, &readfds, &writefds, &exceptfds, &timeout);
if (FD_ISSET(sock,&exceptfds)) {
printf("sendPaquet ERREUR 1\n");
return -1;
}
if (FD_ISSET(sock,&writefds)) {
printf("avant send 2\n");
nbRecu = send(sock, paquet, longueurPaquet, 0);
printf("sendPaquet lg=%d send=%d\n",longueurPaquet,nbRecu);
}
else {
printf("sendPaquet ERREUR 2 : retval=%d\n",retval);
return -1;
}
} |
Partager