Path: blob/main/contrib/libevent/changelist-internal.h
39475 views
/*1* Copyright (c) 2009-2012 Niels Provos and Nick Mathewson2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11* 3. The name of the author may not be used to endorse or promote products12* derived from this software without specific prior written permission.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/25#ifndef CHANGELIST_INTERNAL_H_INCLUDED_26#define CHANGELIST_INTERNAL_H_INCLUDED_2728/*29A "changelist" is a list of all the fd status changes that should be made30between calls to the backend's dispatch function. There are a few reasons31that a backend would want to queue changes like this rather than processing32them immediately.33341) Sometimes applications will add and delete the same event more than35once between calls to dispatch. Processing these changes immediately36is needless, and potentially expensive (especially if we're on a system37that makes one syscall per changed event).38392) Sometimes we can coalesce multiple changes on the same fd into a single40syscall if we know about them in advance. For example, epoll can do an41add and a delete at the same time, but only if we have found out about42both of them before we tell epoll.43443) Sometimes adding an event that we immediately delete can cause45unintended consequences: in kqueue, this makes pending events get46reported spuriously.47*/4849#include "event2/util.h"5051/** Represents a */52struct event_change {53/** The fd or signal whose events are to be changed */54evutil_socket_t fd;55/* The events that were enabled on the fd before any of these changes56were made. May include EV_READ or EV_WRITE. */57short old_events;5859/* The changes that we want to make in reading and writing on this fd.60* If this is a signal, then read_change has EV_CHANGE_SIGNAL set,61* and write_change is unused. */62ev_uint8_t read_change;63ev_uint8_t write_change;64ev_uint8_t close_change;65};6667/* Flags for read_change and write_change. */6869/* If set, add the event. */70#define EV_CHANGE_ADD 0x0171/* If set, delete the event. Exclusive with EV_CHANGE_ADD */72#define EV_CHANGE_DEL 0x0273/* If set, this event refers a signal, not an fd. */74#define EV_CHANGE_SIGNAL EV_SIGNAL75/* Set for persistent events. Currently not used. */76#define EV_CHANGE_PERSIST EV_PERSIST77/* Set for adding edge-triggered events. */78#define EV_CHANGE_ET EV_ET7980/* The value of fdinfo_size that a backend should use if it is letting81* changelist handle its add and delete functions. */82#define EVENT_CHANGELIST_FDINFO_SIZE sizeof(int)8384/** Set up the data fields in a changelist. */85void event_changelist_init_(struct event_changelist *changelist);86/** Remove every change in the changelist, and make corresponding changes87* in the event maps in the base. This function is generally used right88* after making all the changes in the changelist. */89void event_changelist_remove_all_(struct event_changelist *changelist,90struct event_base *base);91/** Free all memory held in a changelist. */92void event_changelist_freemem_(struct event_changelist *changelist);9394/** Implementation of eventop_add that queues the event in a changelist. */95int event_changelist_add_(struct event_base *base, evutil_socket_t fd, short old, short events,96void *p);97/** Implementation of eventop_del that queues the event in a changelist. */98int event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, short events,99void *p);100101#endif102103104