Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / event2 / bufferevent_compat.h @ 14

History | View | Annotate | Download (4.49 KB)

1 13 up20180614
/*        $NetBSD: bufferevent_compat.h,v 1.1.1.2 2015/01/29 06:38:26 spz Exp $        */
2
/*        $NetBSD: bufferevent_compat.h,v 1.1.1.2 2015/01/29 06:38:26 spz Exp $        */
3
/*
4
 * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson
5
 * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. The name of the author may not be used to endorse or promote products
17
 *    derived from this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
#ifndef _EVENT2_BUFFEREVENT_COMPAT_H_
31
#define _EVENT2_BUFFEREVENT_COMPAT_H_
32
33
#define evbuffercb bufferevent_data_cb
34
#define everrorcb bufferevent_event_cb
35
36
/**
37
  Create a new bufferevent for an fd.
38

39
  This function is deprecated.  Use bufferevent_socket_new and
40
  bufferevent_set_callbacks instead.
41

42
  Libevent provides an abstraction on top of the regular event callbacks.
43
  This abstraction is called a buffered event.  A buffered event provides
44
  input and output buffers that get filled and drained automatically.  The
45
  user of a buffered event no longer deals directly with the I/O, but
46
  instead is reading from input and writing to output buffers.
47

48
  Once initialized, the bufferevent structure can be used repeatedly with
49
  bufferevent_enable() and bufferevent_disable().
50

51
  When read enabled the bufferevent will try to read from the file descriptor
52
  and call the read callback.  The write callback is executed whenever the
53
  output buffer is drained below the write low watermark, which is 0 by
54
  default.
55

56
  If multiple bases are in use, bufferevent_base_set() must be called before
57
  enabling the bufferevent for the first time.
58

59
  @deprecated This function is deprecated because it uses the current
60
    event base, and as such can be error prone for multithreaded programs.
61
    Use bufferevent_socket_new() instead.
62

63
  @param fd the file descriptor from which data is read and written to.
64
         This file descriptor is not allowed to be a pipe(2).
65
  @param readcb callback to invoke when there is data to be read, or NULL if
66
         no callback is desired
67
  @param writecb callback to invoke when the file descriptor is ready for
68
         writing, or NULL if no callback is desired
69
  @param errorcb callback to invoke when there is an error on the file
70
         descriptor
71
  @param cbarg an argument that will be supplied to each of the callbacks
72
         (readcb, writecb, and errorcb)
73
  @return a pointer to a newly allocated bufferevent struct, or NULL if an
74
          error occurred
75
  @see bufferevent_base_set(), bufferevent_free()
76
  */
77
struct bufferevent *bufferevent_new(evutil_socket_t fd,
78
    evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
79
80
81
/**
82
  Set the read and write timeout for a buffered event.
83

84
  @param bufev the bufferevent to be modified
85
  @param timeout_read the read timeout
86
  @param timeout_write the write timeout
87
 */
88
void bufferevent_settimeout(struct bufferevent *bufev,
89
    int timeout_read, int timeout_write);
90
91
#define EVBUFFER_READ                BEV_EVENT_READING
92
#define EVBUFFER_WRITE                BEV_EVENT_WRITING
93
#define EVBUFFER_EOF                BEV_EVENT_EOF
94
#define EVBUFFER_ERROR                BEV_EVENT_ERROR
95
#define EVBUFFER_TIMEOUT        BEV_EVENT_TIMEOUT
96
97
/** macro for getting access to the input buffer of a bufferevent */
98
#define EVBUFFER_INPUT(x)        bufferevent_get_input(x)
99
/** macro for getting access to the output buffer of a bufferevent */
100
#define EVBUFFER_OUTPUT(x)        bufferevent_get_output(x)
101
102
#endif