/* mark every vertex reachable from s with the distance to get there */ void graph_explore_bfs(graph_t *g, graph_vertex_t *s, graph_vertex_t *e, visit_func_t visit) { /* clear graph search assets unless we're exploring the whole graph */ if (g) graph_clear_pathtrace(g); /* mark starting point's prev as a self reference to avoid looping back */ s->path.prev = s; /* just a simple queue for breadth first search */ list_t *queue = list_init(NULL, NULL); list_queue(queue, s); while ((s = list_pop(queue))) { int clock = 0; list_node_t *it; /* break if searching for a specific destination */ if (e && e == s) break; s->path.visited = 1; s->path.pre_clock = clock++; if (visit) visit(s); for (it = s->edges->first; it != NULL; it = it->next) { graph_vertex_t *v = ((graph_edge_t *)it->data)->connection; if (!v->path.prev) { v->path.prev = s; v->path.distance = s->path.distance + 1; list_queue(queue, v); } } } list_destroy(queue); }
token_t * lexer_advance(lexer_t *l) { if (!l) return NULL; /* ingest data */ if (!l->curtok) { if (l->tokenized->size == 0) list_queue(l->tokenized, lexer_nextitem(l->s)); l->curtok = l->tokenized->first; return (token_t*)l->curtok->data; } if (!l->curtok->next) list_queue(l->tokenized, lexer_nextitem(l->s)); l->curtok = l->curtok->next; return (token_t*)l->curtok->data; }
int main(int argc, char **argv) { int input=-1; printf("\n===============WELCOME TO THE TEST INTERFACE TO VERIFY THE IPC================\n"); //list_receiver(1); while(1) { printf("\n -----Available Operations--- \n"); printf("\n 1. MESSAGE QUEUE Creation \n"); //this calls to the mq_open printf(" 2. Register Sender in the queue \n"); //this calls the msender system call printf(" 3. Register Receiver in the queue \n"); //this call the mreceiver system call printf(" 4. Send a message using the system call mq_send \n"); // This calls the mq_send system call printf(" 5. Clear and Close Message Queue\n"); //This calls the mq_close system call printf(" 6. Get Attributes of the message queue \n"); printf(" 7. Set Attributes of the message queue \n");//this calls to the mq_getattr system call printf(" 8. Notify system call \n"); printf(" 0. Exit the Program \n"); printf("Choose the operation you want to perform \t "); scanf(" %d",&input); switch(input) { case 1: list_queue(); break; case 2: list_sender(); break; case 3: list_receiver(0); break; case 4: mess_send(); //sender can be created dynamically also. break; case 5: message_clean(); break; case 6: get_attr(); break; case 7: set_attr(); break; case 8 : reqnotify(); break; case 0: exit(0); break; default : printf("\nIncorrect input. Try again. \n"); break; } } }
graph_edge_t * graph_add_edge(graph_vertex_t *orig, graph_vertex_t *dest, double weight) { graph_edge_t *e = malloc(sizeof(graph_edge_t)); e->connection = dest; e->weight = weight; /* provide free func to clean up on graph_edge_t alloc's */ if (!orig->edges) orig->edges = list_init(free, NULL); list_queue(orig->edges, e); return e; }
int main(void) { int quit = 0; // Initialize mail server seed_prng(*(uint32_t *)FLAG_PAGE); int num_mailq = 0; abook = calloc(sizeof(address_book)); initialize_address_book(); initialize_mail_queues(); // run a mail server char line[MAX_LINE+1]; int line_size = 0; printf("sendmail:"); do { // Read a line if ((line_size = receive_until(line, MAX_LINE, '\n')) <= 0) { break; } line[line_size] = '\0'; // Process the command char *next = line; // Terminate first command word while ((*next != ' ') && (*next != '\0')) next++; *next++ = '\0'; if (strcmp(line, "LIST")==0) { // List one mail queue list_queue(next); } else if (strcmp(line, "LISTALL")==0) { // List all mail queues list_all_queues(); } else if (strcmp(line, "POST")==0) { // Post a message sendmail_post(next); } else if (strcmp(line, "READ")==0) { // Read a message read_message(next); } else if (strcmp(line, "ADDRESSBOOK")==0) { // Print address book print_address_book(); } else if (strcmp(line, "QUIT")==0) { // Quit mail server break; } else { // Invalid command printf("Invalid Command!\n"); quit = 1; } } while (quit == 0); printf("Goodbye.\n"); }
/* scrit_add -- local Adds the specified scrit to the list. Returns the address of the created SCRIT. We do not try to eliminate duplicates, this can be done elsewhere. */ static SCRIT * scrit_add (char type, char *value) { SCRIT scrit = { NULL, '?', ' ', ' ' }; scrit.value = mem_strdup (value); scrit.type = type; scrit.method = method; scrit.scope = scope; list_queue (feedback, scrit); return ((SCRIT *) ((char *) feedback->prev + sizeof (LIST))); }
/* clean up after ourselves */ static void clean_on_quit(int sig) { struct cn_strct *tp; int i; #if DEBUG_VERBOSE == 2 printf("\n\n\n\n\nPRINTING QUEUE: \n"); list_queue(_Queue_head, _Queue_count); printf("PRINTING QUEUE_LIST: \n"); list_list(_Queue_tail); printf("PRINTING FREEs: \n"); list_list(_Free_conns); printf("PRINTING BUSYs: \n"); list_list(_Busy_conns); #endif while (NULL != _Free_conns) { tp = _Free_conns->c_next; free(_Free_conns->data_buf_head); free(_Free_conns); _Free_conns = tp; } while (NULL != _Busy_conns) { tp = _Busy_conns->c_next; show_cn(_Busy_conns); free(_Busy_conns->data_buf_head); close(_Busy_conns->net_socket); free(_Busy_conns); _Busy_conns = tp; } close(_Master_sock); _Master_sock = -1; printf("Graceful exit done after signal: %d\n", sig); /* cleanup the threads */ for (i = 0; i < WORKER_THREADS; i++) { pthread_cancel(_Workers[i]); } exit(0); }
void mailsend(int argc, char **argv) { int quit = 0; // parse arguments while (argc > 0) { if (!strcmp(*argv, "-d")) { debug_mode = 1; goto next; } next: argc--; argv++; } // Initialize mail server srand(); int num_mailq = 0; abook = calloc(sizeof(address_book)); initialize_address_book(); initialize_mail_queues(); // run a mail server char line[MAX_LINE+1]; int line_size = 0; do { // Read a line if ((line_size = receive_until(line, MAX_LINE, '\n')) <= 0) { break; } line[line_size] = '\0'; // Process the command char *next = line; // Terminate first command word while ((*next != ' ') && (*next != '\0')) next++; *next++ = '\0'; if (strcmp(line, "LIST")==0) { // List one mail queue list_queue(next); } else if (strcmp(line, "LISTALL")==0) { // List all mail queues list_all_queues(); } else if (strcmp(line, "POST")==0) { // Post a message mailsend_post(next); } else if (strcmp(line, "READ")==0) { // Read a message read_message(next); } else if (strcmp(line, "ADDRESSBOOK")==0) { // Print address book print_address_book(); } else if (strcmp(line, "QUIT")==0) { // Quit mail server break; } else { // Invalid command printf("Invalid Command!\n"); quit = 1; } } while (quit == 0); printf("Goodbye.\n"); }
int process_job(struct job *job){ int err = SUCCESS, len=0, pos =0; char *msg = kmalloc(1024,GFP_KERNEL); char id[3]; len = strlen("\nJob ID :"); memcpy(msg+pos,"\nJob ID :",len); pos+=len; sprintf(id,"%d", job->job_id); memcpy(msg+pos,id,3); pos+=1; len = strlen("\nJob type :"); memcpy(msg+pos,"\nJob type :",len); pos+=len; if(job->job_type==ENCRYPT||job->job_type==DECRYPT){ err = encryptDecrypt(job); len = strlen("ENCRYPT\n"); if(job->job_type==ENCRYPT) memcpy(msg+pos,"ENCRYPT\n",len); else memcpy(msg+pos,"ENCRYPT\n",len); pos+=len; len = strlen("Infile is ") ; memcpy(msg+pos,"Infile is ",len); pos+=len; len = strlen(job->infile) ; memcpy(msg+pos,job->infile,len); pos+=len; len = strlen("\nOutfile is ") ; memcpy(msg+pos,"\nOutfile is ",len); pos+=len; len = strlen(job->outfile) ; memcpy(msg+pos,job->outfile,len); pos+=len; } else if(job->job_type==CHECKSUM){ err = checksum(job); len = strlen("CHECKSUM\n") ; memcpy(msg+pos,"CHECKSUM\n",len); pos+=len; len = strlen("Infile is ") ; memcpy(msg+pos,"Infile is ",len); pos+=len; len = strlen(job->infile) ; memcpy(msg+pos,job->infile,len); pos+=len; } else if(job->job_type==LIST){ list_queue(prod_cons_q, job); } len = strlen("\nStatus is ") ; memcpy(msg+pos,"\nStatus is ",len); pos+=len; if(err>=SUCCESS){ len = strlen("SUCCESS") ; memcpy(msg+pos,"SUCCESS",len); pos+=len; } else { len = strlen("FAILIURE") ; memcpy(msg+pos,"FAILIURE",len); pos+=len; } memcpy(msg+pos,"\0",1); printk("Heyy %s", msg); netlink(job->pid, msg); kfree(job); return err; }