- FD_ZERO(&fds);
- FD_SET(s, &fds);
- tv.tv_sec = 0; /* wait, but only for 10us */
- tv.tv_usec = 10;
-
- generic[0] = 0x00;
-
- readgood = 0;
- i = 0;
- j = 0;
- /* read first 6 bytes (the FLAP header only) off the socket */
- while ( (select(s+1, &fds, NULL, NULL, &tv) == 1) && (i < 6))
- {
- if ((err = Read(s, &(generic[i]), 1)) < 0)
- {
- /* error is probably not recoverable...(must be a pessimistic day) */
- aim_conn_close(conn);
- return err;
- }
-
- if (readgood == 0)
- {
- if (generic[i] == 0x2a)
- {
- readgood = 1;
-#if debug > 1
- printf("%x ", generic[i]);
- fflush(stdout);
-#endif
- i++;
- }
- else
- {
-#if debug > 1
- printf("skipping 0x%d ", generic[i]);
- fflush(stdout);
-#endif
- j++;
- }
- }
- else
- {
-#if debug > 1
- printf("%x ", generic[i]);
-#endif
- i++;
- }
- FD_ZERO(&fds);
- FD_SET(s, &fds);
- tv.tv_sec= 2;
- tv.tv_usec= 2;
- }
-
- if (generic[0] != 0x2a)
- {
- /* this really shouldn't happen, since the main loop
- select() should protect us from entering this function
- without data waiting */
- printf("Bad incoming data!");
- return -1;
- }