libnwam_events.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A * Implementation of event notification mechanism used by the GUI and 2N/A * netadm. Clients register for events via nwam_events_init() and 2N/A * unregister via nwam_events_fini(). nwamd sends events via nwam_event_send() 2N/A * and applications block waiting for a new event to be delivered in 2N/A * nwam_event_wait(). Events are implemented as System V message queues, 2N/A * one per event client. The event mechanism has to be resilient to 2N/A * nwamd restarts so that clients do not lose the event connection. 2N/A * This is protecting simultaneous access to the msqid and its configuration. 2N/A * Get next event in queue. 2N/A * We see this errno eventhough it isn't 2N/A * documented. Try again. If this causes 2N/A * a busy loop then grab a trace otherwise 2N/A * it's a brace 'til we can figure out why it 2N/A /* Resize event down from maximum size */ 2N/A * Register for receipt of events from nwamd. Event delivery is 2N/A * done via a System V message queue. 2N/A /* Get system-wide message queue ID */ 2N/A * Un-register for receipt of events from nwamd. Make a request to nwamd 2N/A * to destroy the message queue. 2N/A * Create an event queue. Called by nwamd to create System V message queues 2N/A * for clients to listen for events. 2N/A * Send event to registered listeners via the set of registered System V 2N/A * For each file matching our event message queue file prefix, 2N/A * check the queue is still being read, and if so send the message. 2N/A /* Retrieve stats to analyse queue activity */ 2N/A * If buf.msg_qnum > NWAM_EVENT_MAX_NUM_PENDING 2N/A * _and_ msg_stime is more than 10s after msg_rtime - 2N/A * indicating message(s) have been hanging around unclaimed - 2N/A * we destroy the queue as the client has most likely gone 2N/A * away. This can happen if a registered client hits Ctrl^C. 2N/A * This shouldn't ever block. If it does then log an error and 2N/A * clean up the queue. 2N/A * Destroy an event queue. Called by nwamd to destroy the associated message 2N/A * Stop sending events. Called by nwamd to destroy each System V message queue 2N/A * For each file matching our event message queue file prefix, 2N/A * destroy the queue and message file.