root/src/stratcon_jlog_streamer.h

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

closes #170

  • 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   eventer_t e;
63
64   eventer_func_t consumer_callback;
65   void (*consumer_free)(void *);
66   void *consumer_ctx;
67 } noit_connection_ctx_t;
68
69 typedef struct jlog_streamer_ctx_t {
70   u_int32_t jlog_feed_cmd;
71   int bytes_expected;
72   int bytes_read;
73   char *buffer;         /* These guys are for doing partial reads */
74
75   enum {
76     JLOG_STREAMER_WANT_INITIATE = 0,
77     JLOG_STREAMER_WANT_COUNT = 1,
78     JLOG_STREAMER_WANT_HEADER = 2,
79     JLOG_STREAMER_WANT_BODY = 3,
80     JLOG_STREAMER_IS_ASYNC = 4,
81     JLOG_STREAMER_WANT_CHKPT = 5,
82     JLOG_STREAMER_WANT_ERROR = 6,
83   } state;
84   int count;            /* Number of jlog messages we need to read */
85   struct {
86     jlog_id   chkpt;
87     u_int32_t tv_sec;
88     u_int32_t tv_usec;
89     u_int32_t message_len;
90   } header;
91
92   u_int64_t total_events;
93   u_int64_t total_bytes_read;
94
95   void (*push)(stratcon_datastore_op_t, struct sockaddr *, const char *, void *, eventer_t);
96 } jlog_streamer_ctx_t;
97
98 API_EXPORT(void)
99   stratcon_jlog_streamer_init(const char *toplevel);
100 API_EXPORT(void)
101   stratcon_jlog_streamer_reload(const char *toplevel);
102 API_EXPORT(int)
103   stratcon_jlog_recv_handler(eventer_t e, int mask, void *closure,
104                              struct timeval *now);
105 API_EXPORT(jlog_streamer_ctx_t *)
106   stratcon_jlog_streamer_ctx_alloc(void);
107 API_EXPORT(void)
108   jlog_streamer_ctx_free(void *cl);
109 API_EXPORT(void)
110   noit_connection_ctx_dealloc(noit_connection_ctx_t *ctx);
111 API_EXPORT(void)
112   stratcon_streamer_connection(const char *toplevel, const char *destination,
113                                eventer_func_t handler,
114                                void *(*handler_alloc)(void), void *handler_ctx,
115                                void (*handler_free)(void *));
116
117 #endif
Note: See TracBrowser for help on using the browser.