/*
* tclUnixNotify.c --
*
* This file contains Unix-specific procedures for the notifier,
* which is the lowest-level part of the Tcl event loop. This file
* works together with ../generic/tclNotify.c.
*
* Copyright (c) 1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tclUnixNotfy.c 1.31 96/07/23 16:17:29
*/
#include "tclInt.h"
#include "tclPort.h"
#include <signal.h>
#ifdef WIN32
#include <windows.h>
#endif
#if HAVE_SYS_SELECT_H && !defined(NFDBITS)
#endif
/*
* The information below is used to provide read, write, and
* exception masks to select during calls to Tcl_DoOneEvent.
*/
/* This array is used to build up the masks
* to be used in the next call to select.
* Bits are set in response to calls to
* Tcl_WatchFile. */
* conditions that were found to exist by the
* last call to select. */
* (one more than highest fd for which
* Tcl_WatchFile has been called). */
#if 1
static int eventsFound;
static int ignoreEvents;
#endif
/*
* Static routines in this file:
*/
extern void TclWinFlushEvents()
{
ignoreEvents = 1;
}
ignoreEvents = 0;
}
/*
*----------------------------------------------------------------------
*
* Tcl_WatchFile --
*
* Arrange for Tcl_DoOneEvent to include this file in the masks
* for the next call to select. This procedure is invoked by
* event sources, which are in turn invoked by Tcl_DoOneEvent
* before it invokes select.
*
* Results:
* None.
*
* Side effects:
*
* The notifier will generate a file event when the I/O channel
* given by fd next becomes ready in the way indicated by mask.
* If fd is already registered then the old mask will be replaced
* with the new one. Once the event is sent, the notifier will
* not send any more events about the fd until the next call to
* Tcl_NotifyFile.
*
*----------------------------------------------------------------------
*/
void
int mask; /* OR'ed combination of TCL_READABLE,
* TCL_WRITABLE, and TCL_EXCEPTION:
* indicates conditions to wait for
* in select. */
{
if (type != TCL_UNIX_FD) {
panic("Tcl_WatchFile: unexpected file type");
}
if (fd >= FD_SETSIZE) {
}
if (mask & TCL_READABLE) {
}
if (mask & TCL_WRITABLE) {
}
if (mask & TCL_EXCEPTION) {
}
}
}
#if 1
extern int Tcl_NumEventsFound()
{
return eventsFound;
}
#endif
/*
*----------------------------------------------------------------------
*
* Tcl_FileReady --
*
* Indicates what conditions (readable, writable, etc.) were
* present on a file the last time the notifier invoked select.
* This procedure is typically invoked by event sources to see
* if they should queue events.
*
* Results:
* The return value is 0 if none of the conditions specified by mask
* was true for fd the last time the system checked. If any of the
* conditions were true, then the return value is a mask of those
* that were true.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
int mask; /* OR'ed combination of TCL_READABLE,
* TCL_WRITABLE, and TCL_EXCEPTION:
* indicates conditions caller cares about. */
{
if (type != TCL_UNIX_FD) {
panic("Tcl_FileReady: unexpected file type");
}
result = 0;
result |= TCL_READABLE;
}
result |= TCL_WRITABLE;
}
result |= TCL_EXCEPTION;
}
return result;
}
/*
*----------------------------------------------------------------------
*
* MaskEmpty --
*
* Returns nonzero if mask is empty (has no bits set).
*
* Results:
* Nonzero if the mask is empty, zero otherwise.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static int
long *maskPtr;
{
runPtr++) {
if (*runPtr != 0) {
found = 1;
break;
}
}
return !found;
}
/*
*----------------------------------------------------------------------
*
* Tcl_WaitForEvent --
*
* This procedure does the lowest level wait for events in a
* platform-specific manner. It uses information provided by
* previous calls to Tcl_WatchFile, plus the timePtr argument,
* to determine what to wait for and how long to wait.
*
* Results:
* The return value is normally TCL_OK. However, if there are
* no events to wait for (e.g. no files and no timers) so that
* the procedure would block forever, then it returns TCL_ERROR.
*
* Side effects:
* May put the process to sleep for a while, depending on timePtr.
* When this procedure returns, an event of interest to the application
* has probably, but not necessarily, occurred.
*
*----------------------------------------------------------------------
*/
int
* that this procedure should block before
* returning. The time is given as an
* interval, not an absolute wakeup time.
* NULL means block forever. */
{
int numFound;
#ifdef WIN32
if (ignoreEvents)
return TCL_OK;
if (winFd < 0)
#endif
return TCL_ERROR;
}
timeoutPtr = NULL;
} else {
timeoutPtr = &timeout;
}
#ifdef WIN32
{
}
#endif
/*
* Some systems don't clear the masks after an error, so
* we have to do it here.
*/
if (numFound == -1) {
}
/*
* Reset the check masks in preparation for the next call to
* select.
*/
numFdBits = 0;
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* Tcl_Sleep --
*
* Delay execution for the specified number of milliseconds.
*
* Results:
* None.
*
* Side effects:
* Time passes.
*
*----------------------------------------------------------------------
*/
void
int ms; /* Number of milliseconds to sleep. */
{
/*
* The only trick here is that select appears to return early
* under some conditions, so we have to check to make sure that
* the right amount of time really has elapsed. If it's too
* early, go back to sleep again.
*/
}
while (1) {
}
/*
* Special note: must convert delay.tv_sec to int before comparing
* to zero, since delay.tv_usec is unsigned on some platforms.
*/
break;
}
(SELECT_MASK *) 0, &delay);
}
}