mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-14 16:49:26 +08:00
25 lines
824 B
C
25 lines
824 B
C
#include "event.h"
|
|
#include "fmt.h"
|
|
#include "log.h"
|
|
#include "net.h"
|
|
|
|
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);
|
|
}
|
|
|
|
void mg_error(struct mg_connection *c, const char *fmt, ...) {
|
|
char mem[256], *buf = mem;
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
mg_vasprintf(&buf, sizeof(mem), fmt, ap);
|
|
va_end(ap);
|
|
MG_ERROR(("%lu %p %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
|
|
if (buf != mem) free(buf);
|
|
}
|