int main(int argc, char ** argv) { verifier_arguments(argc, argv); const int nombre_producteurs = atoi(argv[1]); const int nombre_consommateurs = atoi(argv[2]); const int taille_tampon = (argc != 4) ? TAILLE_TAMPON_DEFAUT : atoi(argv[3]); tampon_t * tampon = creer_tampon(taille_tampon); /* À faire avant le changement du handler de SIGINT ! */ limite = creer_limite(); config_handler(SIGINT, handler_sigint); acteurs_t * producteurs = creer_acteurs(nombre_producteurs, production, tampon, limite); acteurs_t * consommateurs = creer_acteurs(nombre_consommateurs, consommation, tampon, limite); comptes_t comptes_production = bilan(producteurs); comptes_t comptes_consommation = bilan(consommateurs); printf("Bilan:\n\tNombre de valeurs produites : %llu\n" "\tSomme des valeurs produites : %llu\n" "\tNombre de valeurs consommées : %llu\n" "\tSomme des valeurs consommées : %llu\n", comptes_production.nombre, comptes_production.somme, comptes_consommation.nombre, comptes_consommation.somme); tampon = detruire_tampon(tampon); limite = detruire_limite(limite); producteurs = detruire_acteurs(producteurs); consommateurs = detruire_acteurs(consommateurs); return 0; }
void main_handler(WS_CONNINFO *pwsc) { DPRINTF(E_DBG,L_MAIN,"in main_handler\n"); if(plugin_url_candispatch(pwsc)) { DPRINTF(E_DBG,L_MAIN,"Dispatching %s to plugin\n",ws_uri(pwsc)); plugin_url_handle(pwsc); return; } DPRINTF(E_DBG,L_MAIN,"Dispatching %s to config handler\n",ws_uri(pwsc)); config_handler(pwsc); }
int decode_request(char *buf, size_t size) { protocol_binary_request_header *hdr; hdr = (protocol_binary_request_header*)malloc(sizeof(*hdr)); if(hdr) { printf("unable to set memory"); } memset((void *)hdr, '0', sizeof(*hdr)); memcpy((void *)hdr, (const void *)buf, sizeof(*hdr)); if(hdr->request.opcode == PROTOCOL_BINARY_CMD_GET_CLUSTER_CONFIG) { config_handler(); } else { fprintf(stderr, "Got unknown request %d", hdr->request.opcode); } return 0; }
int lcb_dispatch_response(lcb_server_t *c, packet_info *info) { switch (info->res.response.opcode) { case PROTOCOL_BINARY_CMD_FLUSH: flush_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_GETQ: case PROTOCOL_BINARY_CMD_GATQ: case PROTOCOL_BINARY_CMD_GET: case PROTOCOL_BINARY_CMD_GAT: case CMD_GET_LOCKED: getq_response_handler(c, info); break; case CMD_GET_REPLICA: get_replica_response_handler(c, info); break; case CMD_UNLOCK_KEY: unlock_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_DELETE: delete_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_ADD: case PROTOCOL_BINARY_CMD_REPLACE: case PROTOCOL_BINARY_CMD_SET: case PROTOCOL_BINARY_CMD_APPEND: case PROTOCOL_BINARY_CMD_PREPEND: store_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_INCREMENT: case PROTOCOL_BINARY_CMD_DECREMENT: arithmetic_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_TOUCH: touch_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_STAT: stat_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_VERSION: version_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_VERBOSITY: verbosity_response_handler(c, info); break; case CMD_OBSERVE: observe_response_handler(c, info); break; case PROTOCOL_BINARY_CMD_NOOP: /* Ignore */ break; case PROTOCOL_BINARY_CMD_HELLO: fprintf(stderr,"inside handler for hello"); break; case PROTOCOL_BINARY_CMD_COMPACTDB: fprintf(stderr,"inside handler for compactDB"); break; case CMD_GET_CLUSTER_CONFIG: config_handler(c, info); break; default: return -1; } return 0; }