1*805a1ce9Schristos /* $NetBSD: changelist-internal.h,v 1.1.1.2 2017/01/31 21:14:52 christos Exp $ */ 26ecf6635Schristos /* 36ecf6635Schristos * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 46ecf6635Schristos * 56ecf6635Schristos * Redistribution and use in source and binary forms, with or without 66ecf6635Schristos * modification, are permitted provided that the following conditions 76ecf6635Schristos * are met: 86ecf6635Schristos * 1. Redistributions of source code must retain the above copyright 96ecf6635Schristos * notice, this list of conditions and the following disclaimer. 106ecf6635Schristos * 2. Redistributions in binary form must reproduce the above copyright 116ecf6635Schristos * notice, this list of conditions and the following disclaimer in the 126ecf6635Schristos * documentation and/or other materials provided with the distribution. 136ecf6635Schristos * 3. The name of the author may not be used to endorse or promote products 146ecf6635Schristos * derived from this software without specific prior written permission. 156ecf6635Schristos * 166ecf6635Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 176ecf6635Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 186ecf6635Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 196ecf6635Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 206ecf6635Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 216ecf6635Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 226ecf6635Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 236ecf6635Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 246ecf6635Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 256ecf6635Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 266ecf6635Schristos */ 27*805a1ce9Schristos #ifndef CHANGELIST_INTERNAL_H_INCLUDED_ 28*805a1ce9Schristos #define CHANGELIST_INTERNAL_H_INCLUDED_ 296ecf6635Schristos 306ecf6635Schristos /* 316ecf6635Schristos A "changelist" is a list of all the fd status changes that should be made 326ecf6635Schristos between calls to the backend's dispatch function. There are a few reasons 336ecf6635Schristos that a backend would want to queue changes like this rather than processing 346ecf6635Schristos them immediately. 356ecf6635Schristos 366ecf6635Schristos 1) Sometimes applications will add and delete the same event more than 376ecf6635Schristos once between calls to dispatch. Processing these changes immediately 386ecf6635Schristos is needless, and potentially expensive (especially if we're on a system 396ecf6635Schristos that makes one syscall per changed event). 406ecf6635Schristos 416ecf6635Schristos 2) Sometimes we can coalesce multiple changes on the same fd into a single 426ecf6635Schristos syscall if we know about them in advance. For example, epoll can do an 436ecf6635Schristos add and a delete at the same time, but only if we have found out about 446ecf6635Schristos both of them before we tell epoll. 456ecf6635Schristos 466ecf6635Schristos 3) Sometimes adding an event that we immediately delete can cause 476ecf6635Schristos unintended consequences: in kqueue, this makes pending events get 486ecf6635Schristos reported spuriously. 496ecf6635Schristos */ 506ecf6635Schristos 516ecf6635Schristos #include "event2/util.h" 526ecf6635Schristos 536ecf6635Schristos /** Represents a */ 546ecf6635Schristos struct event_change { 556ecf6635Schristos /** The fd or signal whose events are to be changed */ 566ecf6635Schristos evutil_socket_t fd; 576ecf6635Schristos /* The events that were enabled on the fd before any of these changes 586ecf6635Schristos were made. May include EV_READ or EV_WRITE. */ 596ecf6635Schristos short old_events; 606ecf6635Schristos 616ecf6635Schristos /* The changes that we want to make in reading and writing on this fd. 626ecf6635Schristos * If this is a signal, then read_change has EV_CHANGE_SIGNAL set, 636ecf6635Schristos * and write_change is unused. */ 646ecf6635Schristos ev_uint8_t read_change; 656ecf6635Schristos ev_uint8_t write_change; 66*805a1ce9Schristos ev_uint8_t close_change; 676ecf6635Schristos }; 686ecf6635Schristos 696ecf6635Schristos /* Flags for read_change and write_change. */ 706ecf6635Schristos 716ecf6635Schristos /* If set, add the event. */ 726ecf6635Schristos #define EV_CHANGE_ADD 0x01 736ecf6635Schristos /* If set, delete the event. Exclusive with EV_CHANGE_ADD */ 746ecf6635Schristos #define EV_CHANGE_DEL 0x02 756ecf6635Schristos /* If set, this event refers a signal, not an fd. */ 766ecf6635Schristos #define EV_CHANGE_SIGNAL EV_SIGNAL 776ecf6635Schristos /* Set for persistent events. Currently not used. */ 786ecf6635Schristos #define EV_CHANGE_PERSIST EV_PERSIST 796ecf6635Schristos /* Set for adding edge-triggered events. */ 806ecf6635Schristos #define EV_CHANGE_ET EV_ET 816ecf6635Schristos 826ecf6635Schristos /* The value of fdinfo_size that a backend should use if it is letting 836ecf6635Schristos * changelist handle its add and delete functions. */ 846ecf6635Schristos #define EVENT_CHANGELIST_FDINFO_SIZE sizeof(int) 856ecf6635Schristos 866ecf6635Schristos /** Set up the data fields in a changelist. */ 87*805a1ce9Schristos void event_changelist_init_(struct event_changelist *changelist); 886ecf6635Schristos /** Remove every change in the changelist, and make corresponding changes 896ecf6635Schristos * in the event maps in the base. This function is generally used right 906ecf6635Schristos * after making all the changes in the changelist. */ 91*805a1ce9Schristos void event_changelist_remove_all_(struct event_changelist *changelist, 926ecf6635Schristos struct event_base *base); 936ecf6635Schristos /** Free all memory held in a changelist. */ 94*805a1ce9Schristos void event_changelist_freemem_(struct event_changelist *changelist); 956ecf6635Schristos 966ecf6635Schristos /** Implementation of eventop_add that queues the event in a changelist. */ 97*805a1ce9Schristos int event_changelist_add_(struct event_base *base, evutil_socket_t fd, short old, short events, 986ecf6635Schristos void *p); 996ecf6635Schristos /** Implementation of eventop_del that queues the event in a changelist. */ 100*805a1ce9Schristos int event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, short events, 1016ecf6635Schristos void *p); 1026ecf6635Schristos 1036ecf6635Schristos #endif 104