On Thursday 11 September 2003 16:35, you wrote:
>
> I've prepared a draft of the Tcl API Reference. We need information on the
> new API calls. I've left place holders for the info, with new APIs
> highlighted in blue. If you're familiar with the new calls, send me your
> input so we can start filling in those blanks.

Hi Daniel !

Please add this (after proof-reading, of course) to the "ns_chan" command.
Cheers,
Zoran
-----------------------------

ns_chan   Sharing Tcl channels between threads and interpreters

Syntax:

    ns_chan create channel name
    ns_chan get name
    ns_chan put name
    ns_chan cleanup ?-shared?
    ns_chan list ?-shared?

Description:

    The "ns_chan" family of commands allows you to transfer ownership of
    Tcl channel(s) between threads and Tcl interpreters in the AOLserver
    process.
    The AOLserver maintains several internal tables to implement the
    channel-transfer capability. Each virtual server maintains a private
    table of shared Tcl channels. Those are not attached to any thread.
    Each Tcl interpreter maintains a table of currently attached shared
    channels. Consequently, a shared channel may be in the per-virtual-server
    private table *or* in the interpreter private table but not both.
    Furthermore, each shared channel is named. i.e. it bears an user-given
    name used to track the channel handle in above tables.
    By using the ns_chan commands, described below, one can create shared
    Tcl channels and move them back and forth between the current Tcl
    interpreter and per-virtual-server private table.


    "ns_chan create" takes an existing Tcl "channel", created
    by an Tcl or AOLserver command like "open", "ns_sockopen" or alike,
    plugs this channel out of the current interpreter and stores it under
    the "name" in the per-virtual-server private table. Any further attempt
    to use the "channel" from the current interpreter will fail, i.e. result
    in the Tcl error being thrown.
    On success, command will return empty string.
    The command will throw error if the "channel" cannot be found in the
    current Tcl interpreter or if there is already an entry with the same
    "name" in the per-virtual-server private table.


    "ns_chan get" retrieves a channel from the per-virtual-server private
    table and plugs it in into the current interpreter.
    On success, the command will return the handle of the channel. This
    handle can be used in any regular Tcl or AOLserver command operating
    on an Tcl channel, like "puts", "read", "fconfigure", etc.
    The command will throw error if the channel cannot be pluged in into
    the current interpreter or if the entry "name" could not be found in
    the per-virtual-server private table.


    "ns_chan put" does the reverse of the "ns_chan get" command, by
    plugging out the named channel out of the current interpreter and
    storing it in the per-virtual-server private table. Any further attempt
    to use the named channel from the current interpreter will fail, i.e.
    result in the Tcl error being thrown.
    On success, command will return empty string.
    The command will throw error if the named channel was never attached
    to the current interpreter by some previous "ns_chan get" command or
    if the entry "name" is already found in the per-virtual-server private table.


    "ns_chan cleanup" closes all shared channels found in the per-virtual-server
    private table or current Tcl interpreter table, depending on the "-shared"
    flag.
    If the "-shared" flag is not given on the command line the command will close
    all channels from the current interpreter which were attached to it by the
    "ns_chan get" command.
    If the "-shared" flag is given on the command line the command will close
    all channels from the per-virtual-server private table, i.e. all those
    which are currently not attached in any Tcl interpreter/thread.


    "ns_chan list" reports all shared channels found in the per-virtual-server
    private table or current Tcl interpreter, depending on the "-shared" flag.
    If the "-shared" flag is not given on the command line the command will
    report all channels from the current interpreter which were attached to it
    by the "ns_chan get" command.
    If the "-shared" flag is given on the command line the command will report
    all channels from the per-virtual-server private table, i.e. all those
    which are currently not attached in any Tcl interpreter/thread.


    Examples:

    #
    # THREAD-1: Create a shared channel
    #
    ns_chan create [open /some/file1.txt] mychan1
    ns_chan create [open /some/file2.txt] mychan2

    #
    # THREAD-2: Use the shared channel "mychan1"
    #
    set chan [ns_chan get mychan1]
    puts $chan "Hi, I'm thread [ns_thread getid]"

    #
    # THREAD-2: List all shared channels in the per-virtual-server table
    #
    ns_chan list -shared
    mychan2

    #
    # THREAD-2: List all attached shared channels in the current interpreter
    #
    ns_chan list
    mychan1

    #
    # THREAD-2: Return the attached channel back to the shared pool
    #
    ns_chan put mychan1

    #
    # THREAD-2: List all shared channels in the per-virtual-server table
    #
    ns_chan list -shared
    mychan2 mychan1

    #
    # THREAD-2: Cleanup all shared channels
    #
    ns_chan cleanup -shared
















>
> --
> AOLserver - http://www.aolserver.com/
>
> To Remove yourself from this list, simply send an email to
> <[EMAIL PROTECTED]> with the body of "SIGNOFF AOLSERVER" in the
> email message. You can leave the Subject: field of your email blank.


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of 
your email blank.

Reply via email to