Artifacts Associated With Ticket 218435
Ticket change [4a6734106c] (rid 126529) by nobody on 2000-10-26 00:57:34:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- 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 - foundin initialized to: "obsolete: 8.3.2"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "69. Other"
- title initialized to: "Binary format errors"
- type initialized to: "Bug"
Ticket change [8c6d7f8a03] (rid 127744) by welch on 2000-10-26 08:22:15:
- closedate changed to: "2000-10-26T01:22:15"
- closer changed to: "welch"
- priority changed to: "2"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [6d93b7ae6e] (rid 128730) by dgp on 2001-04-20 02:40:46:
- closedate changed to: "2001-04-19T19:40:46"
- closer changed to: "dgp"
- subsystem changed to: "24. Channel Commands"