mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 06:51:04 +08:00
Add mg_ws_printf()
This commit is contained in:
parent
219428c249
commit
cac7f653c9
18
mongoose.c
18
mongoose.c
@ -5702,6 +5702,24 @@ struct ws_msg {
|
||||
size_t data_len;
|
||||
};
|
||||
|
||||
size_t mg_ws_vprintf(struct mg_connection *c, int op, const char *fmt,
|
||||
va_list ap) {
|
||||
char mem[256], *buf = mem;
|
||||
size_t len = mg_vasprintf(&buf, sizeof(mem), fmt, ap);
|
||||
len = mg_ws_send(c, buf, len, op);
|
||||
if (buf != mem) free(buf);
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t mg_ws_printf(struct mg_connection *c, int op, const char *fmt, ...) {
|
||||
size_t len = 0;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
len = mg_ws_vprintf(c, op, fmt, ap);
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
static void ws_handshake(struct mg_connection *c, const struct mg_str *wskey,
|
||||
const struct mg_str *wsproto, const char *fmt,
|
||||
va_list ap) {
|
||||
|
@ -1178,6 +1178,8 @@ void mg_ws_upgrade(struct mg_connection *, struct mg_http_message *,
|
||||
const char *fmt, ...);
|
||||
size_t mg_ws_send(struct mg_connection *, const char *buf, size_t len, int op);
|
||||
size_t mg_ws_wrap(struct mg_connection *, size_t len, int op);
|
||||
size_t mg_ws_printf(struct mg_connection *c, int op, const char *fmt, ...);
|
||||
size_t mg_ws_vprintf(struct mg_connection *c, int op, const char *fmt, va_list);
|
||||
|
||||
|
||||
|
||||
|
18
src/ws.c
18
src/ws.c
@ -13,6 +13,24 @@ struct ws_msg {
|
||||
size_t data_len;
|
||||
};
|
||||
|
||||
size_t mg_ws_vprintf(struct mg_connection *c, int op, const char *fmt,
|
||||
va_list ap) {
|
||||
char mem[256], *buf = mem;
|
||||
size_t len = mg_vasprintf(&buf, sizeof(mem), fmt, ap);
|
||||
len = mg_ws_send(c, buf, len, op);
|
||||
if (buf != mem) free(buf);
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t mg_ws_printf(struct mg_connection *c, int op, const char *fmt, ...) {
|
||||
size_t len = 0;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
len = mg_ws_vprintf(c, op, fmt, ap);
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
static void ws_handshake(struct mg_connection *c, const struct mg_str *wskey,
|
||||
const struct mg_str *wsproto, const char *fmt,
|
||||
va_list ap) {
|
||||
|
2
src/ws.h
2
src/ws.h
@ -21,3 +21,5 @@ void mg_ws_upgrade(struct mg_connection *, struct mg_http_message *,
|
||||
const char *fmt, ...);
|
||||
size_t mg_ws_send(struct mg_connection *, const char *buf, size_t len, int op);
|
||||
size_t mg_ws_wrap(struct mg_connection *, size_t len, int op);
|
||||
size_t mg_ws_printf(struct mg_connection *c, int op, const char *fmt, ...);
|
||||
size_t mg_ws_vprintf(struct mg_connection *c, int op, const char *fmt, va_list);
|
||||
|
Loading…
x
Reference in New Issue
Block a user