static void pm_norepeat_data_available(nx_module_t *module) { nx_logdata_t *logdata; nx_pm_norepeat_conf_t *modconf; log_debug("nx_pm_norepeat_data_available()"); modconf = (nx_pm_norepeat_conf_t *) module->config; if ( nx_module_get_status(module) != NX_MODULE_STATUS_RUNNING ) { log_debug("module %s not running, not processing any more data", module->name); return; } if ( (logdata = nx_module_logqueue_peek(module)) == NULL ) { return; } logdata = pm_norepeat_process(module, logdata); // add logdata to the next modules' queue if ( logdata != NULL ) { nx_module_progress_logdata(module, logdata); } }
static void im_ssl_event(nx_module_t *module, nx_event_t *event) { nx_module_input_t *input = NULL; ASSERT(event != NULL); switch ( event->type ) { case NX_EVENT_READ: im_ssl_read(module, event); break; case NX_EVENT_WRITE: im_ssl_write(module, event); break; case NX_EVENT_DISCONNECT: CHECKERR_MSG(apr_socket_data_get((void **) &input, "input", (apr_socket_t *) event->data), "couldn't get input data from socket"); im_ssl_disconnect(input); break; case NX_EVENT_POLL: if ( nx_module_get_status(module) == NX_MODULE_STATUS_RUNNING ) { nx_module_pollset_poll(module, TRUE); } break; default: nx_panic("invalid event type: %d", event->type); } }
static void om_kafka_write(nx_module_t *module) { nx_om_kafka_conf_t* modconf; modconf = (nx_om_kafka_conf_t*) module->config; nx_logdata_t *logdata; if (nx_module_get_status(module) != NX_MODULE_STATUS_RUNNING) { log_warn("Kafka module not running."); return; } if (module->output.buflen == 0) { if ((logdata = nx_module_logqueue_peek(module)) != NULL) { module->output.logdata = logdata; if (rd_kafka_produce(modconf->rkt, modconf->partition, RD_KAFKA_MSG_F_COPY, /* Payload and length */ logdata->raw_event->buf, (int) logdata->raw_event->len, /* Optional key and its length */ NULL, 0, /* Message opaque, provided in delivery report callback as msg_opaque. */ NULL) == -1) { log_error("Unable to produce message"); rd_kafka_poll(modconf->rk, 0); } else { //TODO: report on message log_debug("Message sent"); rd_kafka_poll(modconf->rk, 0); nx_module_logqueue_pop(module, module->output.logdata); nx_logdata_free(module->output.logdata); module->output.logdata = NULL; } } } }
static void im_tcp_resume(nx_module_t *module) { if ( nx_module_get_status(module) != NX_MODULE_STATUS_STOPPED ) { nx_module_pollset_poll(module, TRUE); } }
static void im_ssl_read(nx_module_t *module, nx_event_t *event) { nx_im_ssl_conf_t *imconf; nx_logdata_t *logdata; apr_socket_t *sock; nx_module_input_t *input = NULL; char *ipstr; nx_exception_t e; boolean disconnect; ASSERT(module != NULL); ASSERT(event != NULL); log_debug("im_ssl_read"); if ( nx_module_get_status(module) != NX_MODULE_STATUS_RUNNING ) { log_debug("module %s not running, not reading any more data", module->name); return; } imconf = (nx_im_ssl_conf_t *) module->config; sock = (apr_socket_t *) event->data; ASSERT(imconf->listensock != NULL); if ( sock == imconf->listensock ) { im_ssl_accept(module); return; } //else we have data from a client connection CHECKERR_MSG(apr_socket_data_get((void **) &input, "input", sock), "couldn't get input data from socket"); ASSERT(input != NULL); // if this is null there is a race/double free in event handling disconnect = im_ssl_fill_buffer(module, input); try { while ( (logdata = input->inputfunc->func(input, input->inputfunc->data)) != NULL ) { //log_debug("read: [%s]", logdata->data); ipstr = nx_module_input_data_get(input, "recv_from_str"); nx_logdata_set_string(logdata, "MessageSourceAddress", ipstr); nx_module_add_logdata_input(module, input, logdata); } } catch(e) { im_ssl_free_input(input); rethrow_msg(e, "Module %s couldn't read the input", input->module->name); } if ( disconnect == TRUE ) { im_ssl_disconnect(input); } }
static void im_ssl_resume(nx_module_t *module) { if ( nx_module_get_status(module) != NX_MODULE_STATUS_STOPPED ) { nx_module_add_poll_event(module); //we could directly go to poll here } }
static void im_exec_read(nx_module_t *module) { nx_logdata_t *logdata; nx_im_exec_conf_t *imconf; int evcnt = 0; ASSERT(module != NULL); imconf = (nx_im_exec_conf_t *) module->config; imconf->event = NULL; if ( nx_module_get_status(module) != NX_MODULE_STATUS_RUNNING ) { log_debug("module %s is not running, not reading any more data", module->name); return; } im_exec_fill_buffer(&(module->input)); while ( (logdata = module->input.inputfunc->func(&(module->input), module->input.inputfunc->data)) != NULL ) { nx_module_add_logdata_input(module, &(module->input), logdata); evcnt++; } #ifdef WIN32 if ( nx_module_get_status(module) == NX_MODULE_STATUS_RUNNING ) { if ( imconf->event == NULL ) { if ( evcnt == 0 ) { im_exec_add_read_event(module, (int) (APR_USEC_PER_SEC * IM_EXEC_DEFAULT_POLL_INTERVAL)); } else { im_exec_add_read_event(module, 0); } } } #endif }
static void im_exec_event(nx_module_t *module, nx_event_t *event) { nx_im_exec_conf_t *imconf; nx_exception_t e; ASSERT(event != NULL); imconf = (nx_im_exec_conf_t *) module->config; switch ( event->type ) { case NX_EVENT_DISCONNECT: // FIXME: restart if imconf->restart == TRUE log_warn("im_exec process %s exited", imconf->cmd); imconf->running = FALSE; im_exec_add_restart_event(module); break; case NX_EVENT_READ: try { im_exec_read(module); } catch(e) { log_exception(e); im_exec_add_restart_event(module); } break; case NX_EVENT_POLL: #ifdef WIN32 nx_panic("pollset based im_exec implementation doesn't work on windows"); #else if ( nx_module_get_status(module) == NX_MODULE_STATUS_RUNNING ) { nx_module_pollset_poll(module, TRUE); } break; #endif default: nx_panic("invalid event type: %d", event->type); } }
static void im_tcp_event(nx_module_t *module, nx_event_t *event) { ASSERT(event != NULL); switch ( event->type ) { case NX_EVENT_READ: im_tcp_read(module, event); break; case NX_EVENT_DISCONNECT: im_tcp_got_disconnect(module, event); break; case NX_EVENT_POLL: if ( nx_module_get_status(module) == NX_MODULE_STATUS_RUNNING ) { nx_module_pollset_poll(module, TRUE); } break; default: nx_panic("invalid event type: %d", event->type); } }
static void om_kafka_event(nx_module_t *module, nx_event_t *event) { log_debug("Kafka module event entrypoint"); nx_exception_t e; ASSERT(module != NULL); ASSERT(event != NULL); nx_om_kafka_conf_t* modconf; modconf = (nx_om_kafka_conf_t*) module->config; switch (event->type) { case NX_EVENT_DATA_AVAILABLE: log_debug("Output buflen: %d, bufstart: %d", (int) module->output.buflen, (int) module->output.bufstart); try { om_kafka_write(module); } catch (e) { io_err_handler(module, &e); } break; case NX_EVENT_READ: break; case NX_EVENT_WRITE: break; case NX_EVENT_RECONNECT: break; case NX_EVENT_DISCONNECT: break; case NX_EVENT_TIMEOUT: break; case NX_EVENT_POLL: if (nx_module_get_status(module) == NX_MODULE_STATUS_RUNNING) { nx_module_pollset_poll(module, FALSE); } break; default: nx_panic("invalid event type: %d", event->type); } }
static void im_tcp_read(nx_module_t *module, nx_event_t *event) { nx_im_tcp_conf_t *imconf; nx_logdata_t *logdata; boolean volatile got_eof = FALSE; apr_socket_t *sock; nx_module_input_t *input; apr_sockaddr_t *sa; char *ipstr; apr_status_t rv; nx_exception_t e; ASSERT(event != NULL); ASSERT(module != NULL); log_debug("im_tcp_read"); if ( nx_module_get_status(module) != NX_MODULE_STATUS_RUNNING ) { log_debug("module %s not running, not reading any more data", module->name); return; } imconf = (nx_im_tcp_conf_t *) module->config; sock = (apr_socket_t *) event->data; ASSERT(imconf->listensock != NULL); if ( sock == imconf->listensock ) { im_tcp_accept(module); return; } //else we have data from a client connection CHECKERR_MSG(apr_socket_data_get((void **) &input, "input", sock), "couldn't get input data from socket"); ASSERT(input != NULL); // if this is null there is a race/double free in event handling if ( (rv = nx_module_input_fill_buffer_from_socket(input)) != APR_SUCCESS ) { if ( APR_STATUS_IS_ECONNREFUSED(rv) || APR_STATUS_IS_ECONNABORTED(rv) || APR_STATUS_IS_ECONNRESET(rv) || APR_STATUS_IS_ETIMEDOUT(rv) || APR_STATUS_IS_TIMEUP(rv) || APR_STATUS_IS_EHOSTUNREACH(rv) || APR_STATUS_IS_ENETUNREACH(rv) || APR_STATUS_IS_EOF(rv) ) { got_eof = TRUE; } else if ( APR_STATUS_IS_EAGAIN(rv) ) { nx_module_add_poll_event(module); } else { im_tcp_free_input(input); throw(rv, "Module %s couldn't read from socket", input->module->name); } } try { while ( (logdata = input->inputfunc->func(input, input->inputfunc->data)) != NULL ) { //log_debug("read %d bytes: [%s]", (int) logdata->datalen, logdata->data); ipstr = nx_module_input_data_get(input, "recv_from_str"); nx_logdata_set_string(logdata, "MessageSourceAddress", ipstr); nx_module_add_logdata_input(module, input, logdata); } } catch(e) { im_tcp_free_input(input); rethrow_msg(e, "Module %s couldn't read the input", input->module->name); } if ( got_eof == TRUE ) { CHECKERR_MSG(apr_socket_addr_get(&sa, APR_REMOTE, input->desc.s), "couldn't get info on accepted socket"); CHECKERR_MSG(apr_sockaddr_ip_get(&ipstr, sa), "couldn't get IP of accepted socket"); log_aprwarn(rv, "TCP connection closed from %s:%u", ipstr, sa->port); im_tcp_free_input(input); } }