Changeset 6011


Ignore:
Timestamp:
Feb 14, 2016 2:42:06 PM (7 years ago)
Author:
ldelgass
Message:

In VisViewer::SendBytes?, append to output buffer rather than clobbering buffer.
This allows SendBytes? to be called recursively. This can happen in the call to
tkwait in SendBytes? if an event handler calls SendBytes?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/visviewer.tcl

    r5725 r6011  
    7575    private method SendDebugCommand {}
    7676    private method SendHelper {}
    77     private method SendHelper.old {}
    7877    private method ServerDown {}
    7978    private method Shuffle { servers }
     
    334333    set _sid ""
    335334    set _buffer(in) ""
     335    set _buffer(out) ""
    336336    set _outbuf ""
    337337    set _cmdSeq 0
     
    421421
    422422#
    423 # SendHelper.old --
    424 #
    425 #   Helper routine called from a file event to send data when the
    426 #   connection is writable (i.e. not blocked).  Sends data in chunks of 8k
    427 #   (or less).  Sets magic variable _done($this) to indicate that we're
    428 #   either finished (success) or could not send bytes to the server
    429 #   (failure).
    430 #
    431 itcl::body Rappture::VisViewer::SendHelper.old {} {
    432     if { ![CheckConnection] } {
    433         return 0
    434     }
    435     set bytesLeft [string length $_buffer(out)]
    436     if { $bytesLeft > 0} {
    437         set chunk [string range $_buffer(out) 0 8095]
    438         set _buffer(out)  [string range $_buffer(out) 8096 end]
    439         incr bytesLeft -8096
    440         set code [catch {
    441             if { $bytesLeft > 0 } {
    442                 puts -nonewline $_sid $chunk
    443             } else {
    444                 puts $_sid $chunk
    445             }
    446         } err]
    447         if { $code != 0 } {
    448             puts stderr "error sending data to $_sid: $err"
    449             Disconnect
    450             set _done($this) 0;     # Failure
    451         }
    452     } else {
    453         set _done($this) 1;     # Success
    454     }
    455 }
    456 
    457 #
    458423# SendBytes --
    459424#
     
    470435    # before sending anything.
    471436    set _done($this) 1
    472     if {$_buffer(out) != ""} {
    473         puts stderr "ERROR: re-entered SendBytes: buffer=([string range $_buffer(out) 0 70]...)"
    474         puts stderr "New cmd $_cmdSeq: [string range $bytes 0 70]..."
    475     }
    476     set _buffer(out) $bytes
     437    if { $_debug && [string bytelength $_buffer(out)] > 0 } {
     438        puts stderr "SendBytes: appending to output buffer"
     439    }
     440    # Append to the buffer, since we may have been called recursively
     441    append _buffer(out) $bytes
    477442    # There's problem when the user is interacting with the GUI at the
    478443    # same time we're trying to write to the server.  Don't want to
     
    481446    # mouse movements aren't received.
    482447    if {$_blockOnWrite} {
    483         # Let's try this approach: allow a write to block so we don't
    484         # re-enter SendBytes
     448        # Allow a write to block.  In this case we won't re-enter SendBytes.
    485449        SendHelper
    486450    } else {
    487         # This can cause us to re-enter SendBytes during the tkwait, which
    488         # is not safe because the _buffer will be clobbered
     451        # NOTE: This can cause us to re-enter SendBytes during the tkwait.
     452        # For this reason, we append to the buffer in the code above.
    489453        if { [info exists itk_component(main)] } {
    490454            blt::busy hold $itk_component(main) -cursor ""
Note: See TracChangeset for help on using the changeset viewer.