Skip to content

jdc8/tclfcgi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fcgi - A Tcl wrapper for the FastCGI library
Generated from file '' by tcllib/doctools with format 'text'
fcgi(n) 1.0.0  "A Tcl wrapper for the FastCGI library"

NAME
====

fcgi - fcgi Package Reference

SYNOPSIS
========

package require Tcl 8.6
package require critcl ?3?

fcgi Init
fcgi OpenSocket path ?backlog?
fcgi CloseSocket socket
fcgi InitRequest socket ?flags?
fcgi Free request close
fcgi Accept_r request
fcgi Finish_r request
fcgi GetParam request ?name?
fcgi PutStr request stream string
fcgi GetStr request stream n
fcgi SetExitStatus request stream status

DESCRIPTION
===========

The _fcgi_ package is a wrapper for the _FastCGI library_
<URL:http://www.fastcgi.com>. The wrapper is based on version 2.4.1 of the
FastCGI library. It is written using critcl 3.

The package tries to stay close to the C calls in the FastCGI library
application server API. Consult the _FastCGI library documentations_
<URL:http://www.fastcgi.com/drupal/node/6> for more details about the wrapped
API functions and data structures.

The _fcgi_ package code can be found on _GitHub_
<URL:http://github.com/jdc8/tclfcgi>.

_fcgi_ commands
===============

    fcgi Init

        Initialize the FCGX library. Must be called before calling the Accept_r
        command.

    fcgi OpenSocket path ?backlog?

        Create a FastCGI listen socket.

        The path arguments can be a Unix domain socket, a Windows named pipe, or
        a colon followed by a port number.

        The backlog argument is the listen queue depth used in the _listen()_
        call. Default value is 5.

        The socket file descriptor is returned.

    fcgi CloseSocket socket

        Close the FastCGI listen socket.

    fcgi InitRequest socket ?flags?

        Initialize a _FCGX_Request_ structure for use with Accept_r.

        The socket argument is the file descriptor as returned by the OpenSocket
        command.

        the flags argument is specified as an integer. Default value is 0.

        A _FCGX_Request_ handle is returned.

    fcgi Free request close

        Frees the memory allocated by the _FCGX_Request_ structure. If the close
        close is true, the associated stream are closed too.

    fcgi Accept_r request

        Accept a new request.

    fcgi Finish_r request

        Finish the request.

    fcgi GetParam request ?name?

        Obtain value of FCGI parameter.

    fcgi PutStr request stream string

        Write the specified string to the specified stream. Known streams are
        _stdout_ and _stderr_.

    fcgi GetStr request stream n

        Read n consecutive bytes from the specified stream. The string is
        returned. The only known value for stream is _stdin_.

    fcgi SetExitStatus request stream status

        Set the exit status for the stream.

Examples
========

The following example opens a FCGI listen socket on the specified path or port
and responds to requests with a HTML page containing the FCGI parameters and, if
present, the POST-ed data.

| package require fcgi

| if {[llength $argv] != 1} {
|     puts stderr "Usage: example.tcl <path_or_port>"
|     exit
| }

| set sock [fcgi OpenSocket [lindex $argv 0] 1]
| fcgi Init
| set req [fcgi InitRequest $sock {}]

| while {1} {
|     puts "### Accepr_r ###################################################################"
|     fcgi Accept_r $req
|     puts $req
|     puts "### GetParam ###################################################################"
|     set pd [fcgi GetParam $req]
|     dict for {k v} $pd {
| 	puts "$k=$v"
|     }
|     puts "### GetStr #####################################################################"
|     set content ""
|     if {[dict exists $pd "CONTENT_LENGTH"] && [string is integer -strict [dict get $pd "CONTENT_LENGTH"]] && [dict get $pd "CONTENT_LENGTH"] > 0} {
| 	set content [fcgi GetStr $req stdin [dict get $pd "CONTENT_LENGTH"]]
| 	puts $content
|     }
|     puts "### PutStr #####################################################################"
|     set C "Status: 200 OK
| Content-Type: text/html

| <html>
| <body>
| <h1>FCGI CriTcl wrapper test</h1>
| <h2>Parameters<h2>
| <table>
| "
|     dict for {k v} $pd {
| 	append C "<tr><td>$k</td><td>$v</td></tr>\n"
|     }
|     append C "</table>
| <h2>Body</h2>
| <pre>"
|     append C $content
|     append C "</pre>\n</body>\n</html>\n"
|     fcgi PutStr $req stdout $C
|     puts "### Finish_r ###################################################################"
|     fcgi SetExitStatus $req stdout 0
|     fcgi Finish_r $req
| }

Bugs, ideas, feedback
=====================

This document, and the package it describes, will undoubtedly contain bugs and
other problems. Please report such at the _Github tracker_
<URL:https://github.com/jdc8/tclfcgi/issues>. Please also report any ideas for
enhancements you may have for either package and/or documentation.

License
=======

The fcgi wrapper is relicensed under the BSD license (specifically Modified BSD
aka New BSD aka 3-clause BSD). Check COPYING.BSD for more info.

KEYWORDS
========

cgi fcgi fastcgi

CATEGORY
========

cgi

COPYRIGHT
=========

Copyright (c) Jos Decoster <[email protected]>

About

FastCGI wrapper for Tcl

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages