delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/03/18/03:51:58

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <F536EC3453B2D411AD6100508BAF5F9901FAB455@bwga521a.ts.siemens.de>
From: Kandziora Jan <Jan DOT Kandziora AT ts DOT siemens DOT de>
To: "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com>
Subject: 1.3.9: setitimer/getitimer granularity
Date: Mon, 18 Mar 2002 09:50:38 +0100
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)

Hello folks,

I want to poll some sockets other machines deliver data to. I have to wait a
maximum amount of time until ALL sockets should have received an arbitrary
amount of data, to put the incoming data into time slots. So I have to do
subsequent poll()s or select()s, each with a timeout of the remaining time
from the previous one. With Linux, I can use select() for this: it returns
the time remaining. But the manpage stated this is not portable.

I have tried to get the remaining time with setitimer/getitimer, but that
doesn't seem to work with Cygwin. Anyway, with Linux, it works well.
The code snippet is like below:

#include <sys/poll.h>
#include <sys/time.h>

int subsequent_poll(struct pollfd connections[], unsigned int
connection_count, int timeout);
{
	struct itimerval timer;
	unsigned int i;

	for(i=0;i<connection_count;i++)
	{
		connections[i]->revent=0;
		connections[i]->event=POLLIN;
	}

	timer.it_interval.tv_sec=0;
	timer.it_interval.tv_usec=0;
	timer.it_value.tv_sec=timeout / 1000;
	timer.it_value.tv_usec=(timeout-timer.it_value.tv_sec*1000)*1000;
	setitimer(ITIMER_REAL,&timer,NULL);

	poll(connections,connection_count,timeout);

	getitimer(ITIMER_REAL,&timer);
	return (timer.it_value.tv_sec * 1000 + timer.it_value.tv_usec /
1000);
}

The problem is, getimer returns only values which are a multiple of
1000(and, oddly, sometimes a value of -296), so the granularity is only one
second. This happens for a value of timeout below or above 1000, all the
same.

Is there any way to get around this problem, or does select() in Cygwin
works like in Linux? That will be portable enough for now.

Thanks,

	Jan Kandziora


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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