| 43 | #define MSG_VERSION (1) |
| 44 | |
| 45 | static int hb_monitor(hb_ctx_t *ctx, apr_pool_t *p) |
| 46 | { |
| 47 | apr_size_t len; |
| 48 | apr_socket_t *sock = NULL; |
| 49 | char buf[256]; |
| 50 | int i, j; |
| 51 | apr_uint32_t ready = 0; |
| 52 | apr_uint32_t busy = 0; |
| 53 | ap_generation_t mpm_generation; |
| 54 | |
| 55 | ap_mpm_query(AP_MPMQ_GENERATION, &mpm_generation); |
| 56 | |
| 57 | for (i = 0; i < ctx->server_limit; i++) { |
| 58 | process_score *ps; |
| 59 | ps = ap_get_scoreboard_process(i); |
| 60 | |
| 61 | for (j = 0; j < ctx->thread_limit; j++) { |
| 62 | int res; |
| 63 | |
| 64 | worker_score *ws = NULL; |
| 65 | |
| 66 | ws = &ap_scoreboard_image->servers[i][j]; |
| 67 | |
| 68 | res = ws->status; |
| 69 | |
| 70 | if (res == SERVER_READY && ps->generation == mpm_generation) { |
| 71 | ready++; |
| 72 | } |
| 73 | else if (res != SERVER_DEAD && |
| 74 | res != SERVER_STARTING && res != SERVER_IDLE_KILL && |
| 75 | ps->generation == mpm_generation) { |
| 76 | busy++; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | len = apr_snprintf(buf, sizeof(buf), msg_format, MSG_VERSION, ready, busy); |
| 82 | |
| 83 | do { |
| 84 | apr_status_t rv; |
| 85 | rv = apr_socket_create(&sock, ctx->mcast_addr->family, |
| 86 | SOCK_DGRAM, APR_PROTO_UDP, p); |
| 87 | if (rv) { |
| 88 | ap_log_error(APLOG_MARK, APLOG_WARNING, rv, |
| 89 | NULL, APLOGNO(02097) "Heartbeat: apr_socket_create failed"); |
| 90 | break; |
| 91 | } |
| 92 | |
| 93 | rv = apr_mcast_loopback(sock, 1); |
| 94 | if (rv) { |
| 95 | ap_log_error(APLOG_MARK, APLOG_WARNING, rv, |
| 96 | NULL, APLOGNO(02098) "Heartbeat: apr_mcast_loopback failed"); |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | rv = apr_socket_sendto(sock, ctx->mcast_addr, 0, buf, &len); |
| 101 | if (rv) { |
| 102 | ap_log_error(APLOG_MARK, APLOG_WARNING, rv, |
no test coverage detected