Lines Matching refs:ctx

76 static apr_status_t hm_listen(hm_ctx_t *ctx)
80 rv = apr_socket_create(&ctx->sock, ctx->mcast_addr->family,
81 SOCK_DGRAM, APR_PROTO_UDP, ctx->p);
84 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02068)
89 rv = apr_socket_opt_set(ctx->sock, APR_SO_REUSEADDR, 1);
91 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02069)
97 rv = apr_socket_opt_set(ctx->sock, APR_SO_NONBLOCK, 1);
99 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02070)
104 rv = apr_socket_bind(ctx->sock, ctx->mcast_addr);
106 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02071)
111 rv = apr_mcast_join(ctx->sock, ctx->mcast_addr, NULL, NULL);
114 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02072)
119 rv = apr_mcast_loopback(ctx->sock, 1);
121 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02073)
198 hm_slot_server_ctx_t ctx;
199 ctx.s = s;
200 ctx.found = 0;
201 storage->doall(slotmem, hm_update, &ctx, pool);
202 if (!ctx.found) {
218 hm_slot_server_ctx_t ctx;
219 ctx.s = s;
220 ctx.found = 0;
221 storage->doall(slotmem, hm_readid, &ctx, pool);
222 if (ctx.found) {
223 storage->release(slotmem, ctx.item_id);
227 static apr_status_t hm_file_update_stat(hm_ctx_t *ctx, hm_server_t *s, apr_pool_t *pool)
236 char *path = apr_pstrcat(pool, ctx->storage_path, ".tmp.XXXXXX", NULL);
243 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02074)
247 rv = apr_file_open(&fpin, ctx->storage_path, APR_READ|APR_BINARY|APR_BUFFERED,
260 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02075)
261 "Unable to read file: %s", ctx->storage_path);
283 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02076)
284 "Unable to read from file: %s", ctx->storage_path);
353 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02077)
360 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02078)
369 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02079)
375 rv = apr_file_rename(path, ctx->storage_path, pool);
378 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02080)
380 ctx->storage_path);
386 static apr_status_t hm_update_stat(hm_ctx_t *ctx, hm_server_t *s, apr_pool_t *pool)
391 return hm_file_update_stat(ctx, s, pool);
395 static apr_status_t hm_file_update_stats(hm_ctx_t *ctx, apr_pool_t *p)
401 char *path = apr_pstrcat(p, ctx->storage_path, ".tmp.XXXXXX", NULL);
406 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02081)
412 for (hi = apr_hash_first(p, ctx->servers);
432 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02082)
439 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02083)
448 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02084)
454 rv = apr_file_rename(path, ctx->storage_path, p);
457 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02085)
459 ctx->storage_path);
466 static apr_status_t hm_slotmem_update_stats(hm_ctx_t *ctx, apr_pool_t *p)
472 for (hi = apr_hash_first(p, ctx->servers);
491 static apr_status_t hm_update_stats(hm_ctx_t *ctx, apr_pool_t *p)
494 return hm_slotmem_update_stats(ctx, p);
496 return hm_file_update_stats(ctx, p);
499 static hm_server_t *hm_get_server(hm_ctx_t *ctx, const char *ip, const int port)
503 s = apr_hash_get(ctx->servers, ip, APR_HASH_KEY_STRING);
506 s = apr_palloc(ctx->p, sizeof(hm_server_t));
507 s->ip = apr_pstrdup(ctx->p, ip);
512 apr_hash_set(ctx->servers, s->ip, APR_HASH_KEY_STRING, s);
519 static void hm_processmsg(hm_ctx_t *ctx, apr_pool_t *p,
537 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ctx->s, APLOGNO(02086)
546 s = hm_get_server(ctx, ip, port);
553 ap_log_error(APLOG_MARK, APLOG_CRIT, 0, ctx->s, APLOGNO(02087)
561 static apr_status_t hm_recv(hm_ctx_t *ctx, apr_pool_t *p)
570 rv = apr_socket_recvfrom(&from, ctx->sock, 0, buf, &len);
573 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02088) "would block");
577 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02089) "recvfrom failed");
581 hm_processmsg(ctx, p, &from, buf, len);
591 hm_ctx_t *ctx = (hm_ctx_t *)data;
593 if (!ctx->active) {
599 rv = hm_listen(ctx);
601 ctx->status = rv;
602 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ctx->s, APLOGNO(02090)
606 ctx->keep_running = 1;
607 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ctx->s, APLOGNO(02091)
614 hm_update_stats(ctx, pool);
617 * the ctx->interval
619 while ((now - cur) < apr_time_sec(ctx->interval)) {
629 pfd.desc.s = ctx->sock;
637 if (!ctx->keep_running) {
642 hm_recv(ctx, p);
649 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ctx->s, APLOGNO(02092)
653 ctx->keep_running = 0;
654 if (ctx->sock) {
655 apr_socket_close(ctx->sock);
656 ctx->sock = NULL;
667 hm_ctx_t *ctx = ap_get_module_config(s->module_config,
702 if (!ctx->active) {
705 rv = hm_watchdog_get_instance(&ctx->watchdog,
715 rv = hm_watchdog_register_callback(ctx->watchdog,
717 ctx,
739 hm_ctx_t *ctx;
749 ctx = ap_get_module_config(r->server->module_config,
772 hm_update_stat(ctx, &hmserver, r->pool);
792 hm_ctx_t *ctx = (hm_ctx_t *) apr_palloc(p, sizeof(hm_ctx_t));
794 ctx->active = 0;
795 ctx->storage_path = ap_runtime_dir_relative(p, DEFAULT_HEARTBEAT_STORAGE);
798 ctx->interval = apr_time_from_sec(HM_UPDATE_SEC);
799 ctx->s = s;
800 apr_pool_create(&ctx->p, p);
801 ctx->servers = apr_hash_make(ctx->p);
803 return ctx;
810 hm_ctx_t *ctx =
819 ctx->storage_path = ap_runtime_dir_relative(p, path);
832 hm_ctx_t *ctx =
841 if (!ctx->active) {
842 ctx->active = 1;
862 rv = apr_sockaddr_info_get(&ctx->mcast_addr, host_str, APR_INET, port, 0,