root/src/stratcon_jlog_streamer.h

Revision 1da42f7ee53fe062b95962b97d885d16c7363589, 4.0 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

fixes #202 flag-day(noitd,stratcond)

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _STRATCON_LOG_STREAMER_H
34 #define _STRATCON_LOG_STREAMER_H
35
36 #include "noit_conf.h"
37 #include "utils/noit_atomic.h"
38 #include "jlog/jlog.h"
39 #include <netinet/in.h>
40 #include <sys/un.h>
41 #include <arpa/inet.h>
42 #include "stratcon_datastore.h"
43
44 typedef struct noit_connection_ctx_t {
45   noit_atomic32_t refcnt;
46   union {
47     struct sockaddr remote;
48     struct sockaddr_un remote_un;
49     struct sockaddr_in remote_in;
50     struct sockaddr_in6 remote_in6;
51   } r;
52   socklen_t remote_len;
53   char *remote_str;
54   char *remote_cn;
55   u_int32_t current_backoff;
56   int wants_shutdown;
57   int wants_permanent_shutdown;
58   noit_hash_table *config;
59   noit_hash_table *sslconfig;
60   struct timeval last_connect;
61   eventer_t timeout_event;
62
63   eventer_func_t consumer_callback;
64   void (*consumer_free)(void *);
65   void *consumer_ctx;
66 } noit_connection_ctx_t;
67
68 typedef struct jlog_streamer_ctx_t {
69   u_int32_t jlog_feed_cmd;
70   int bytes_expected;
71   int bytes_read;
72   char *buffer;         /* These guys are for doing partial reads */
73
74   enum {
75     JLOG_STREAMER_WANT_INITIATE = 0,
76     JLOG_STREAMER_WANT_COUNT = 1,
77     JLOG_STREAMER_WANT_HEADER = 2,
78     JLOG_STREAMER_WANT_BODY = 3,
79     JLOG_STREAMER_IS_ASYNC = 4,
80     JLOG_STREAMER_WANT_CHKPT = 5,
81     JLOG_STREAMER_WANT_ERROR = 6,
82   } state;
83   int count;            /* Number of jlog messages we need to read */
84   struct {
85     jlog_id   chkpt;
86     u_int32_t tv_sec;
87     u_int32_t tv_usec;
88     u_int32_t message_len;
89   } header;
90
91   u_int64_t total_events;
92   u_int64_t total_bytes_read;
93
94   void (*push)(stratcon_datastore_op_t, struct sockaddr *, const char *, void *, eventer_t);
95 } jlog_streamer_ctx_t;
96
97 API_EXPORT(void)
98   stratcon_jlog_streamer_init(const char *toplevel);
99 API_EXPORT(void)
100   stratcon_jlog_streamer_reload(const char *toplevel);
101 API_EXPORT(int)
102   stratcon_jlog_recv_handler(eventer_t e, int mask, void *closure,
103                              struct timeval *now);
104 API_EXPORT(jlog_streamer_ctx_t *)
105   stratcon_jlog_streamer_ctx_alloc(void);
106 API_EXPORT(void)
107   jlog_streamer_ctx_free(void *cl);
108 API_EXPORT(void)
109   noit_connection_ctx_dealloc(noit_connection_ctx_t *ctx);
110 API_EXPORT(void)
111   stratcon_streamer_connection(const char *toplevel, const char *destination,
112                                eventer_func_t handler,
113                                void *(*handler_alloc)(void), void *handler_ctx,
114                                void (*handler_free)(void *));
115
116 #endif
Note: See TracBrowser for help on using the browser.