2596954-http.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. commit 26d7a4430dbf9c9c6fa4efaf06c22bdf447f07b7
  2. author: aozeritsky
  3. date: 2016-12-19T19:47:17+03:00
  4. revision: 2596954
  5. [LOGBROKER-2064] apply https patches
  6. --- libevent/http-internal.h (index)
  7. +++ libevent/http-internal.h (working tree)
  8. @@ -13,6 +13,7 @@
  9. #include "event2/event_struct.h"
  10. #include "util-internal.h"
  11. #include "defer-internal.h"
  12. +#include "event2/http.h"
  13. #define HTTP_CONNECT_TIMEOUT 45
  14. #define HTTP_WRITE_TIMEOUT 50
  15. @@ -55,6 +56,8 @@ struct evhttp_connection {
  16. evutil_socket_t fd;
  17. struct bufferevent *bufev;
  18. + bev_factory_cb bufcb;
  19. + void *bufcb_arg;
  20. struct event retry_ev; /* for retrying connects */
  21. --- libevent/http.c (index)
  22. +++ libevent/http.c (working tree)
  23. @@ -1355,6 +1355,23 @@ evhttp_connection_reset_(struct evhttp_connection *evcon)
  24. if (evhttp_connected(evcon) && evcon->closecb != NULL)
  25. (*evcon->closecb)(evcon, evcon->closecb_arg);
  26. + /* if we have a bufferevent factory callback set, get a new bufferevent */
  27. + if (NULL != evcon->bufcb && -1 != bufferevent_getfd(evcon->bufev)) {
  28. + struct bufferevent *bev = (*evcon->bufcb)(evcon->bufcb_arg);
  29. +
  30. + if (NULL == bev) {
  31. + event_warn("%s: bufferevent factory callback failed", __func__);
  32. + }
  33. + else {
  34. + if (bufferevent_get_base(bev) != evcon->base) {
  35. + bufferevent_base_set(evcon->base, bev);
  36. + }
  37. +
  38. + bufferevent_free(evcon->bufev);
  39. + evcon->bufev = bev;
  40. + }
  41. + }
  42. +
  43. shutdown(evcon->fd, EVUTIL_SHUT_WR);
  44. evutil_closesocket(evcon->fd);
  45. evcon->fd = -1;
  46. @@ -2376,6 +2393,30 @@ evhttp_read_header(struct evhttp_connection *evcon,
  47. * happen elsewhere.
  48. */
  49. +struct evhttp_connection *evhttp_connection_base_bufferevent_factory_new(
  50. + struct event_base *base, struct evdns_base *dnsbase,
  51. + bev_factory_cb cb, void * arg, const char *address, unsigned short port)
  52. +{
  53. + struct bufferevent *bev = NULL;
  54. +
  55. + if (NULL != cb) {
  56. + if (NULL == (bev = (*cb)(arg))) {
  57. + event_warn("%s: bufferevent factory callback failed", __func__);
  58. + return (NULL);
  59. + }
  60. + }
  61. +
  62. + struct evhttp_connection *ret =
  63. + evhttp_connection_base_bufferevent_new(base, dnsbase, bev, address, port);
  64. +
  65. + if (NULL != ret) {
  66. + ret->bufcb = cb;
  67. + ret->bufcb_arg = arg;
  68. + }
  69. +
  70. + return (ret);
  71. +}
  72. +
  73. struct evhttp_connection *
  74. evhttp_connection_new(const char *address, ev_uint16_t port)
  75. {
  76. --- libevent/include/event2/http.h (index)
  77. +++ libevent/include/event2/http.h (working tree)
  78. @@ -234,6 +234,9 @@ EVENT2_EXPORT_SYMBOL
  79. void evhttp_set_default_content_type(struct evhttp *http,
  80. const char *content_type);
  81. +void evhttp_set_bevcb(struct evhttp *http,
  82. + struct bufferevent* (*cb)(struct event_base *, void *), void *arg);
  83. +
  84. /**
  85. Sets the what HTTP methods are supported in requests accepted by this
  86. server, and passed to user callbacks.
  87. @@ -392,6 +395,11 @@ int evhttp_set_flags(struct evhttp *http, int flags);
  88. /* Request/Response functionality */
  89. +struct evhttp_connection *evhttp_connection_base_bufferevent_new(
  90. + struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, unsigned short port);
  91. +
  92. +struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon);
  93. +
  94. /**
  95. * Send an HTML error message to the client.
  96. *
  97. @@ -528,6 +536,38 @@ struct evhttp_connection *evhttp_connection_base_bufferevent_new(
  98. struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, ev_uint16_t port);
  99. /**
  100. + * Creates and returns a new bufferevent object.
  101. + */
  102. +typedef struct bufferevent* (*bev_factory_cb)(void *);
  103. +
  104. +/**
  105. + * Create and return a connection object that can be used for making HTTP
  106. + * requests. The connection object tries to resolve address and establish the
  107. + * connection when it is given an http request object. The specified factory
  108. + * function is called with the user-supplied argument to retrieve a new
  109. + * bufferevent whenever the underlying HTTP connection needs to be
  110. + * reestablished. This is what you want if, for example, you have a bufferevent
  111. + * that needs to perform some setup for new connections, such as an SSL
  112. + * bufferevent.
  113. + *
  114. + * @param base the event_base to use for handling the connection
  115. + * @param dnsbase the dns_base to use for resolving host names; if not
  116. + * specified host name resolution will block.
  117. + * @param cb a callback that returns a new bufferevent to use for connecting to
  118. + * the server; if NULL, behavior is the same as in calling
  119. + * evhttp_connection_base_bufferevent_new with a NULL bufferevent. The
  120. + * returned bufferevents will be freed as necessary. The returned
  121. + * bufferevents must have no fd set on them.
  122. + * @param arg the argument to supply to the callback
  123. + * @param address the address to which to connect
  124. + * @param port the port to connect to
  125. + * @return an evhttp_connection object that can be used for making requests
  126. + */
  127. +struct evhttp_connection *evhttp_connection_base_bufferevent_factory_new(
  128. + struct event_base *base, struct evdns_base *dnsbase,
  129. + bev_factory_cb cb, void * arg, const char *address, unsigned short port);
  130. +
  131. +/**
  132. * Return the bufferevent that an evhttp_connection is using.
  133. */
  134. EVENT2_EXPORT_SYMBOL