Bonjour à tous,

Je recherche des informations sur le comportement concernant l'extrait de code ci-dessous :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
  const int        maxLength = 1;
  char             buffer[maxLength];
 
  while (TRUE == handle->running)
  {
    /* Initialize the fd_set structure and the greatest handle variable */
    FD_ZERO(&readfds);
    greatestHandle = -1;
    ...
    /* Add socket to the set */
    FD_SET(handle->sock, &readfds);
    greatestHandle = (handle->sock > greatestHandle) ? handle->sock : greatestHandle;
    /* Set up sleep time of select function to 50ms */
    tv.tv_sec = 0;
    tv.tv_usec = 50000;
    /* Wait for 50ms or an event */
    if (0 != select(greatestHandle + 1, &readfds, NULL, NULL, &tv))
    {
      ...
      /* Does the event come from UDP socket? */
      if (FD_ISSET(handle->sock, &readfds))
      {
        remoteLength = sizeof(struct sockaddr_in);
	length = recvfrom(handle->sock, buffer, maxLength, MSG_DONTWAIT, (struct sockaddr *)&handle->remote, &remoteLength);
        length = write(handle->inHandle, buffer, length);
      }
    }
  }
Tout fonctionne bien si le paquet fait moins de 10 caractères. Toutefois, je m'attendais à ce que la fonction select repositionne l'indicateur du socket quand il reste des caractères en réception (je reçois 24 caractères, je ne lit que 9 caractères d'où trois lectures et, malheureusement, la fonction recvfrom n'est appelé qu'une seule fois).

C'est peut-être normal. Qu'en pensez-vous ?

D'avance merci

Thoma