mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-20 11:19:56 +00:00
remove fn_data from event handler signature
This commit is contained in:
1 parent
b8bfa5565b
commit
deca1aaf46
77 files changed
+2839
-2259
No files matched your search
@@ -134,8 +134,7 @@ bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *dm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dns_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data) {
|
||||
static void dns_cb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
struct dns_data *d, *tmp;
|
||||
struct dns_data **head = (struct dns_data **) &c->mgr->active_dns_requests;
|
||||
if (ev == MG_EV_POLL) {
|
||||
@@ -189,7 +188,6 @@ static void dns_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
mg_dns_free(head, d);
|
||||
}
|
||||
}
|
||||
(void) fn_data;
|
||||
}
|
||||
|
||||
static bool mg_dns_send(struct mg_connection *c, const struct mg_str *name,
|
||||
|
||||
+3
-3
@@ -19,8 +19,8 @@ void mg_call(struct mg_connection *c, int ev, void *ev_data) {
|
||||
// Run user-defined handler first, in order to give it an ability
|
||||
// to intercept processing (e.g. clean input buffer) before the
|
||||
// protocol handler kicks in
|
||||
if (c->fn != NULL) c->fn(c, ev, ev_data, c->fn_data);
|
||||
if (c->pfn != NULL) c->pfn(c, ev, ev_data, c->pfn_data);
|
||||
if (c->fn != NULL) c->fn(c, ev, ev_data);
|
||||
if (c->pfn != NULL) c->pfn(c, ev, ev_data);
|
||||
}
|
||||
|
||||
void mg_error(struct mg_connection *c, const char *fmt, ...) {
|
||||
@@ -31,5 +31,5 @@ void mg_error(struct mg_connection *c, const char *fmt, ...) {
|
||||
va_end(ap);
|
||||
MG_ERROR(("%lu %ld %s", c->id, c->fd, buf));
|
||||
c->is_closing = 1; // Set is_closing before sending MG_EV_CALL
|
||||
mg_call(c, MG_EV_ERROR, buf); // Let user handler to override it
|
||||
mg_call(c, MG_EV_ERROR, buf); // Let user handler override it
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
struct mg_connection;
|
||||
typedef void (*mg_event_handler_t)(struct mg_connection *, int ev,
|
||||
void *ev_data, void *fn_data);
|
||||
void *ev_data);
|
||||
void mg_call(struct mg_connection *c, int ev, void *ev_data);
|
||||
void mg_error(struct mg_connection *c, const char *fmt, ...);
|
||||
|
||||
|
||||
+8
-9
@@ -1,7 +1,7 @@
|
||||
#include "http.h"
|
||||
#include "arch.h"
|
||||
#include "base64.h"
|
||||
#include "fmt.h"
|
||||
#include "http.h"
|
||||
#include "json.h"
|
||||
#include "log.h"
|
||||
#include "net.h"
|
||||
@@ -431,7 +431,7 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers,
|
||||
c->is_resp = 0;
|
||||
}
|
||||
|
||||
static void http_cb(struct mg_connection *, int, void *, void *);
|
||||
static void http_cb(struct mg_connection *, int, void *);
|
||||
static void restore_http_cb(struct mg_connection *c) {
|
||||
mg_fs_close((struct mg_fd *) c->pfn_data);
|
||||
c->pfn_data = NULL;
|
||||
@@ -445,10 +445,9 @@ char *mg_http_etag(char *buf, size_t len, size_t size, time_t mtime) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void static_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data) {
|
||||
static void static_cb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_WRITE || ev == MG_EV_POLL) {
|
||||
struct mg_fd *fd = (struct mg_fd *) fn_data;
|
||||
struct mg_fd *fd = (struct mg_fd *) c->pfn_data;
|
||||
// Read to send IO buffer directly, avoid extra on-stack buffer
|
||||
size_t n, max = MG_IO_SIZE, space;
|
||||
size_t *cl = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
|
||||
@@ -973,7 +972,7 @@ static int skip_chunk(const char *buf, int len, int *pl, int *dl) {
|
||||
return i + 2 + n + 2;
|
||||
}
|
||||
|
||||
static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||
static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_READ || ev == MG_EV_CLOSE) {
|
||||
struct mg_http_message hm;
|
||||
size_t ofs = 0; // Parsing offset
|
||||
@@ -1035,10 +1034,10 @@ static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||
}
|
||||
if (ofs > 0) mg_iobuf_del(&c->recv, 0, ofs); // Delete processed data
|
||||
}
|
||||
(void) evd, (void) fnd;
|
||||
(void) ev_data;
|
||||
}
|
||||
|
||||
static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) {
|
||||
static void mg_hfn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
if (mg_http_match_uri(hm, "/quit")) {
|
||||
@@ -1053,7 +1052,7 @@ static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) {
|
||||
mg_http_reply(c, 200, "", "hi\n");
|
||||
}
|
||||
} else if (ev == MG_EV_CLOSE) {
|
||||
if (c->data[0] == 'X') *(bool *) fnd = true;
|
||||
if (c->data[0] == 'X') *(bool *) c->fn_data = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -410,7 +410,8 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
|
||||
}
|
||||
if (p > end) return MQTT_MALFORMED;
|
||||
if (version == 5 && p + 2 < end) {
|
||||
len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &m->props_size);
|
||||
len_len =
|
||||
(uint32_t) decode_varint(p, (size_t) (end - p), &m->props_size);
|
||||
if (!len_len) return MQTT_MALFORMED;
|
||||
m->props_start = (size_t) (p + len_len - buf);
|
||||
p += len_len + m->props_size;
|
||||
@@ -426,8 +427,7 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
|
||||
return MQTT_OK;
|
||||
}
|
||||
|
||||
static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data) {
|
||||
static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_READ) {
|
||||
for (;;) {
|
||||
uint8_t version = c->is_mqtt5 ? 5 : 4;
|
||||
@@ -495,7 +495,6 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
}
|
||||
}
|
||||
(void) ev_data;
|
||||
(void) fn_data;
|
||||
}
|
||||
|
||||
void mg_mqtt_ping(struct mg_connection *nc) {
|
||||
|
||||
+2
-3
@@ -38,7 +38,7 @@ int64_t mg_sntp_parse(const unsigned char *buf, size_t len) {
|
||||
return res;
|
||||
}
|
||||
|
||||
static void sntp_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||
static void sntp_cb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_READ) {
|
||||
int64_t milliseconds = mg_sntp_parse(c->recv.buf, c->recv.len);
|
||||
if (milliseconds > 0) {
|
||||
@@ -52,8 +52,7 @@ static void sntp_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||
mg_sntp_request(c);
|
||||
} else if (ev == MG_EV_CLOSE) {
|
||||
}
|
||||
(void) fnd;
|
||||
(void) evd;
|
||||
(void) ev_data;
|
||||
}
|
||||
|
||||
void mg_sntp_request(struct mg_connection *c) {
|
||||
|
||||
+2
-2
@@ -620,7 +620,7 @@ static bool mg_socketpair(MG_SOCKET_TYPE sp[2], union usa usa[2]) {
|
||||
}
|
||||
|
||||
// mg_wakeup() event handler
|
||||
static void wufn(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||
static void wufn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_READ) {
|
||||
unsigned long *id = (unsigned long *) c->recv.buf;
|
||||
// MG_INFO(("Got data"));
|
||||
@@ -640,7 +640,7 @@ static void wufn(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||
closesocket(c->mgr->pipe); // When we're closing, close the other
|
||||
c->mgr->pipe = MG_INVALID_SOCKET; // side of the socketpair, too
|
||||
}
|
||||
(void) evd, (void) fnd;
|
||||
(void) ev_data;
|
||||
}
|
||||
|
||||
bool mg_wakeup_init(struct mg_mgr *mgr) {
|
||||
|
||||
@@ -163,8 +163,7 @@ static bool mg_ws_client_handshake(struct mg_connection *c) {
|
||||
return false; // Continue event handler
|
||||
}
|
||||
|
||||
static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data) {
|
||||
static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
struct ws_msg msg;
|
||||
size_t ofs = (size_t) c->pfn_data;
|
||||
|
||||
@@ -230,7 +229,6 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
}
|
||||
}
|
||||
}
|
||||
(void) fn_data;
|
||||
(void) ev_data;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user