xref: /netbsd-src/external/bsd/ntp/dist/sntp/libevent/changelist-internal.h (revision cdfa2a7ef92791ba9db70a584a1d904730e6fb46)
1*cdfa2a7eSchristos /*	$NetBSD: changelist-internal.h,v 1.5 2020/05/25 20:47:33 christos Exp $	*/
28585484eSchristos 
38585484eSchristos /*
48585484eSchristos  * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
58585484eSchristos  *
68585484eSchristos  * Redistribution and use in source and binary forms, with or without
78585484eSchristos  * modification, are permitted provided that the following conditions
88585484eSchristos  * are met:
98585484eSchristos  * 1. Redistributions of source code must retain the above copyright
108585484eSchristos  *    notice, this list of conditions and the following disclaimer.
118585484eSchristos  * 2. Redistributions in binary form must reproduce the above copyright
128585484eSchristos  *    notice, this list of conditions and the following disclaimer in the
138585484eSchristos  *    documentation and/or other materials provided with the distribution.
148585484eSchristos  * 3. The name of the author may not be used to endorse or promote products
158585484eSchristos  *    derived from this software without specific prior written permission.
168585484eSchristos  *
178585484eSchristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
188585484eSchristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
198585484eSchristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
208585484eSchristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
218585484eSchristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
228585484eSchristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238585484eSchristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
248585484eSchristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258585484eSchristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
268585484eSchristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278585484eSchristos  */
288585484eSchristos #ifndef CHANGELIST_INTERNAL_H_INCLUDED_
298585484eSchristos #define CHANGELIST_INTERNAL_H_INCLUDED_
308585484eSchristos 
318585484eSchristos /*
328585484eSchristos   A "changelist" is a list of all the fd status changes that should be made
338585484eSchristos   between calls to the backend's dispatch function.  There are a few reasons
348585484eSchristos   that a backend would want to queue changes like this rather than processing
358585484eSchristos   them immediately.
368585484eSchristos 
378585484eSchristos     1) Sometimes applications will add and delete the same event more than
388585484eSchristos        once between calls to dispatch.  Processing these changes immediately
398585484eSchristos        is needless, and potentially expensive (especially if we're on a system
408585484eSchristos        that makes one syscall per changed event).
418585484eSchristos 
428585484eSchristos     2) Sometimes we can coalesce multiple changes on the same fd into a single
438585484eSchristos        syscall if we know about them in advance.  For example, epoll can do an
448585484eSchristos        add and a delete at the same time, but only if we have found out about
458585484eSchristos        both of them before we tell epoll.
468585484eSchristos 
478585484eSchristos     3) Sometimes adding an event that we immediately delete can cause
488585484eSchristos        unintended consequences: in kqueue, this makes pending events get
498585484eSchristos        reported spuriously.
508585484eSchristos  */
518585484eSchristos 
528585484eSchristos #include "event2/util.h"
538585484eSchristos 
548585484eSchristos /** Represents a */
558585484eSchristos struct event_change {
568585484eSchristos 	/** The fd or signal whose events are to be changed */
578585484eSchristos 	evutil_socket_t fd;
588585484eSchristos 	/* The events that were enabled on the fd before any of these changes
598585484eSchristos 	   were made.  May include EV_READ or EV_WRITE. */
608585484eSchristos 	short old_events;
618585484eSchristos 
628585484eSchristos 	/* The changes that we want to make in reading and writing on this fd.
638585484eSchristos 	 * If this is a signal, then read_change has EV_CHANGE_SIGNAL set,
648585484eSchristos 	 * and write_change is unused. */
658585484eSchristos 	ev_uint8_t read_change;
668585484eSchristos 	ev_uint8_t write_change;
67b8ecfcfeSchristos 	ev_uint8_t close_change;
688585484eSchristos };
698585484eSchristos 
708585484eSchristos /* Flags for read_change and write_change. */
718585484eSchristos 
728585484eSchristos /* If set, add the event. */
738585484eSchristos #define EV_CHANGE_ADD     0x01
748585484eSchristos /* If set, delete the event.  Exclusive with EV_CHANGE_ADD */
758585484eSchristos #define EV_CHANGE_DEL     0x02
768585484eSchristos /* If set, this event refers a signal, not an fd. */
778585484eSchristos #define EV_CHANGE_SIGNAL  EV_SIGNAL
788585484eSchristos /* Set for persistent events.  Currently not used. */
798585484eSchristos #define EV_CHANGE_PERSIST EV_PERSIST
808585484eSchristos /* Set for adding edge-triggered events. */
818585484eSchristos #define EV_CHANGE_ET      EV_ET
828585484eSchristos 
838585484eSchristos /* The value of fdinfo_size that a backend should use if it is letting
848585484eSchristos  * changelist handle its add and delete functions. */
858585484eSchristos #define EVENT_CHANGELIST_FDINFO_SIZE sizeof(int)
868585484eSchristos 
878585484eSchristos /** Set up the data fields in a changelist. */
888585484eSchristos void event_changelist_init_(struct event_changelist *changelist);
898585484eSchristos /** Remove every change in the changelist, and make corresponding changes
908585484eSchristos  * in the event maps in the base.  This function is generally used right
918585484eSchristos  * after making all the changes in the changelist. */
928585484eSchristos void event_changelist_remove_all_(struct event_changelist *changelist,
938585484eSchristos     struct event_base *base);
948585484eSchristos /** Free all memory held in a changelist. */
958585484eSchristos void event_changelist_freemem_(struct event_changelist *changelist);
968585484eSchristos 
978585484eSchristos /** Implementation of eventop_add that queues the event in a changelist. */
988585484eSchristos int event_changelist_add_(struct event_base *base, evutil_socket_t fd, short old, short events,
998585484eSchristos     void *p);
1008585484eSchristos /** Implementation of eventop_del that queues the event in a changelist. */
1018585484eSchristos int event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, short events,
1028585484eSchristos     void *p);
1038585484eSchristos 
1048585484eSchristos #endif
105