int main(int argc, char* argv[]) { int option, option_idx; int worker_id = 0; int datacenter_id = 0; int port = 7954; while ((option = getopt_long(argc, argv, "w:d:p:", options, &option_idx)) != -1) { switch (option) { case 'w': worker_id = atoi(optarg); break; case 'd': datacenter_id = atoi(optarg); break; case 'p': port = atoi(optarg); break; case 'h': case '?': printf(help); exit(EXIT_FAILURE); break; } } Context ctx = generator_init(worker_id, datacenter_id); server_serve(ctx, port); return 0; }
static void server_recv(void *arg, char *p, unsigned short len) { struct espconn *c = (struct espconn *) arg; char *body = strstr(p, "\r\n\r\n"); printf("HTTP: recv incoming\n"); if (body == NULL) { /* TODO(mkm): handle buffering and proper HTTP request parsing */ printf("cannot find header terminator aborting\n"); espconn_disconnect(c); return; } if (len >= 4 && (strncmp(p, "POST", 4) == 0)) { server_eval(c, body, len - (body - p)); } else { server_serve(c, p, len); } }