/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <errno.h>
#include <libinetutil.h>
#include "libinetutil_impl.h"
/*
* signal_to_eh[] is pretty much useless, since the event handler is
* really a singleton (we pass iu_eh_t *'s around to maintain an
* abstraction, not to allow multiple event handlers to exist). we
* need some way to get back our event handler in post_signal(),
* and since the signal model is too lame to provide opaque pointers,
* we have to resort to global variables.
*/
/*
* iu_eh_create(): creates, initializes, and returns an event handler for use
*
* input: void
* output: iu_eh_t *: the new event handler
*/
iu_eh_t *
iu_eh_create(void)
{
int sig;
return (NULL);
eh->iueh_num_fds = 0;
eh->iueh_reason = 0;
}
return (eh);
}
/*
* iu_eh_destroy(): destroys an existing event handler
*
* input: iu_eh_t *: the event handler to destroy
* output: void
* notes: it is assumed all events related to this eh have been unregistered
* prior to calling iu_eh_destroy()
*/
void
{
int sig;
}
/*
* iu_stop_handling_events(): informs the event handler to stop handling events
*
* input: iu_eh_t *: the event handler to stop.
* unsigned int: the (user-defined) reason why
* iu_eh_shutdown_t *: the shutdown callback. if it is NULL,
* the event handler will stop right away;
* otherwise, the event handler will not
* stop until the callback returns B_TRUE
* void *: data for the shutdown callback. it may be NULL
* output: void
* notes: the event handler in question must be in iu_handle_events()
*/
void
{
}
/*
* grow_fds(): grows the internal file descriptor set used by the event
* handler
*
* input: iu_eh_t *: the event handler whose descriptor set needs to be grown
* int: the new total number of descriptors needed in the set
* output: int: zero on failure, success otherwise
*/
static int
{
unsigned int i;
return (1);
if (new_pollfds == NULL)
return (0);
total_fds * sizeof (iu_event_node_t));
if (new_events == NULL) {
/*
* yow. one realloc failed, but the other succeeded.
* we will just leave the descriptor size at the
* original size. if the caller tries again, then the
* first realloc() will do nothing since the requested
* number of descriptors is already allocated.
*/
return (0);
}
return (1);
}
/*
* when increasing the file descriptor set size, how much to increase by:
*/
/*
* iu_register_event(): adds an event to the set managed by an event handler
*
* input: iu_eh_t *: the event handler to add the event to
* int: the descriptor on which to listen for events. must be
* a descriptor which has not yet been registered.
* short: the events to listen for on that descriptor
* iu_eh_callback_t: the callback to execute when the event happens
* void *: the argument to pass to the callback function
* output: iu_event_id_t: -1 on failure, the new event id otherwise
*/
void *arg)
{
return (-1);
/*
* the current implementation uses the file descriptor itself
* as the iu_event_id_t, since we know the kernel's gonna be
* pretty smart about managing file descriptors and we know
* that they're per-process unique. however, it does mean
* that the same descriptor cannot be registered multiple
* times for different callbacks depending on its events. if
* this behavior is desired, either use dup(2) to get a unique
* descriptor, or demultiplex in the callback function based
* on `events'.
*/
return (-1);
return (fd);
}
/*
* iu_unregister_event(): removes an event from the set managed by an event
* handler
*
* input: iu_eh_t *: the event handler to remove the event from
* iu_event_id_t: the event to remove (from iu_register_event())
* void **: if non-NULL, will be set to point to the argument passed
* into iu_register_event()
* output: int: zero on failure, success otherwise
*/
int
{
return (0);
/*
* fringe condition: in case this event was about to be called
* back in iu_handle_events(), zero revents to prevent it.
* (having an unregistered event get called back could be
* disastrous depending on if `arg' is reference counted).
*/
return (1);
}
/*
* iu_handle_events(): begins handling events on an event handler
*
* input: iu_eh_t *: the event handler to begin event handling on
* tq_t *: a timer queue of timers to process while handling events
* (see timer_queue.h for details)
* output: int: the reason why we stopped, -1 if due to internal failure
*/
int
{
unsigned int i;
do {
/*
* we only unblock registered signals around poll(); this
* way other parts of the code don't have to worry about
* restarting "non-restartable" system calls and so forth.
*/
saved_errno = errno;
switch (n_lit) {
case -1:
if (saved_errno != EINTR)
return (-1);
sig,
}
}
break;
continue;
case 0:
/*
* timeout occurred. we must have a valid tq pointer
* since that's the only way a timeout can happen.
*/
(void) iu_expire_timers(tq);
continue;
default:
break;
}
/* file descriptors are lit; call 'em back */
continue;
n_lit--;
/*
* turn off any descriptors that have gone
* bad. shouldn't happen, but...
*/
/* TODO: issue a warning here - but how? */
continue;
}
}
return (eh->iueh_reason);
}
/*
* post_signal(): posts a signal for later consumption in iu_handle_events()
*
* input: int: the signal that's been received
* output: void
*/
static void
{
}
/*
* iu_eh_register_signal(): registers a signal handler with an event handler
*
* input: iu_eh_t *: the event handler to register the signal handler with
* int: the signal to register
* iu_eh_sighandler_t *: the signal handler to call back
* void *: the argument to pass to the signal handler function
* output: int: zero on failure, success otherwise
*/
int
void *data)
{
return (0);
return (0);
return (0);
}
/*
* iu_eh_unregister_signal(): unregisters a signal handler from an event handler
*
* input: iu_eh_t *: the event handler to unregister the signal handler from
* int: the signal to unregister
* void **: if non-NULL, will be set to point to the argument passed
* into iu_eh_register_signal()
* output: int: zero on failure, success otherwise
*/
int
{
return (0);
return (0);
(void) sigemptyset(&set);
return (1);
}