Repository navigation
Expand file tree
/
Copy pathnetwork-injection.c
More file actions
140 lines (102 loc) · 3.14 KB
/
Copy pathnetwork-injection.c
File metadata and controls
140 lines (102 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* $%BEGINLICENSE%$
Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; version 2 of the
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
$%ENDLICENSE%$ */
#include <string.h>
#include "network-injection.h"
#include "network-mysqld-proto.h"
#include "network-mysqld-packet.h"
#include "glib-ext.h"
#include "lua-env.h"
#include "chassis-timings.h"
#define C(x) x, sizeof(x) - 1
#define S(x) x->str, x->len
#define TIME_DIFF_US(t2, t1) \
((t2.tv_sec - t1.tv_sec) * 1000000.0 + (t2.tv_usec - t1.tv_usec))
/**
* Initialize an injection struct.
*/
injection *injection_new(int id, GString *query) {
injection *i;
i = g_new0(injection, 1);
i->id = id;
i->query = query;
i->resultset_is_needed = FALSE; /* don't buffer the resultset */
/**
* we have to assume that injection_new() is only used by the read_query call
* which should be fine
*/
i->ts_read_query = chassis_get_rel_microseconds();
/* g_get_current_time(&(i->ts_read_query)); */
return i;
}
/**
* Free an injection struct
*/
void injection_free(injection *i) {
if (!i) return;
if (i->query) g_string_free(i->query, TRUE);
g_free(i);
}
network_injection_queue *network_injection_queue_new() {
return g_queue_new();
}
void network_injection_queue_free(network_injection_queue *q) {
if (!q) return;
network_injection_queue_reset(q);
g_queue_free(q);
}
void network_injection_queue_reset(network_injection_queue *q) {
injection *inj;
if (!q) return;
while ((inj = g_queue_pop_head(q))) injection_free(inj);
}
void network_injection_queue_append(network_injection_queue *q, injection *inj) {
g_queue_push_tail(q, inj);
}
void network_injection_queue_prepend(network_injection_queue *q, injection *inj) {
g_queue_push_head(q, inj);
}
guint network_injection_queue_len(network_injection_queue *q) {
return q->length;
}
NETWORK_API injection* network_injection_queue_peek_head(network_injection_queue *q) {
return g_queue_peek_head(q);
}
/**
* Initialize a resultset struct
*/
proxy_resultset_t *proxy_resultset_init() {
return proxy_resultset_new();
}
void proxy_resultset_init1(proxy_resultset_t* resultset, injection* inj) {
resultset->qstat = inj->qstat;
resultset->rows = inj->rows;
resultset->bytes = inj->bytes;
}
proxy_resultset_t *proxy_resultset_new() {
proxy_resultset_t *res;
res = g_new0(proxy_resultset_t, 1);
return res;
}
/**
* Free a resultset struct
*/
void proxy_resultset_free(proxy_resultset_t *res) {
if (!res) return;
if (res->fields) {
network_mysqld_proto_fielddefs_free(res->fields);
}
g_free(res);
}