Ejemplo n.º 1
0
static void*
callback(enum mg_event event,
         struct mg_connection *conn,
         const struct mg_request_info *request_info) {
    if (event == MG_NEW_REQUEST) {
        std::string request_uri = request_info->uri;
        if (request_uri == "/face/suggest/") {
            return handle_suggest(event, conn, request_info);
        }
        else if (request_uri == "/face/import/") {
            return handle_import(event, conn, request_info);
        }
        else if (request_uri == "/face/export/") {
            return handle_export(event, conn, request_info);
        }
        else if (request_uri == "/face/stats/") {
            return handle_stats(event, conn, request_info);
        }
        else {
            return handle_invalid_request(event, conn, request_info);
        }
    }
    else {
        return NULL;
    }
}
Ejemplo n.º 2
0
int main()
{
	SDL_Init(SDL_INIT_VIDEO);
	resize_screen(640, 480);
	SDL_WM_SetCaption("Mandelbrot", "mandelbrot");
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
	uint32_t stat_ticks = SDL_GetTicks();
	uint64_t stat_pixels = 0;
	uint32_t palette[MAX_ITER];
	for (int i = 0; i < MAX_ITER; i++)
		palette[i] = i ? color(i / (float)MAX_ITER) : 0;
	while (1) {
		handle_events();
		uint32_t *fbp = (uint32_t *)screen->pixels;
		int w = screen->w;
		int h = screen->h;
		float dx = 1.0f / (float)w;
		float dy = 1.0f / (float)h;
		for (int j = 0; j < (h * w - NUM); j += NUM) {
			complex float c[NUM];
			for (int k = 0; k < NUM; k++)
				c[k] = (zoom * (dx * (float)((j+k)%w) - 0.5f) + xoff)
					+ I * (zoom * (dy * (float)((j+k)/w) - 0.5f) + yoff);
			int t[NUM];
			calc(t, c);
			for (int k = 0; k < NUM; k++)
				fbp[j + k] = palette[t[k]];
		}
#if 0
		for (int j = 0; j < h; j++)
			for (int i = 0; i < MAX_ITER; i++)
				fbp[j * w + i] = palette[i];
#endif
		stat_pixels += w*h;
		uint32_t cur_ticks = SDL_GetTicks();
		if ((cur_ticks - stat_ticks) > 1000) {
			handle_stats(0.001 * (double)(cur_ticks - stat_ticks), stat_pixels, w*h);
			stat_pixels = 0;
			stat_ticks = cur_ticks;
		}
		SDL_Flip(screen);
	}
	return 0;
}
/*!
 * Dispatch an asynchronous request by invoking the respective callback. If no
 * matching command is found, return an error.
 *
 * \param[in]     req       Request
 * \param[in,out] res       Result
 * \param[in,out] drv_state Driver state
 * \param[in,out] trd_state Thread state
 */
