From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nick Roberts Newsgroups: gmane.emacs.devel Subject: FIONREAD with select Date: Sun, 6 May 2007 19:37:37 +1200 Message-ID: <17981.34241.190694.931030@kahikatea.snap.net.nz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1178437076 23274 80.91.229.12 (6 May 2007 07:37:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 6 May 2007 07:37:56 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 06 09:37:54 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HkbJZ-0001UH-Jj for ged-emacs-devel@m.gmane.org; Sun, 06 May 2007 09:37:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HkbQO-0002WY-V0 for ged-emacs-devel@m.gmane.org; Sun, 06 May 2007 03:44:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HkbQK-0002Rl-Ch for emacs-devel@gnu.org; Sun, 06 May 2007 03:44:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HkbQI-0002Md-DW for emacs-devel@gnu.org; Sun, 06 May 2007 03:44:51 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HkbQI-0002MT-BY for emacs-devel@gnu.org; Sun, 06 May 2007 03:44:50 -0400 Original-Received: from viper.snap.net.nz ([202.37.101.8]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HkbJR-00005e-Qi for emacs-devel@gnu.org; Sun, 06 May 2007 03:37:46 -0400 Original-Received: from kahikatea.snap.net.nz (7.61.255.123.dynamic.snap.net.nz [123.255.61.7]) by viper.snap.net.nz (Postfix) with ESMTP id ACF1F3D9E2F for ; Sun, 6 May 2007 19:37:42 +1200 (NZST) Original-Received: by kahikatea.snap.net.nz (Postfix, from userid 1000) id E80178F92B; Sun, 6 May 2007 19:37:37 +1200 (NZST) X-Mailer: VM 7.19 under Emacs 22.1.50.44 X-detected-kernel: Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:70584 Archived-At: I'm trying to get Gpm (a mouse server for a console) to work with Emacs through a Unix socket. To do this I am using select in read_avail_input to catch mouse events (on gpm_fd) and usual keyboard input (input_fd). For some reason with keyboard input, after passing through select, ioctl (input_fd, FIONREAD, &n_to_read) always reports no bytes to read (without select it's always 1). Does anybody know what I'm doing wrong? -- Nick http://www.inet.net.nz/~nickrob if (n_to_read == 0) return 0; #else /* not MSDOS */ + #ifdef HAVE_GPM + fd_set readset; + if (term_gpm) + { + Gpm_Event event; + int gpm = 1; + struct input_event hold_quit; + struct timeval timeout; + + /* How long `select' should wait. */ + timeout.tv_sec = 0; + timeout.tv_usec = 10000; + + hold_quit.kind = NO_EVENT; + + while (gpm) { + FD_ZERO (&readset); + FD_SET (gpm_fd, &readset); + FD_SET (input_fd, &readset); + + if (select (max (input_fd, gpm_fd) + 1, &readset, NULL, NULL, NULL) + < 0 && errno == EINTR) + continue; + gpm = FD_ISSET (gpm_fd, &readset); + if (gpm) { + if (Gpm_GetEvent (&event) > 0) { + nread += handle_one_term_event (&event, &hold_quit); + } + else + hold_quit.kind = NO_EVENT; + } + } + if (hold_quit.kind != NO_EVENT) + kbd_buffer_store_event (&hold_quit); + } + #endif /* HAVE_GPM */ #ifdef FIONREAD /* Find out how much input is available. */ if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) /* Formerly simply reported no input, but that sometimes led to a failure of Emacs to terminate.