Beispiel #1
0
/*********************************************************
 * This function handles keypresses
 *
 *   s - save image
 *   q - quit
 *
 * DO NOT CHANGE
 *********************************************************/
void keyboard(unsigned char key, int x, int y)
{
	switch (key) {
	case 'q':case 'Q':
		cleanup_threads();
		exit(0);
		break;
	case 's':case 'S':
		save_image();
		glutPostRedisplay();
		break;
	default:
		break;
	}
}
Beispiel #2
0
void PX(cleanup) (void){
#ifdef _OPENMP
  X(cleanup_threads());
#endif
  XM(cleanup)();
}
/* @Test */
void test_pop3(void)
{
	struct list pop3_list;
	struct account *ac;
	struct pop3_server *pop3_server;
	struct pop3_dl_options dl_options = {0};

	char *profile_path;
	char *pwd;

	debug_init();
	debug_set_level(25);

	pwd = realpath(".", NULL);
	CU_ASSERT(pwd != NULL);

	profile_path = mycombinepath(pwd, "test-account-profile");
	CU_ASSERT(profile_path != NULL);

	config_set_user_profile_directory(profile_path);

	CU_ASSERT(codesets_init() != 0);

	CU_ASSERT(progmon_init() != 0);
	CU_ASSERT(init_threads() != 0);

	CU_ASSERT(load_config() != 0);
	CU_ASSERT(init_folders() != 0);

	ac = account_malloc();
	CU_ASSERT(ac != NULL);
	CU_ASSERT(ac->imap != NULL);
	CU_ASSERT(ac->pop != NULL);

	ac->recv_type = 0;
	if (ac->pop->name) free(ac->pop->name);
	ac->pop->name = mystrdup("localhost");
	CU_ASSERT(ac->pop->name != NULL);

	if (ac->pop->login) free(ac->pop->login);
	ac->pop->login = mystrdup("test");
	CU_ASSERT(ac->pop->login != NULL);

	if (ac->pop->passwd) free(ac->pop->passwd);
	ac->pop->passwd = mystrdup("test");
	CU_ASSERT(ac->pop->passwd != NULL);

	ac->pop->ssl = 0;
	ac->pop->port = 10110;

	insert_config_account(ac);

	mails_test_account(ac, mails_test_account_callback);
	sleep(3);

	account_free(ac);

	cleanup_threads();
	del_folders();
	free_config();
	progmon_deinit();
	codesets_cleanup();

	free(profile_path);
	free(pwd);
}
Beispiel #4
0
void rtsp_listen_loop(void) {
    struct addrinfo hints, *info, *p;
    char portstr[6];
    int *sockfd = NULL;
    int nsock = 0;
    int i, ret;

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE;

    snprintf(portstr, 6, "%d", config.port);

    ret = getaddrinfo(NULL, portstr, &hints, &info);
    if (ret) {
        die("getaddrinfo failed: %s", gai_strerror(ret));
    }

    for (p=info; p; p=p->ai_next) {
        int fd = socket(p->ai_family, p->ai_socktype, IPPROTO_TCP);
        int yes = 1;

        ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));

#ifdef IPV6_V6ONLY
        // some systems don't support v4 access on v6 sockets, but some do.
        // since we need to account for two sockets we might as well
        // always.
        if (p->ai_family == AF_INET6)
            ret |= setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes));
#endif

        if (!ret)
            ret = bind(fd, p->ai_addr, p->ai_addrlen);

        // one of the address families will fail on some systems that
        // report its availability. do not complain.
        if (ret) {
            debug(1, "Failed to bind to address %s\n", format_address(p->ai_addr));
            continue;
        }
        debug(1, "Bound to address %s\n", format_address(p->ai_addr));

        listen(fd, 5);
        nsock++;
        sockfd = realloc(sockfd, nsock*sizeof(int));
        sockfd[nsock-1] = fd;
    }

    freeaddrinfo(info);

    if (!nsock)
        die("could not bind any listen sockets!");


    int maxfd = -1;
    fd_set fds;
    FD_ZERO(&fds);
    for (i=0; i<nsock; i++) {
        if (sockfd[i] > maxfd)
            maxfd = sockfd[i];
    }

    mdns_register();

    printf("Listening for connections.\n");
    shairport_startup_complete();

    int acceptfd;
    struct timeval tv;
    while (1) {
        tv.tv_sec = 300;
        tv.tv_usec = 0;

        for (i=0; i<nsock; i++)
            FD_SET(sockfd[i], &fds);

        ret = select(maxfd+1, &fds, 0, 0, &tv);
        if (ret<0) {
            if (errno==EINTR)
                continue;
            break;
        }

        cleanup_threads();

        acceptfd = -1;
        for (i=0; i<nsock; i++) {
            if (FD_ISSET(sockfd[i], &fds)) {
                acceptfd = sockfd[i];
                break;
            }
        }
        if (acceptfd < 0) // timeout
            continue;

        rtsp_conn_info *conn = malloc(sizeof(rtsp_conn_info));
        memset(conn, 0, sizeof(rtsp_conn_info));
        socklen_t slen = sizeof(conn->remote);

        debug(1, "new RTSP connection\n");
        conn->fd = accept(acceptfd, (struct sockaddr *)&conn->remote, &slen);
        if (conn->fd < 0) {
            perror("failed to accept connection");
            free(conn);
        } else {
            pthread_t rtsp_conversation_thread;
            ret = pthread_create(&rtsp_conversation_thread, NULL, rtsp_conversation_thread_func, conn);
            if (ret)
                die("Failed to create RTSP receiver thread!");

            conn->thread = rtsp_conversation_thread;
            conn->running = 1;
            track_thread(conn);
        }
    }
    perror("select");
    die("fell out of the RTSP select loop");
}