Example #1
0
void AllOrder::tic(){
	execute_order();
	if(order_stack.back()->END())pop_order();
}
Example #2
0
void daemon_loop() {

    int sock = 0;
    int ret = 0;

    /* クライアント通信ソケット生成 */
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == -1) {
        DEBUG_PRINTF("socket error: %s", strerror(errno));
        return;
    }

    struct sockaddr_in myaddr;
    memset(&myaddr, 0, sizeof(myaddr));
    myaddr.sin_family = AF_INET;
    myaddr.sin_port = htons(41260);
    inet_aton("127.0.0.1", &myaddr.sin_addr);

    ret = bind(sock, (struct sockaddr*)&myaddr, sizeof(myaddr));

    ret = listen(sock, 10);
    if (ret == -1) {
        DEBUG_PRINTF("listen error: %s", strerror(errno));
        return;
    }

    /* 要求受付ループ */
    while(1) {
        // struct timeval wait;

        fd_set rfds;
        FD_ZERO(&rfds);
        FD_SET(sock, &rfds);

        ret = select(sock+1, &rfds, NULL, NULL, NULL);
        if (ret == -1) {
            DEBUG_PRINTF("select error: %s", strerror(errno));
            break;
        }

        printf("select returns count = %d\n", ret);

        if (ret == 1) {
            if (FD_ISSET(sock, &rfds)) {
                int readsock = 0;
                struct sockaddr_in addr;
                memset(&addr, 0, sizeof(addr));
                socklen_t socklen = sizeof(addr);

                /* 接続要求受付 */
                if ((readsock = accept(sock, (struct sockaddr*)&addr, &socklen)) == -1) {
                    DEBUG_PRINTF("accept error: %s", strerror(errno));
                    break;
                } else {
                    printf("receive request sock=%d\n", readsock);
                    /* データ処理 */
                    if (execute_order(readsock) != 0) {
                        printf("%s\n", getmsg());
                    }
                    printf("%s", "order complete\n");

                    shutdown(readsock, SHUT_RDWR);
                    close(readsock);
                    free_args();
                }
            } else {
                DEBUG_PRINT("ellegal operation select?");
                break;
            }
        } else {
            DEBUG_PRINT("socket closed?");
            break;
        }

    } /* end loop */

    shutdown(sock, SHUT_RDWR);
    close(sock);

    return;
}
Example #3
0
void main_loop(int argc, char *argv[], int max_hosts)
{
	int i;
	int host;
	int *targeted_host;
	FileData local_file_data;
	FileData remote_file_data;
	Order *order;
	Direction direction;
	bool use_cache;
	char *top_dir;

	FtpInit();

	targeted_host = get_targeted_host(argc, argv, max_hosts);

	for (i = 0;; i++) {
		host = targeted_host[i];
		if (host == -1) {
			break;
		}

		message(PROCESS, cfgSectionNumberToName(host), 0, host);

		direction = get_direction(host);

		get_local_file_data(&local_file_data, host);

		if (command_line_option.rebuild_cache) { /* -r | --rebuild-cache */
			rebuild_cache(host);
			free_file_data(&local_file_data);
			continue;
		}
		if (command_line_option.catch_up) { /* -R | --catch-up */
			catch_up(&local_file_data, host);
			free_file_data(&local_file_data);
			continue;
		}

		if (direction == DOWNLOAD || !does_cache_exist(host)) {
			if (direction == DOWNLOAD) {
				printf(_("Rebuilding cache for downloading...\n"));
			} else {
				printf(_("Cache file is not found.\nCreating a new one...\n"));
			}
			if (connect_to_remote_host(host) != 0) {
				free_file_data(&local_file_data);
				continue;
			}
			get_remote_file_data(&remote_file_data, host);
			use_cache = FALSE;
		} else {
			load_cache(&remote_file_data, host);
			use_cache = TRUE;
		}

		order = compare_both_hosts_and_generate_order(&local_file_data, &remote_file_data, config.local_top_dir[host], config.remote_top_dir[host], direction, host);

		if (!does_need_update(order)) {
			disconnect_from_remote_host(host);
			if (direction == UPLOAD) {
				printf(_("The remote host doesn't need updating.\n"));
			} else {
				printf(_("The local host doesn't need updating.\n"));
			}
			if (!use_cache) {
				save_cache(&remote_file_data, host);
			}
			free_file_data(&remote_file_data);
			free_file_data(&local_file_data);
			continue;
		}

		if(command_line_option.list) {
			disconnect_from_remote_host(host);
			put_listing_of_updated_file(order, direction);
			free_file_data(&remote_file_data);
			free_file_data(&local_file_data);
			continue;
		}

		if(command_line_option.nlist) {
			disconnect_from_remote_host(host);
			put_the_number_of_updated_file(order, direction);
			free_file_data(&remote_file_data);
			free_file_data(&local_file_data);
			continue;
		}

		if (!use_cache) {
			printf("\n");
		}
		put_num_updated_file(order, direction);

		if (connect_to_remote_host(host) != 0) {
			free_file_data(&remote_file_data);
			free_file_data(&local_file_data);
			continue;
		}

		if (direction == UPLOAD) {
			top_dir = str_concat(config.remote_top_dir[host], "/", NULL);
		} else {
			top_dir = str_concat(config.local_top_dir[host], "/", NULL);
		}

		message(ENTER, top_dir, 0, host);
		execute_order(order, &remote_file_data, direction, host);
		message(LEAVE, top_dir, 0, host);

		free(top_dir);
		free_order(order);

		disconnect_from_remote_host(host);

		save_cache(&remote_file_data, host);

		free_file_data(&remote_file_data);
		free_file_data(&local_file_data);
	}
	free(targeted_host);
}