forked from yandex/odyssey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.h
84 lines (75 loc) · 2.31 KB
/
frontend.h
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
#ifndef ODYSSEY_FRONTEND_H
#define ODYSSEY_FRONTEND_H
/*
* Odyssey.
*
* Scalable PostgreSQL connection pooler.
*/
#define MAX_STARTUP_ATTEMPTS 7
static inline machine_msg_t *od_frontend_error_msg(od_client_t *client,
machine_msg_t *stream,
char *code, char *fmt,
va_list args)
{
char msg[OD_QRY_MAX_SZ];
int msg_len;
msg_len = od_snprintf(msg, sizeof(msg),
"odyssey: %s%.*s: ", client->id.id_prefix,
(signed)sizeof(client->id.id), client->id.id);
msg_len +=
od_vsnprintf(msg + msg_len, sizeof(msg) - msg_len, fmt, args);
return kiwi_be_write_error(stream, code, msg, msg_len);
}
static inline machine_msg_t *od_frontend_fatal_msg(od_client_t *client,
machine_msg_t *stream,
char *code, char *fmt,
va_list args)
{
char msg[OD_QRY_MAX_SZ];
int msg_len;
msg_len = od_snprintf(msg, sizeof(msg),
"odyssey: %s%.*s: ", client->id.id_prefix,
(signed)sizeof(client->id.id), client->id.id);
msg_len +=
od_vsnprintf(msg + msg_len, sizeof(msg) - msg_len, fmt, args);
return kiwi_be_write_error_fatal(stream, code, msg, msg_len);
}
static inline machine_msg_t *od_frontend_errorf(od_client_t *client,
machine_msg_t *stream,
char *code, char *fmt, ...)
{
va_list args;
va_start(args, fmt);
machine_msg_t *msg;
msg = od_frontend_error_msg(client, stream, code, fmt, args);
va_end(args);
return msg;
}
static inline machine_msg_t *od_frontend_info_msg(od_client_t *client,
machine_msg_t *stream,
char *fmt, va_list args)
{
char msg[OD_QRY_MAX_SZ];
int msg_len;
msg_len = od_snprintf(msg, sizeof(msg),
"odyssey: %s%.*s: ", client->id.id_prefix,
(signed)sizeof(client->id.id), client->id.id);
msg_len +=
od_vsnprintf(msg + msg_len, sizeof(msg) - msg_len, fmt, args);
return kiwi_be_write_notice_info(stream, msg, msg_len);
}
static inline machine_msg_t *
od_frontend_infof(od_client_t *client, machine_msg_t *stream, char *fmt, ...)
{
va_list args;
va_start(args, fmt);
machine_msg_t *msg;
msg = od_frontend_info_msg(client, stream, fmt, args);
va_end(args);
return msg;
}
int od_frontend_info(od_client_t *, char *, ...);
int od_frontend_error(od_client_t *, char *, char *, ...);
int od_frontend_fatal(od_client_t *, char *, char *, ...);
void od_frontend(void *);
#endif /* ODYSSEY_FRONTEND_H */