Skip to content

Commit cf17ccf

Browse files
committed
restapi: add metrics
Signed-off-by: He Xian <hexian000@outlook.com>
1 parent edd83bd commit cf17ccf

15 files changed

Lines changed: 610 additions & 264 deletions

File tree

m.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ case "$1" in
160160
-DENABLE_SANITIZERS=ON \
161161
..
162162
cp compile_commands.json ../
163-
cmake --build .
164-
ctest
163+
cmake --build . -j"$(nproc)"
164+
ctest -j"$(nproc)"
165165
ls -lh bin/neosocksd
166166
;;
167167
*)

src/api_client.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ static void api_client_finish(
118118

119119
static void on_http_client_done(
120120
struct ev_loop *loop, void *data, const char *errmsg,
121-
const size_t errlen, struct http_parser *parser)
121+
const size_t errlen, struct http_conn *conn)
122122
{
123123
struct api_client_ctx *restrict ctx = data;
124124

125125
if (errmsg != NULL) {
126126
api_client_finish(loop, ctx, errmsg, errlen, NULL);
127127
return;
128128
}
129-
ASSERT(parser != NULL);
130-
struct vbuffer *content = parser->cbuf;
131-
parser->cbuf = NULL;
129+
ASSERT(conn != NULL);
130+
struct vbuffer *content = conn->cbuf;
131+
conn->cbuf = NULL;
132132

133-
const struct http_message *restrict msg = &parser->msg;
133+
const struct http_message *restrict msg = &conn->msg;
134134
uint16_t code = 0;
135135
{
136136
const uintmax_t status = strtoumax(msg->rsp.code, NULL, 10);
@@ -146,13 +146,13 @@ static void on_http_client_done(
146146
return;
147147
}
148148
/* rpcall: validate content type */
149-
if (!check_rpcall_mime(parser->hdr.content.type)) {
149+
if (!check_rpcall_mime(conn->hdr.content.type)) {
150150
VBUF_FREE(content);
151151
API_RETURN_ERROR(loop, ctx, "unsupported content-type");
152152
}
153153
} else if (
154154
content != NULL && VBUF_LEN(content) > 0 &&
155-
check_rpcall_mime(parser->hdr.content.type)) {
155+
check_rpcall_mime(conn->hdr.content.type)) {
156156
/* Server returned structured error in RPC format */
157157
ctx->result.content = content;
158158
api_client_finish(
@@ -190,7 +190,7 @@ static void on_http_client_done(
190190

191191
struct stream *r = content_reader(
192192
VBUF_DATA(content), VBUF_LEN(content),
193-
parser->hdr.content.encoding);
193+
conn->hdr.content.encoding);
194194
if (r == NULL) {
195195
LOGOOM();
196196
VBUF_FREE(content);
@@ -202,7 +202,7 @@ static void on_http_client_done(
202202
}
203203

204204
static bool make_request(
205-
struct http_parser *restrict p, const char *restrict uri,
205+
struct http_conn *restrict p, const char *restrict uri,
206206
const void *restrict content, const size_t len)
207207
{
208208
/* Compress large payloads to reduce traffic */
@@ -245,7 +245,7 @@ static bool parse_header(void *ctx, const char *key, char *value)
245245
{
246246
struct api_client_ctx *restrict c = ctx;
247247
ASSERT(c->hctx.state != STATE_CLIENT_INIT);
248-
struct http_parser *restrict p = &c->hctx.parser;
248+
struct http_conn *restrict p = &c->hctx.conn;
249249

250250
/* hop-by-hop headers */
251251
if (strcasecmp(key, "Transfer-Encoding") == 0) {
@@ -294,7 +294,7 @@ static bool api_client_do(
294294
.data = ctx,
295295
};
296296
http_client_init(&ctx->hctx, loop, on_header, &hcb, conf, resolver);
297-
if (!make_request(&ctx->hctx.parser, uri, payload, len)) {
297+
if (!make_request(&ctx->hctx.conn, uri, payload, len)) {
298298
LOGOOM();
299299
dialreq_free(req);
300300
free(ctx);

0 commit comments

Comments
 (0)