extern void
dispatch(gd_req_t *req, gd_res_t *res, void *drv_state, void *trd_state) {
  gdt_drv_t *drv = drv_state;
  gdt_trd_t *trd = trd_state;

  /* Dispatch the request */
  switch (req->cmd) {
    case GDE_CMD_SUM:
      handle_sum(req, res, drv, trd);
      break;
    case GDE_CMD_PING:
      handle_ping(req, res, drv, trd);
      break;
    case GDE_CMD_STATS:
      handle_stats(req, res, drv, trd);
      break;
    default:
      error_set(res, GDE_ERR_COMMAND);
  }
}
Ejemplo n.º 4
0
void serve_request(client_t *client) {
    parsed_url_t url;
    parse_URL(client->url, url);
    std::string &request_uri = url.path;
    DCERR("request_uri: " << request_uri << endl);

    if (request_uri == "/face/suggest/") {
        handle_suggest(client, url);
    }
    else if (request_uri == "/face/import/") {
        handle_import(client, url);
    }
    else if (request_uri == "/face/export/") {
        handle_export(client, url);
    }
    else if (request_uri == "/face/stats/") {
        handle_stats(client, url);
    }
    else {
        handle_invalid_request(client, url);
    }
}
Ejemplo n.º 5
0
/* Worker to consume Fluent Bit statistics */
void *worker_stats_reader(void *data)
{
    int i;
    int fd;
    int ret;
    int evl;
    int n_events = 8;
    int n_fds;
    struct epoll_event *events = NULL;

    while (1) {
        /* Connect to the Fluent Bit server */
        fd = fluentbit_connect(FLB_SOCK);
        if (fd == -1) {
            /* If it fails, always try to reconnect */
            goto again;
        }

        /* Create the epoll(7) instance */
        evl = epoll_create(64);
        if (evl == -1) {
            perror("epoll_create");
            goto again;
        }

        /* Register the socket into the event loop */
        ret = create_event(evl, fd, MK_EPOLL_READ, MK_EPOLL_LEVEL_TRIGGERED);
        if (ret == -1) {
            goto again;
        }

        /* Allocate an array to get the events reported */
        events = monkey->mem_alloc(sizeof(struct epoll_event) * n_events);
        if (!events) {
            goto again;
        }

        /*
         * A while() inside a while() is very dirty, once we move to Duda API 2
         * we will use the right interfaces.
         */
        while (1) {
            n_fds = epoll_wait(evl, events, n_events, -1);
            for (i = 0; i < n_fds; i++) {
                /* If we have some data available (READ) */
                if (events[i].events & EPOLLIN) {
                    if (handle_stats(events[i].data.fd) == -1) {
                        goto again;
                    }
                }
                else {
                    /* Anything different than EPOLLIN is an error, just break */
                    goto again;
                }
            }
        }

    again:
        /*
         * Release resources and always delay, don't burn the CPU if
         * there are exceptions.
         */
        if (fd) {
            close(fd);
        }
        if (evl > 0) {
            close(evl);
        }
        if (events) {
            monkey->mem_free(events);
        }
        sleep(1);
    }
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: OPSF/uClinux
/*
 * This is called once the connection has been negotiated.  It is used
 * for rsyncd, remote-shell, and local connections.
 */
int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[])
{
	struct file_list *flist = NULL;
	int status = 0, status2 = 0;
	char *local_name = NULL;

	cleanup_child_pid = pid;
	if (!read_batch) {
		set_nonblocking(f_in);
		set_nonblocking(f_out);
	}

	io_set_sock_fds(f_in, f_out);
	setup_protocol(f_out,f_in);

	if (protocol_version >= 23 && !read_batch)
		io_start_multiplex_in();

	/* We set our stderr file handle to blocking because ssh might have
	 * set it to non-blocking.  This can be particularly troublesome if
	 * stderr is a clone of stdout, because ssh would have set our stdout
	 * to non-blocking at the same time (which can easily cause us to lose
	 * output from our print statements).  This kluge shouldn't cause ssh
	 * any problems for how we use it.  Note also that we delayed setting
	 * this until after the above protocol setup so that we know for sure
	 * that ssh is done twiddling its file descriptors.  */
	set_blocking(STDERR_FILENO);

	if (am_sender) {
		keep_dirlinks = 0; /* Must be disabled on the sender. */
		io_start_buffering_out();
		if (!filesfrom_host)
			set_msg_fd_in(f_in);
		send_filter_list(f_out);
		if (filesfrom_host)
			filesfrom_fd = f_in;

		if (write_batch && !am_server)
			start_write_batch(f_out);
		flist = send_file_list(f_out, argc, argv);
		set_msg_fd_in(-1);
		if (verbose > 3)
			rprintf(FINFO,"file list sent\n");
		the_file_list = flist;

		io_flush(NORMAL_FLUSH);
		send_files(flist,f_out,f_in);
		io_flush(FULL_FLUSH);
		handle_stats(-1);
		if (protocol_version >= 24)
			read_final_goodbye(f_in, f_out);
		if (pid != -1) {
			if (verbose > 3)
				rprintf(FINFO,"client_run waiting on %d\n", (int) pid);
			io_flush(FULL_FLUSH);
			wait_process(pid, &status);
		}
		output_summary();
		io_flush(FULL_FLUSH);
		exit_cleanup(status);
	}

	if (need_messages_from_generator && !read_batch)
		io_start_multiplex_out();

	if (argc == 0)
		list_only |= 1;

	send_filter_list(read_batch ? -1 : f_out);

	if (filesfrom_fd >= 0) {
		io_set_filesfrom_fds(filesfrom_fd, f_out);
		filesfrom_fd = -1;
	}

	if (write_batch && !am_server)
		start_write_batch(f_in);
	flist = recv_file_list(f_in);
	the_file_list = flist;

	if (flist && flist->count > 0) {
		local_name = get_local_name(flist, argv[0]);

		status2 = do_recv(f_in, f_out, flist, local_name);
	} else {
		handle_stats(-1);
		output_summary();
	}

	if (pid != -1) {
		if (verbose > 3)
			rprintf(FINFO,"client_run2 waiting on %d\n", (int) pid);
		io_flush(FULL_FLUSH);
		wait_process(pid, &status);
	}

	return MAX(status, status2);
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: OPSF/uClinux
static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
{
	int pid;
	int status = 0;
	int error_pipe[2];

	/* The receiving side mustn't obey this, or an existing symlink that
	 * points to an identical file won't be replaced by the referent. */
	copy_links = 0;

	if (preserve_hard_links)
		init_hard_links();

	if (fd_pair(error_pipe) < 0) {
		rsyserr(FERROR, errno, "pipe failed in do_recv");
		exit_cleanup(RERR_IPC);
	}

	io_flush(NORMAL_FLUSH);

	if ((pid = do_fork()) == -1) {
		rsyserr(FERROR, errno, "fork failed in do_recv");
		exit_cleanup(RERR_IPC);
	}

	if (pid == 0) {
		close(error_pipe[0]);
		if (f_in != f_out)
			close(f_out);

		/* we can't let two processes write to the socket at one time */
		close_multiplexing_out();

		/* set place to send errors */
		set_msg_fd_out(error_pipe[1]);

		recv_files(f_in, flist, local_name);
		io_flush(FULL_FLUSH);
		handle_stats(f_in);

		send_msg(MSG_DONE, "", 0);
		io_flush(FULL_FLUSH);

		/* Handle any keep-alive packets from the post-processing work
		 * that the generator does. */
		if (protocol_version >= 29) {
			kluge_around_eof = -1;

			/* This should only get stopped via a USR2 signal. */
			while (read_int(f_in) == flist->count
			    && read_shortint(f_in) == ITEM_IS_NEW) {}

			rprintf(FERROR, "Invalid packet at end of run [%s]\n",
				who_am_i());
			exit_cleanup(RERR_PROTOCOL);
		}

		/* Finally, we go to sleep until our parent kills us with a
		 * USR2 signal.  We sleep for a short time, as on some OSes
		 * a signal won't interrupt a sleep! */
		while (1)
			msleep(20);
	}

	am_generator = 1;
	close_multiplexing_in();
	if (write_batch && !am_server)
		stop_write_batch();

	close(error_pipe[1]);
	if (f_in != f_out)
		close(f_in);

	io_start_buffering_out();

	set_msg_fd_in(error_pipe[0]);

	generate_files(f_out, flist, local_name);

	handle_stats(-1);
	io_flush(FULL_FLUSH);
	if (protocol_version >= 24) {
		/* send a final goodbye message */
		write_int(f_out, -1);
	}
	io_flush(FULL_FLUSH);

	set_msg_fd_in(-1);
	kill(pid, SIGUSR2);
	wait_process(pid, &status);
	return status;
}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: OPSF/uClinux
static void do_server_sender(int f_in, int f_out, int argc,char *argv[])
{
	int i;
	struct file_list *flist;
	char *dir = argv[0];

	if (verbose > 2) {
		rprintf(FINFO, "server_sender starting pid=%ld\n",
			(long)getpid());
	}

	if (am_daemon && lp_write_only(module_id)) {
		rprintf(FERROR, "ERROR: module is write only\n");
		exit_cleanup(RERR_SYNTAX);
		return;
	}
	if (am_daemon && lp_read_only(module_id) && remove_sent_files) {
		rprintf(FERROR,
		    "ERROR: --remove-sent-files cannot be used with a read-only module\n");
		exit_cleanup(RERR_SYNTAX);
		return;
	}

	if (!relative_paths && !push_dir(dir)) {
		rsyserr(FERROR, errno, "push_dir#3 %s failed",
			full_fname(dir));
		exit_cleanup(RERR_FILESELECT);
	}
	argc--;
	argv++;

	if (strcmp(dir,".")) {
		int l = strlen(dir);
		if (strcmp(dir,"/") == 0)
			l = 0;
		for (i = 0; i < argc; i++)
			argv[i] += l+1;
	}

	if (argc == 0 && (recurse || list_only)) {
		argc = 1;
		argv--;
		argv[0] = ".";
	}

	flist = send_file_list(f_out,argc,argv);
	if (!flist || flist->count == 0) {
		exit_cleanup(0);
	}
	the_file_list = flist;

	io_start_buffering_in();
	io_start_buffering_out();

	send_files(flist,f_out,f_in);
	io_flush(FULL_FLUSH);
	handle_stats(f_out);
	if (protocol_version >= 24)
		read_final_goodbye(f_in, f_out);
	io_flush(FULL_FLUSH);
	exit_cleanup(0);
}
Ejemplo n.º 9
0
int main_0062_stats_event (int argc, char **argv) {
    rd_kafka_t *rk;
    rd_kafka_conf_t *conf;
    test_timing_t t_delivery;
    rd_kafka_queue_t *eventq;
    const int iterations = 5;
    int i;
    test_conf_init(NULL, NULL, 10);

    /* Set up a global config object */
    conf = rd_kafka_conf_new();
    rd_kafka_conf_set(conf,"statistics.interval.ms", "100", NULL, 0);

    rd_kafka_conf_set_events(conf, RD_KAFKA_EVENT_STATS);

    /* Create kafka instance */
    rk = test_create_handle(RD_KAFKA_PRODUCER, conf);

    eventq = rd_kafka_queue_get_main(rk);

    /* Wait for stats event */
    for (i = 0 ; i < iterations ; i++) {
            TIMING_START(&t_delivery, "STATS_EVENT");
            stats_count = 0;
            while (stats_count == 0) {
                    rd_kafka_event_t *rkev;
                    rkev = rd_kafka_queue_poll(eventq, 100);
                    switch (rd_kafka_event_type(rkev))
                    {
                    case RD_KAFKA_EVENT_STATS:
                            TEST_SAY("%s event\n", rd_kafka_event_name(rkev));
                            handle_stats(rkev);
                            break;
                    case RD_KAFKA_EVENT_NONE:
                            break;
                    default:
                            TEST_SAY("Ignore event: %s\n",
                                     rd_kafka_event_name(rkev));
                            break;
                    }
                    rd_kafka_event_destroy(rkev);
            }
            TIMING_STOP(&t_delivery);

            if (!strcmp(test_mode, "bare")) {
                    /* valgrind is too slow to make this meaningful. */
                    if (TIMING_DURATION(&t_delivery) < 1000 * 100 * 0.8 ||
                        TIMING_DURATION(&t_delivery) > 1000 * 100 * 1.2)
                            TEST_FAIL("Stats duration %.3fms is >= 20%% "
                                      "outside statistics.interval.ms 100",
                                      (float)TIMING_DURATION(&t_delivery)/
                                      1000.0f);
            }
    }

    rd_kafka_queue_destroy(eventq);

    rd_kafka_destroy(rk);

    return 0;
}