Browse Source

Workaround for Solaris libc

The Solaris libc has some issues with alternating input and output
on sockets passed to fdopen(). Apparently there is a shared buffer
which has to be emptied, either by fseek() or fflush(), whenever
the direction of the data flow changes.
tags/1.2
Timo Röhling 10 years ago
parent
commit
859796b126
1 changed files with 4 additions and 0 deletions
  1. 4
    0
      postsrsd.c

+ 4
- 0
postsrsd.c View File

459
           if (poll(&fds[2], 1, timeout * 1000) <= 0) return EXIT_FAILURE;
459
           if (poll(&fds[2], 1, timeout * 1000) <= 0) return EXIT_FAILURE;
460
           line = fgets(linebuf, sizeof(linebuf), fp);
460
           line = fgets(linebuf, sizeof(linebuf), fp);
461
           while (line) {
461
           while (line) {
462
+            fseek (fp, 0, SEEK_CUR); /* Workaround for Solaris */
462
             char* token;
463
             char* token;
463
             token = strtok(line, " \r\n");
464
             token = strtok(line, " \r\n");
464
             if (token == NULL || strcmp(token, "get") != 0) {
465
             if (token == NULL || strcmp(token, "get") != 0) {
465
               fprintf (fp, "500 Invalid request\n");
466
               fprintf (fp, "500 Invalid request\n");
467
+              fflush (fp);
466
               return EXIT_FAILURE;
468
               return EXIT_FAILURE;
467
             }
469
             }
468
             token = strtok(NULL, "\r\n");
470
             token = strtok(NULL, "\r\n");
469
             if (!token) {
471
             if (!token) {
470
               fprintf (fp, "500 Invalid request\n");
472
               fprintf (fp, "500 Invalid request\n");
473
+              fflush (fp);
471
               return EXIT_FAILURE;
474
               return EXIT_FAILURE;
472
             }
475
             }
473
             key = url_decode(keybuf, sizeof(keybuf), token);
476
             key = url_decode(keybuf, sizeof(keybuf), token);
474
             if (!key) break;
477
             if (!key) break;
475
             handler[i](srs, fp, key, domain, excludes);
478
             handler[i](srs, fp, key, domain, excludes);
476
             if (poll(&fds[2], 1, timeout * 1000) <= 0) break;
479
             if (poll(&fds[2], 1, timeout * 1000) <= 0) break;
480
+            fflush (fp);
477
             line = fgets(linebuf, sizeof(linebuf), fp);
481
             line = fgets(linebuf, sizeof(linebuf), fp);
478
           }
482
           }
479
           fclose (fp);
483
           fclose (fp);

Loading…
Cancel
Save