예제 #1
0
파일: network.c 프로젝트: DSMan195276/fircd
void network_handle_input (struct network *net, fd_set *infd, fd_set *outfd)
{
    struct channel *tmp;
    if (FD_ISSET(net->cmdfd.fd, infd)) {
        buf_handle_input(&(net->cmdfd));
        while (net->cmdfd.has_line > 0) {
            char *line = buf_read_line(&(net->cmdfd));
            handle_cmd_line(net, line);
            free(line);
        }
    }

    if (FD_ISSET(net->sock.fd, infd)) {
        buf_handle_input(&(net->sock));
        if (net->sock.closed_gracefully) {
            DEBUG_PRINT("Connection to %s was closed", net->name);
            net->close_network = 1;
        }
        while (net->sock.has_line > 0) {
            char *line = buf_read_line(&(net->sock));
            line[strlen(line)] = '\0';
            handle_irc_line(net, line);
            free(line);
        }
    }

    network_foreach_channel(net, tmp)
        channel_handle_input(tmp, infd, outfd);
}
예제 #2
0
int main(int argc, char **argv)
{
	struct timeval timeout;
	fd_set readfds;

	handle_cmd_line(argc, argv);

	in = dup(0);
	out = dup(1);
	terminal = open(terminal_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (terminal == -1) {
		perror("Failed to open terminal");
		exit(3);
	}

	configure_terminal(speed);
	configure_input();

	setup_signal_handlers();
	escape_state = 0;
	for (;;) {
		FD_ZERO(&readfds);
		FD_SET(terminal, &readfds);
		FD_SET(in, &readfds);

		timeout.tv_sec  = 0;
		timeout.tv_usec = 500000;

		if (select(FD_SETSIZE, &readfds, NULL, NULL, &timeout) == -1) {
			break;
		} else {
			if (FD_ISSET(terminal, &readfds) &&
			    transfer_from_terminal() == false)
				break;

			if (FD_ISSET(in, &readfds) &&
			    transfer_to_terminal() == false)
				break;
		}
	}

	unconfigure_input();
	if (opt_reset)
		write(out, RESET_SEQUENCE, sizeof(RESET_SEQUENCE));

	close(terminal);
	close(in);
	close(out);

	return 0;
}