Skip to content
Tcl Source Code History Of Ticket 218435
Login

History Of Ticket 218435

Artifacts Associated With Ticket 218435

  1. Ticket change [4a6734106c] (rid 126529) by nobody on 2000-10-26 00:57:34:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 6156 Bug
      Version: 8.3.2
      SubmitDate: '2000-08-23'
      LastModified: '2000-08-25'
      Severity: SER
      Status: Closed
      Submitter: techsupp
      ChangedBy: ericm
      OS: Windows 95
      FixedDate: '2000-10-25'
      ClosedDate: '2000-08-25'
      
      
      Name:
      Brent Iwanoczko
      
      Comments:
      Help, ASAP :) Theres a emulator thats waiting to be built, failure here
          for any reason means we cant use TK/Tcl, and the intention to purchase a
      
          TCLPRO support license will be null and void.
      
      ReproducibleScript:
      Try the following 2 commands in your console.
      
      EXPECTED RESULT - When you put the below output down a socket, the filevent on the client will get called once, and a gets on the socket will get 32 bytes of data.
      set x [binary format Ia8IIIcccB8cxxx 124 WxYz0000 967004765 967004765 32 0 0 13 01010101 1]
      
      UNEXPECTED RESULT - When you put the below output down a socket, the filevent on the client will get called twice, the first time getting 28 bytes, the second time getting 3 bytes. So not only is the gets split, you also lose a byte.
      set x [binary format Ia8IIIcccB8cxxx 124 WxYz0000 967002665 967002665 32 0 0 8 01010101 10]
      This will display a binary string that appears to be split over 2 lines, altho the length registers as 32 bytes as expected.
      
      The sockets in all cases are fconfigure -translation binary -encoding binary
      
      As it stands, the binary format command is not able to be used reliably, as every now and then with different data combinations, you get unexpected results.
      
      ObservedBehavior:
      Try the following 2 commands in your console.
      
      EXPECTED RESULT - When you put the below output down a socket, the filevent on the client will get called once, and a gets on the socket will get 32 bytes of data.
      set x [binary format Ia8IIIcccB8cxxx 124 WxYz0000 967004765 967004765 32 0 0 13 01010101 1]
      
      UNEXPECTED RESULT - When you put the below output down a socket, the filevent on the client will get called twice, the first time getting 28 bytes, the second time getting 3 bytes. So not only is the gets split, you also lose a byte.
      set x [binary format Ia8IIIcccB8cxxx 124 WxYz0000 967002665 967002665 32 0 0 8 01010101 10]
      This will display a binary string that appears to be split over 2 lines, altho the length registers as 32 bytes.
      
      The sockets in all cases are fconfigure -translation binary -encoding binary
      
      As it stands, the binary format command is not able to be used reliably, as every now and then with different data combinations, you get unexpected results.
      
      DesiredBehavior:
      I expect to see the binary format command to always construct a string that doesnt have some kind of line break imbedded in it. So that a gets on
      a socket gets all the data sent with the puts command, not bits of it.
      
      
      
      From comp.lang.tcl (thanks to Dan Kuchler):
      
      If you use 'gets' to read from a socket that has binary data placed
      on it, and one of the characters in the data (when interpretted as
      a string) is an end-of-line character (character codes 10 and 13
      I believe) then that character will be swallowed as an end-of-line
      character, which is what you are observing.  The solution is to use
      'read' which doesn't look for end-of-line.
      
      On server (process 1):
      ---------------------------------------------------------
      set server  [socket -server [list foo] 9000]
      
      proc foo {channel clientaddr clientport} {
          fconfigure $channel -translation binary
          fileevent $channel readable [list bar $channel]
      }
      
      proc bar {channel} {
          if {[eof $channel]} {
              close $channel
          } else {
              set res [read $channel]
              puts "string length [string length $res]"
              binary scan $res c* result
              puts "number of bytes: [llength [split $result]]"
          }
          return
      }
      vwait forever
      ---------------------------------------------------------
      On the client (process 2):
      ---------------------------------------------------------
      
      # First try the string from your 'expected result' section:
      
      set client [socket localhost 9000]
      fconfigure $client -translation binary
      set x [binary format Ia8IIIcccB8cxxx 124 WxYz0000 967002665 967002665
      32 0 0 8 01010101 10]
      puts -nonewline $client $x
      flush $client
      close $client
      
      # Then try the string from your 'unexpected result' section:
      
      set client [socket localhost 9000]
      fconfigure $client -translation binary
      set x [binary format Ia8IIIcccB8cxxx 124 WxYz0000 967002665 967002665
      32 0 0 8 01010101 10]
      puts -nonewline $client $x
      flush $client
      close $client
      --------------------------------------------------------
      output:
      ---------------------------------------------------------
      string length 32
      number of bytes: 32
      string length 32
      number of bytes: 32
      
      
      When I change the bar procedure to:
      
      proc bar {channel} {
          if {[eof $channel]} {
              close $channel
          } else {
              gets $channel res
              puts "string length [string length $res]"
              binary scan $res c* result
              puts "number of bytes: [llength [split $result]]"
          }
          return
      }
      
      And retry I get:
      
      string length 28
      number of bytes: 28
      string length 3
      number of bytes: 3
      string length 28
      number of bytes: 28
      string length 3
      
      This is because (according to the man page):
      
      
      NAME
             gets - Read a line from a channel
      
      SYNOPSIS
             gets channelId ?varName?
      _________________________________________________________________
      
      
      DESCRIPTION
      
      This  command  reads the next line from channelId, returns
      everything in the line up to (but not including) the  end-
      of-line character(s), and discards the end-of-line characĀ­
      ter(s).
      
      
      --
      
         Eric Melski                            The Other Tcl Guy
         ericm at ajubasolutions.com            Ajuba Solutions
       
      -- 08/25/2000 ericm
      
    4. foundin initialized to: "obsolete: 8.3.2"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "69. Other"
    10. title initialized to: "Binary format errors"
    11. type initialized to: "Bug"
  2. Ticket change [8c6d7f8a03] (rid 127744) by welch on 2000-10-26 08:22:15:

    1. closedate changed to: "2000-10-26T01:22:15"
    2. closer changed to: "welch"
    3. priority changed to: "2"
    4. resolution changed to: "Fixed"
    5. status changed to: "Closed"
  3. Ticket change [6d93b7ae6e] (rid 128730) by dgp on 2001-04-20 02:40:46:

    1. closedate changed to: "2001-04-19T19:40:46"
    2. closer changed to: "dgp"
    3. subsystem changed to: "24. Channel Commands"