Nasty problem with background fcopy from socket to stdout



Hello!

I'm trying to push data from a socket to stdout using a background fcopy.

I create a server socket with the procedure ("output"), that invokes the
background fcopy as soon as the there is an incoming connection. The fcopy
is supposed to call another procedure ("done"), when it finishes:

fconfigure stdout -buffering full -encoding binary -translation binary
....
proc done {conn db bytes {e {}}} {
global ${db}_done
if {$bytes == < 100 ||
[llength $e] > 0 && ![string match "*broken pipe* $e]} {
puts stderr "\tSome wrong with $db: processed $bytes bytes,\
got\n\t\t$e"
}
set ${db}_done 1
}

proc output {conn db sock ip cport} {
global P
fconfigure $sock -buffersize 65536 -buffering full \
-encoding binary -translation binary
puts stderr "Proceeding to [info command fcopy]"
fconfigure stdout -buffersize 65536
fcopy $sock stdout -command [list done $conn $db]
}

socket -server "output $conn $db" 0
....
vwait ${db}_done

The fcopy fails without setting any error message (!). According to
debugger, the failure happens in around tcl8.4.13/generic/tclIO.c:7710,
which reads:

if (inPtr != outPtr) {
if (nonBlocking != (writeFlags & CHANNEL_NONBLOCKING)) {
if (SetBlockMode(NULL, outPtr,
nonBlocking ? TCL_MODE_NONBLOCKING : TCL_MODE_BLOCKING)
!= TCL_OK) {
if (nonBlocking != (readFlags & CHANNEL_NONBLOCKING)) {
SetBlockMode(NULL, inPtr,
(readFlags & CHANNEL_NONBLOCKING)
? TCL_MODE_NONBLOCKING : TCL_MODE_BLOCKING);
return TCL_ERROR;
}
}
}
}

That first SetBlockMode() fails (without setting interp->result) and I get
back the rather undescriptive error :-(

What's going on? It was working fine, when I used the foreground fcopy, but
I want to be able to continue processing events, while the fcopy is in
progress... Thanks!

-mi
.



Relevant Pages

  • Re: "Streaming" binary files
    ... fcopy $fd stdout ... fconfigure stdout -translation binary ... be aware that fcopy has known bugs. ... IMO it should have higher priority for the Tcl developers, ...
    (comp.lang.tcl)
  • Re: "Streaming" binary files
    ... fconfigure $_fd -translation binary ... fcopy $_fd stdout ... If I replace it with [chan configure], ... Maybe I am doing something wrong, but it really looks like the fcopy ...
    (comp.lang.tcl)
  • Re: Nasty problem with background fcopy from socket to stdout
    ... I'm trying to push data from a socket to stdout using a background fcopy. ... I create a server socket with the procedure, ...
    (comp.lang.tcl)
  • Re: cat a binary file to stdout
    ... I am looking for a solution to cat the content ... fconfigure stdout -translation binary ... You could also use the -command option of fcopy if you need this ...
    (comp.lang.tcl)