// This is called when the headers are received so we can look for a message waiting for // this person, or leave them connected until one comes, or time them out after 50s maybe? void receivedHeaders(clientStatus *thisClient) { printf ("Connected by >%s<\r\n", thisClient->clientId); // Check to see if there's a message queued for this person // if so, send it and drop the connection khiter_t q = kh_get(queue, queue, (char*)thisClient->clientId); if (q != kh_end(queue)) { char *queuedMessage; kl_shift(messages, kh_value(queue,q), &queuedMessage); // Now send the message to the person and close snprintf(httpResponse, HTTP_RESPONSE_SIZE, HTTP_TEMPLATE, (int)strlen(queuedMessage), queuedMessage); // Compose the response message free(queuedMessage); write(thisClient->io.fd, httpResponse, strlen(httpResponse)); // Send it closeConnectionSkipHash((ev_io*)thisClient); // If that was the last one, free the list and remove it from the hash if (!kh_value(queue, q)->head->next) { kl_destroy(messages, kh_value(queue, q)); // Free the list free((void*)kh_key(queue, q)); // Free the key (the client id) kh_del(queue, queue, q); // Remove this client id from the hash } } else { // If there's no message, then add their client id to the hash for later int ret; khiter_t k = kh_put(clientStatuses, clientStatuses, thisClient->clientId, &ret); kh_value(clientStatuses, k) = thisClient; } }
// Runs the appropriate action for each queued event void event_process() { Event event; while (kl_shift(Event, event_queue, &event) == 0) { switch (event.type) { case kEventSignal: signal_handle(event); break; case kEventJobActivity: job_handle(event); break; default: abort(); } } }
// Runs the appropriate action for each queued event void event_process(bool deferred) { Event event; while (kl_shift(Event, get_queue(deferred), &event) == 0) { switch (event.type) { case kEventSignal: signal_handle(event); break; case kEventRStreamData: rstream_read_event(event); break; case kEventJobExit: job_exit_event(event); break; default: abort(); } } }
// Runs the appropriate action for each queued event bool event_process(bool deferred) { bool processed_events = false; Event event; while (kl_shift(Event, get_queue(deferred), &event) == 0) { processed_events = true; switch (event.type) { case kEventSignal: signal_handle(event); break; case kEventRStreamData: rstream_read_event(event); break; case kEventJobExit: job_exit_event(event); break; default: abort(); } } return processed_events; }