On Mon, Sep 26, 2011 at 3:57 PM, Ludwig Isaac Lim <[email protected]> wrote:
> Hi:
>       Thanks for the quick response. Since according to definition of line
> buffering (see below), a buffer is flushed is after newlines, so writing
> statements such as :
>         print "<p> This is a paragraph</p>\n"
>
>      in a CGI program will automatically flush the buffer right? Or it
> doesn't? I wondering if perl will figure out that since STDOUT is not
> connected to a terminal, it will still buffer it even though the print
> contains a newline.

hi ludwig,

you need to understand the buffering system of standard i/o library..

there are 3 kinds of buffering..

1. fully buffered
2. line bufffered
3. unbuffered

the goal of buffering is to minimize number of read and write
expensive system calls...

in fully buffered.. actual i/o takes place when allocated buffer is
filled... for example files in a disk are normally fully buffered..
when you read data from a file.. data from kernel land to user land
delivered when bufer is filled... when you write a data to a file..
disk write takes place (flush) when buffer is filled..

in line buffered.. actual i/o takes place either allocated buffer is
filled or new line character is encountered on input or output stream
whichever comes first...  for example interactive device such as
terminal device is normally line buffered..

in unbuffered.. i/o takes place immediately... for example.. standard
error is normally unbuffered... error messages are displayed as soon
and quickly as possible...

ANSI C requiers the following buffering characteristics...

1. standard input and standard output are fully buffered as long as
they do not refer to an interactive device..
2. standard error is never fully buffered...

in your CGI program... if you run that in interactive mode... print
command is line buffered because standard output is connected to a
terminal device.... if you run that as a server and output connected
to a socket... it is a fully buffered because socket is fully
buffered..

if you dont like these defaults of any given standard i/o stream or
you want to change its characteristic from fully buffered to line
buffered for example..   you can use "setvbuf" function call and
specify the mode you want...

 _IOFBF  = fully buffered
 _IOLBF  = line buffered
 _IONBF  = unbuffered

$| is equivalent to line buffered as it flushes after write or print command..

fooler.
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph

Reply via email to