154359Sroberto/*	$NetBSD: bufferevent_compat.h,v 1.1.1.4 2021/04/07 02:43:14 christos Exp $	*/
254359Sroberto/*
354359Sroberto * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson
454359Sroberto * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
554359Sroberto * All rights reserved.
654359Sroberto *
754359Sroberto * Redistribution and use in source and binary forms, with or without
854359Sroberto * modification, are permitted provided that the following conditions
954359Sroberto * are met:
1054359Sroberto * 1. Redistributions of source code must retain the above copyright
1154359Sroberto *    notice, this list of conditions and the following disclaimer.
1254359Sroberto * 2. Redistributions in binary form must reproduce the above copyright
1354359Sroberto *    notice, this list of conditions and the following disclaimer in the
1454359Sroberto *    documentation and/or other materials provided with the distribution.
1554359Sroberto * 3. The name of the author may not be used to endorse or promote products
1654359Sroberto *    derived from this software without specific prior written permission.
1754359Sroberto *
1854359Sroberto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1954359Sroberto * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2054359Sroberto * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2154359Sroberto * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2254359Sroberto * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2354359Sroberto * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2454359Sroberto * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2554359Sroberto * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2654359Sroberto * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2754359Sroberto * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2854359Sroberto */
2954359Sroberto#ifndef EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_
3054359Sroberto#define EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_
3154359Sroberto
3254359Sroberto#include <event2/visibility.h>
3354359Sroberto
3454359Sroberto#define evbuffercb bufferevent_data_cb
3554359Sroberto#define everrorcb bufferevent_event_cb
3654359Sroberto
3754359Sroberto/**
3854359Sroberto  Create a new bufferevent for an fd.
3954359Sroberto
4054359Sroberto  This function is deprecated.  Use bufferevent_socket_new and
4154359Sroberto  bufferevent_set_callbacks instead.
4254359Sroberto
4354359Sroberto  Libevent provides an abstraction on top of the regular event callbacks.
4454359Sroberto  This abstraction is called a buffered event.  A buffered event provides
4554359Sroberto  input and output buffers that get filled and drained automatically.  The
4654359Sroberto  user of a buffered event no longer deals directly with the I/O, but
4754359Sroberto  instead is reading from input and writing to output buffers.
4854359Sroberto
4954359Sroberto  Once initialized, the bufferevent structure can be used repeatedly with
5054359Sroberto  bufferevent_enable() and bufferevent_disable().
5154359Sroberto
5254359Sroberto  When read enabled the bufferevent will try to read from the file descriptor
5354359Sroberto  and call the read callback.  The write callback is executed whenever the
5454359Sroberto  output buffer is drained below the write low watermark, which is 0 by
5554359Sroberto  default.
5654359Sroberto
5754359Sroberto  If multiple bases are in use, bufferevent_base_set() must be called before
5854359Sroberto  enabling the bufferevent for the first time.
5954359Sroberto
6054359Sroberto  @deprecated This function is deprecated because it uses the current
6154359Sroberto    event base, and as such can be error prone for multithreaded programs.
6254359Sroberto    Use bufferevent_socket_new() instead.
6382498Sroberto
6454359Sroberto  @param fd the file descriptor from which data is read and written to.
65132451Sroberto	 This file descriptor is not allowed to be a pipe(2).
66106163Sroberto  @param readcb callback to invoke when there is data to be read, or NULL if
6754359Sroberto	 no callback is desired
6854359Sroberto  @param writecb callback to invoke when the file descriptor is ready for
6954359Sroberto	 writing, or NULL if no callback is desired
7054359Sroberto  @param errorcb callback to invoke when there is an error on the file
7154359Sroberto	 descriptor
7254359Sroberto  @param cbarg an argument that will be supplied to each of the callbacks
7354359Sroberto	 (readcb, writecb, and errorcb)
7454359Sroberto  @return a pointer to a newly allocated bufferevent struct, or NULL if an
7554359Sroberto	  error occurred
7654359Sroberto  @see bufferevent_base_set(), bufferevent_free()
7754359Sroberto  */
7854359SrobertoEVENT2_EXPORT_SYMBOL
7954359Srobertostruct bufferevent *bufferevent_new(evutil_socket_t fd,
8054359Sroberto    evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
8154359Sroberto
8254359Sroberto
8354359Sroberto/**
8454359Sroberto  Set the read and write timeout for a buffered event.
8554359Sroberto
8654359Sroberto  @param bufev the bufferevent to be modified
87132451Sroberto  @param timeout_read the read timeout
8854359Sroberto  @param timeout_write the write timeout
8954359Sroberto */
9054359SrobertoEVENT2_EXPORT_SYMBOL
9154359Srobertovoid bufferevent_settimeout(struct bufferevent *bufev,
9254359Sroberto    int timeout_read, int timeout_write);
9354359Sroberto
9454359Sroberto#define EVBUFFER_READ		BEV_EVENT_READING
9554359Sroberto#define EVBUFFER_WRITE		BEV_EVENT_WRITING
9654359Sroberto#define EVBUFFER_EOF		BEV_EVENT_EOF
9754359Sroberto#define EVBUFFER_ERROR		BEV_EVENT_ERROR
9854359Sroberto#define EVBUFFER_TIMEOUT	BEV_EVENT_TIMEOUT
9954359Sroberto
10054359Sroberto/** macro for getting access to the input buffer of a bufferevent */
10154359Sroberto#define EVBUFFER_INPUT(x)	bufferevent_get_input(x)
10254359Sroberto/** macro for getting access to the output buffer of a bufferevent */
10354359Sroberto#define EVBUFFER_OUTPUT(x)	bufferevent_get_output(x)
10454359Sroberto
10554359Sroberto#endif
10654359Sroberto