bufferevent_compat.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson
  3. * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. The name of the author may not be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #ifndef EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_
  29. #define EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_
  30. #include <event2/visibility.h>
  31. #define evbuffercb bufferevent_data_cb
  32. #define everrorcb bufferevent_event_cb
  33. /**
  34. Create a new bufferevent for an fd.
  35. This function is deprecated. Use bufferevent_socket_new and
  36. bufferevent_set_callbacks instead.
  37. Libevent provides an abstraction on top of the regular event callbacks.
  38. This abstraction is called a buffered event. A buffered event provides
  39. input and output buffers that get filled and drained automatically. The
  40. user of a buffered event no longer deals directly with the I/O, but
  41. instead is reading from input and writing to output buffers.
  42. Once initialized, the bufferevent structure can be used repeatedly with
  43. bufferevent_enable() and bufferevent_disable().
  44. When read enabled the bufferevent will try to read from the file descriptor
  45. and call the read callback. The write callback is executed whenever the
  46. output buffer is drained below the write low watermark, which is 0 by
  47. default.
  48. If multiple bases are in use, bufferevent_base_set() must be called before
  49. enabling the bufferevent for the first time.
  50. @deprecated This function is deprecated because it uses the current
  51. event base, and as such can be error prone for multithreaded programs.
  52. Use bufferevent_socket_new() instead.
  53. @param fd the file descriptor from which data is read and written to.
  54. This file descriptor is not allowed to be a pipe(2).
  55. @param readcb callback to invoke when there is data to be read, or NULL if
  56. no callback is desired
  57. @param writecb callback to invoke when the file descriptor is ready for
  58. writing, or NULL if no callback is desired
  59. @param errorcb callback to invoke when there is an error on the file
  60. descriptor
  61. @param cbarg an argument that will be supplied to each of the callbacks
  62. (readcb, writecb, and errorcb)
  63. @return a pointer to a newly allocated bufferevent struct, or NULL if an
  64. error occurred
  65. @see bufferevent_base_set(), bufferevent_free()
  66. */
  67. EVENT2_EXPORT_SYMBOL
  68. struct bufferevent *bufferevent_new(evutil_socket_t fd,
  69. evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
  70. /**
  71. Set the read and write timeout for a buffered event.
  72. @param bufev the bufferevent to be modified
  73. @param timeout_read the read timeout
  74. @param timeout_write the write timeout
  75. */
  76. EVENT2_EXPORT_SYMBOL
  77. void bufferevent_settimeout(struct bufferevent *bufev,
  78. int timeout_read, int timeout_write);
  79. #define EVBUFFER_READ BEV_EVENT_READING
  80. #define EVBUFFER_WRITE BEV_EVENT_WRITING
  81. #define EVBUFFER_EOF BEV_EVENT_EOF
  82. #define EVBUFFER_ERROR BEV_EVENT_ERROR
  83. #define EVBUFFER_TIMEOUT BEV_EVENT_TIMEOUT
  84. /** macro for getting access to the input buffer of a bufferevent */
  85. #define EVBUFFER_INPUT(x) bufferevent_get_input(x)
  86. /** macro for getting access to the output buffer of a bufferevent */
  87. #define EVBUFFER_OUTPUT(x) bufferevent_get_output(x)
  88. #endif