[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gcl-devel] read-char-no-hang
From: |
Camm Maguire |
Subject: |
Re: [Gcl-devel] read-char-no-hang |
Date: |
15 Feb 2005 09:37:29 -0500 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Greetings!
OK, my thought is that it is rather kernel related, and there is
something wrong/changed about the FIONREAD ioctl on standard terminal
file pointers.
To test:
echo '#undef LISTEN_FOR_INPUT' >>h/config.h
make h/cmpinclude.h
cd o
touch file.d
cd ..
rm unixport/saved_ansi_gcl
make
(Make sure file.o is remade).
Here is the 'fast' listen code implemented in linux.h for this
platform:
#undef LISTEN_FOR_INPUT
#define LISTEN_FOR_INPUT(fp) \
do { int c = 0; \
if(((fp)->_IO_read_ptr >= (fp)->_IO_read_end) \
&& (ioctl((fp)->_fileno, FIONREAD, &c),c<=0)) \
return 0;} while (0)
Here is the default fallback when the analog of the above is
unavailable (file.d):
#ifdef LISTEN_USE_FCNTL
do { int c = 0;
FILE *fp = strm->sm.sm_fp;
int orig;
int res;
if (feof(fp)) return TRUE;
orig = fcntl(fileno(fp), F_GETFL);
if (! (orig & O_NONBLOCK ) ) {
res=fcntl(fileno(fp),F_SETFL,orig | O_NONBLOCK);
}
c = getc(fp);
if (! (orig & O_NONBLOCK ) ){
fcntl(fileno(fp),F_SETFL,orig );
}
if (c != EOF)
{
ungetc(c,fp);
return TRUE;
}
return FALSE;
} while (0);
#endif
LISTEN_USE_FCNTL must be set by configure, which is basically always
the case as far as I can tell.
It would be helpful if someone could point to where to read up on the
FIONREAD iocntl on newer machines. I suppose the linux kernel doc is
as good a place as any, but these items have always been poorly
documented.
Take care,
James Amundson <address@hidden> writes:
> On Mon, 2005-02-14 at 10:04, Camm Maguire wrote:
> > Greetings!
>
> Thanks for looking into this.
>
> > I can't reproduce this, but rather get:
>
> On my system, read-char-no-hang and listen always return nil. I attached
> my output from foo and foo2 to the end of this message. I'm afraid it
> must be a gcc and/or libc issue. Here are my versions:
>
> |abacus3>gcc --version
> gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-42)
> Copyright (C) 2002 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is
> NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE.
>
> |abacus3>/lib/libc.so.6 --version
> GNU C Library stable release version 2.3.2, by Roland McGrath et al.
> Copyright (C) 2003 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.
> There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
> PARTICULAR PURPOSE.
> Compiled by GNU CC version 3.2.3 20030502 (Red Hat Linux 3.2.3-42).
> Compiled on a Linux 2.4.20 system on 2004-12-20.
> Available extensions:
> GNU libio by Per Bothner
> crypt add-on version 2.1 by Michael Glad and others
> linuxthreads-0.10 by Xavier Leroy
> The C stubs add-on version 2.1.2.
> BIND-8.2.3-T5B
> NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
> Glibc-2.0 compatibility add-on by Cristian Gafton
> libthread_db work sponsored by Alpha Processor Inc
> Thread-local storage support included.
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/libc/bugs.html>.
>
> I'm not sure what debugging steps to try next. I tried to understand how
> read-char-no-hang and listen are implemented in the gcl source, but I
> couldn't see it. Any pointers?
>
> Thanks,
> Jim
>
> P.S.
>
> GCL (GNU Common Lisp) 2.6.6 ANSI Feb 14 2005 21:03:12
> Source License: LGPL(gcl,gmp), GPL(unexec,bfd)
> Binary License: GPL due to GPL'ed components: (READLINE BFD UNEXEC)
> Modifications of this banner must retain notice of a compatible license
> Dedicated to the memory of W. Schelter
>
> Use (help) to get some basic information on how to use GCL.
>
> >(defun foo ()
> (format t "normal: '~a'~%" (read-char))
> (format t "normal: '~a'~%" (read-char))
> (format t "no-hang: '~a'~%" (read-char-no-hang))
> (format t "normal: '~a'~%" (read-char))
> (read-line))
>
> FOO
>
> >(foo)
> normal: '
> '
> abcde
> normal: 'a'
> no-hang: 'NIL'
> normal: 'b'
> "cde"
> NIL
>
> >(defun foo2 ()
> (do ()
> ((not (listen)))
> (read-char-no-hang))
> (foo))
>
> FOO2
>
> >(foo2)
> normal: '
> '
> abcdef
> normal: 'a'
> no-hang: 'NIL'
> normal: 'b'
> "cdef"
> NIL
>
> >
>
>
>
>
>
--
Camm Maguire address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens." -- Baha'u'llah
- [Gcl-devel] read-char-no-hang, James Amundson, 2005/02/06
- Message not available
- Re: [Gcl-devel] read-char-no-hang, Camm Maguire, 2005/02/15
- Re: [Gcl-devel] read-char-no-hang, Peter Wood, 2005/02/16
- Re: [Gcl-devel] read-char-no-hang, Peter Wood, 2005/02/16
- [Gcl-devel] Readline, Camm Maguire, 2005/02/16
- [Gcl-devel] Re: Readline, Peter Wood, 2005/02/22