Blame libevent/changelist-internal.h

Packit e9ba0d
/*
Packit e9ba0d
 * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
Packit e9ba0d
 *
Packit e9ba0d
 * Redistribution and use in source and binary forms, with or without
Packit e9ba0d
 * modification, are permitted provided that the following conditions
Packit e9ba0d
 * are met:
Packit e9ba0d
 * 1. Redistributions of source code must retain the above copyright
Packit e9ba0d
 *    notice, this list of conditions and the following disclaimer.
Packit e9ba0d
 * 2. Redistributions in binary form must reproduce the above copyright
Packit e9ba0d
 *    notice, this list of conditions and the following disclaimer in the
Packit e9ba0d
 *    documentation and/or other materials provided with the distribution.
Packit e9ba0d
 * 3. The name of the author may not be used to endorse or promote products
Packit e9ba0d
 *    derived from this software without specific prior written permission.
Packit e9ba0d
 *
Packit e9ba0d
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Packit e9ba0d
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit e9ba0d
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Packit e9ba0d
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit e9ba0d
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Packit e9ba0d
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit e9ba0d
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit e9ba0d
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit e9ba0d
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Packit e9ba0d
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit e9ba0d
 */
Packit e9ba0d
#ifndef _CHANGELIST_H_
Packit e9ba0d
#define _CHANGELIST_H_
Packit e9ba0d
Packit e9ba0d
/*
Packit e9ba0d
  A "changelist" is a list of all the fd status changes that should be made
Packit e9ba0d
  between calls to the backend's dispatch function.  There are a few reasons
Packit e9ba0d
  that a backend would want to queue changes like this rather than processing
Packit e9ba0d
  them immediately.
Packit e9ba0d
Packit e9ba0d
    1) Sometimes applications will add and delete the same event more than
Packit e9ba0d
       once between calls to dispatch.  Processing these changes immediately
Packit e9ba0d
       is needless, and potentially expensive (especially if we're on a system
Packit e9ba0d
       that makes one syscall per changed event).
Packit e9ba0d
Packit e9ba0d
    2) Sometimes we can coalesce multiple changes on the same fd into a single
Packit e9ba0d
       syscall if we know about them in advance.  For example, epoll can do an
Packit e9ba0d
       add and a delete at the same time, but only if we have found out about
Packit e9ba0d
       both of them before we tell epoll.
Packit e9ba0d
Packit e9ba0d
    3) Sometimes adding an event that we immediately delete can cause
Packit e9ba0d
       unintended consequences: in kqueue, this makes pending events get
Packit e9ba0d
       reported spuriously.
Packit e9ba0d
 */
Packit e9ba0d
Packit e9ba0d
#include "event2/util.h"
Packit e9ba0d
Packit e9ba0d
/** Represents a */
Packit e9ba0d
struct event_change {
Packit e9ba0d
	/** The fd or signal whose events are to be changed */
Packit e9ba0d
	evutil_socket_t fd;
Packit e9ba0d
	/* The events that were enabled on the fd before any of these changes
Packit e9ba0d
	   were made.  May include EV_READ or EV_WRITE. */
Packit e9ba0d
	short old_events;
Packit e9ba0d
Packit e9ba0d
	/* The changes that we want to make in reading and writing on this fd.
Packit e9ba0d
	 * If this is a signal, then read_change has EV_CHANGE_SIGNAL set,
Packit e9ba0d
	 * and write_change is unused. */
Packit e9ba0d
	ev_uint8_t read_change;
Packit e9ba0d
	ev_uint8_t write_change;
Packit e9ba0d
};
Packit e9ba0d
Packit e9ba0d
/* Flags for read_change and write_change. */
Packit e9ba0d
Packit e9ba0d
/* If set, add the event. */
Packit e9ba0d
#define EV_CHANGE_ADD     0x01
Packit e9ba0d
/* If set, delete the event.  Exclusive with EV_CHANGE_ADD */
Packit e9ba0d
#define EV_CHANGE_DEL     0x02
Packit e9ba0d
/* If set, this event refers a signal, not an fd. */
Packit e9ba0d
#define EV_CHANGE_SIGNAL  EV_SIGNAL
Packit e9ba0d
/* Set for persistent events.  Currently not used. */
Packit e9ba0d
#define EV_CHANGE_PERSIST EV_PERSIST
Packit e9ba0d
/* Set for adding edge-triggered events. */
Packit e9ba0d
#define EV_CHANGE_ET      EV_ET
Packit e9ba0d
Packit e9ba0d
/* The value of fdinfo_size that a backend should use if it is letting
Packit e9ba0d
 * changelist handle its add and delete functions. */
Packit e9ba0d
#define EVENT_CHANGELIST_FDINFO_SIZE sizeof(int)
Packit e9ba0d
Packit e9ba0d
/** Set up the data fields in a changelist. */
Packit e9ba0d
void event_changelist_init(struct event_changelist *changelist);
Packit e9ba0d
/** Remove every change in the changelist, and make corresponding changes
Packit e9ba0d
 * in the event maps in the base.  This function is generally used right
Packit e9ba0d
 * after making all the changes in the changelist. */
Packit e9ba0d
void event_changelist_remove_all(struct event_changelist *changelist,
Packit e9ba0d
    struct event_base *base);
Packit e9ba0d
/** Free all memory held in a changelist. */
Packit e9ba0d
void event_changelist_freemem(struct event_changelist *changelist);
Packit e9ba0d
Packit e9ba0d
/** Implementation of eventop_add that queues the event in a changelist. */
Packit e9ba0d
int event_changelist_add(struct event_base *base, evutil_socket_t fd, short old, short events,
Packit e9ba0d
    void *p);
Packit e9ba0d
/** Implementation of eventop_del that queues the event in a changelist. */
Packit e9ba0d
int event_changelist_del(struct event_base *base, evutil_socket_t fd, short old, short events,
Packit e9ba0d
    void *p);
Packit e9ba0d
Packit e9ba0d
#endif