Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: aa4efac96d6e094e0b5acaf506af6dbbf1b61fbc
Ticket: 10dc6daa375d45051a3c6064cbc1b32686bc1745
Tcl_Gets() fails to read non-blocking socket
User & Date: anonymous on 2014-10-15 19:15:05
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    * Ralf Fassel <[email protected]>
    | * Don Porter <[email protected]>
    | | On 10/13/2014 08:32 AM, Ralf Fassel wrote:
    | | > Using Tcl_Read on a non-blocking socket, we get different return values
    | | > for a read with no data available in 8.5.15 vs 8.5.16:
    | >
    | | ...
    | >
    | | > Is this change in behaviour and return values documented somewhere?
    | >
    | | This serious bug came in with Tcl 8.5.16 (and 8.6.2).
    | >
    | |   http://core.tcl.tk/tcl/info/ed29c4da21
    | >
    | | Already fixed for 8.5.17 (and 8.6.3).  Pull from dev branches if you
    | | need right away, or keep eyes open for the next Release Candidates.
    >
    | We still have an issue with the code in Tcl+Source+Code-59a0067f32.tar.gz
    | (obtained from https://core.tcl.tk/tcl/timeline?r=core-8-5-17-rc by
    | clicking on the upmost Leaf [59a0067f32] and downloading the tarball
    | from the resulting page).
    --<snip-snip>--
    | I will try to come up with a little c program...
    
    The following program shows the problem when linked against 8.5.17 and
    no problem when linked against 8.5.15.
    
    -----------------------------------------------
    /* t.c */
    /* input: yes | netcat 65422 */
    #include <stdio.h>
    #include <tcl.h>
    #include <unistd.h>
    
    int main(int argc, char *argv[]) {
    
      Tcl_FindExecutable(argv[0]);
      Tcl_DString line;
      Tcl_DStringInit(&line);
      int nothing=0;
    
      Tcl_Channel device = Tcl_OpenTcpClient(0, 65422, "localhost", 0, 0, 0);
      if (0 == device) {
        perror("cant open port");
        return 1;
      }
    
      if (Tcl_SetChannelOption(0, device, "-blocking", "false") != TCL_OK
          || Tcl_SetChannelOption(0, device, "-buffersize", "1048576") != TCL_OK
          || Tcl_SetChannelOption(0, device, "-translation", "binary") != TCL_OK
          || Tcl_SetChannelOption(0, device, "-buffering", "none") != TCL_OK) {
        fprintf(stderr, "cant set stdin channel options\n");
        return 1;
      }
    
      while (1) {
        Tcl_DStringSetLength(&line, 0);
        int num = Tcl_Gets(device, &line);
        if (num > 0 || nothing > 1000000) {
          printf("got %d chars with %d nothings\n", num, nothing);
          nothing = 0;
        } else {
          nothing++;
        }
      }
      return 0;
    }
    
    /* End of file */
    
    -----------------------------------------------
    
    The socket is provided by
       yes | netcat -l 65422
    but probably anything which sends masses of data will probably do.
    
    When linked against 8.5.17, an initial read succeeds, but then nothing
        sh-4.2$ gcc -I PATH-TO-TCL-HEADERS -L . -o t t.c -ltcl8.5.17
        sh-4.2$ env LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./t
        got 6 chars with 3314 nothings
        got -1 chars with 1000001 nothings
        got -1 chars with 1000001 nothings
        got -1 chars with 1000001 nothings
        got -1 chars with 1000001 nothings
        got -1 chars with 1000001 nothings
        got -1 chars with 1000001 nothings
        got -1 chars with 1000001 nothings
    
    Linked against 8.5.15:
        sh-4.2$ gcc -I $SIXXBASE/tcltk/linux/include/ -L . -o t t.c -ltcl8.5.15
        sh-4.2$ env LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./t
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        got 1 chars with 0 nothings
        ...
    
    Note that TCL_STDIN instead of a real socket did not show the problem.
    
  5. foundin changed to: "8.5.16 8.5.17rc"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "1d3c95db24e116878d6afed7cf890a89a0effe62"
  10. resolution changed to: "None"
  11. severity changed to: "Severe"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "25. Channel System"
  15. title changed to: "Tcl_Gets() fails to read non-blocking socket"
  16. type changed to: "Bug"