void worker_engine::respond_to_help_request(void * socket) { if (!data->enrolled) { data->enrolled = true; send_full_msg(socket, serialize_msg(NITRO_AFFIRM_HELP)); } else { send_full_msg(socket, serialize_msg(NITRO_DENY_HELP_1REASON, "not yet enrolled")); } }
void worker_engine::respond_to_assignment(void * socket, Json::Value const & json) { string txt; if (data->enrolled) { auto aid = json["body"]["assignment"]["id"]; auto lines = json["body"]["assignment"]["lines"]; assignment * asgn = new assignment(aid.asCString(), lines.asCString()); accept_assignment(asgn); txt = serialize_msg(NITRO_ACCEPT_ASSIGNMENT); } else { txt = serialize_msg(NITRO_REJECT_ASSIGNMENT_1REASON, "not yet enrolled"); } send_full_msg(socket, txt); }
void worker_engine::notify_thread_complete(thread::id tid) { task::id_type task_id_to_complete = UINT64_MAX; { lock_guard<mutex> lock(data->tmap_mutex); auto i = data->threadmap.find(tid); if (i != data->threadmap.end()) { // Have to detach before we erase; otherwise we trigger a terminate // in thread dtor, which recursively calls this method... i->second.associated_thread->detach(); task_id_to_complete = i->second.associated_task->get_id(); // This causes the thread object to be destroyed, among other // things. data->threadmap.erase(i); } } // release lock on threadmap if (task_id_to_complete != UINT64_MAX) { --data->active_thread_count; auto asgn = get_current_assignment(); if (asgn) { bool all_complete = asgn->complete_task(task_id_to_complete); if (all_complete) { auto msg = serialize_msg(NITRO_1ASSIGNMENT_COMPLETE, asgn->get_id()); queue_for_send(publisher, msg); lock_guard<mutex> lock(data->aqueue_mutex); data->asgn_queue.pop(); } } else { xlog("Got thread exit without current assignment. Huh?"); } } else { xlog("Didn't find thread in map."); } }
void IPC_send(message_t msg, int fd, int pid){ struct sockaddr_in client; // A QUIEN LE MANDO?????????????????????????????????????????????? int client_len = sizeof(struct sockaddr_in); int length = sizeof(int) + MAX_BUFFER_SIZE * sizeof(char); char * serialized = calloc(1, length); serialized = serialize_msg(msg); // sends the message back to where it came from if( sendto(fd, serialized, length, 0, (struct sockaddr *)&client, client_len)== -1){ perror("server could not send message"); // return -1; } }