delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/01/17/17:20:33

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=0.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,SARE_SUB_ENC_UTF8,SPF_HELO_PASS,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Robert F <squaretriangle AT hotmail DOT co DOT uk>
Subject: Madness with the 'select' function, sigalrm, and stdout. =?utf-8?b?KENZR1dJTl9OVC02LjEtV09XNjQp?=
Date: Tue, 17 Jan 2012 22:16:19 +0000 (UTC)
Lines: 30
Message-ID: <loom.20120117T231256-287@post.gmane.org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

This could be a cygwin bug, but I'm not 100% sure.  It may even be a weird
interaction with the windows console.

I have a single threaded app that loops, polls network activity with a 'select'
function and interrupts the flow of the loop when a SIGALRM signal is ran, the
handler of which sets a variable that the loop responds to.

While this app more-or-less ran fine in its native linux environment, when
trying to run it at home in cygwin a problem occurs. Basically, between about
2-100 seconds of starting the process (on average), the alarm signal never runs
as scheduled and never runs again, except for one more time when I hit CTRL+C
(which I know by inserting debugging output into the signal handler).

The funny thing is the app happily continues looping and calling the 'select'
function, it just never gets interrupted by an alarm signal. The select function
handles cases of EINTR where it was interrupted by an alarm, btw (sockets are
nonblocking and timeout is 1 second).

Now here's the REALLY weird bit. IF I insert a printf (with newline terminated
string) after the select function, _the problem never occurs_.  If there's no
newline, the printed strings are buffered without being shown, until either a
newline arrives or I hit CTRL-C.

Doesn't work if I put it before the select function, only after.

I haven't included any io streams into the fd_sets passed to the select
function, in case you were wondering. They are zeroed and then only receive
network connections.

This has me stumped.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019