Ejemplo n.º 1
0
void socket_accept(int fd) {
    struct sockaddr_in client_addr;
    socklen_t addrlen;
    fd_set fds;
    struct timeval timeout = {3, 0};

    while (!quit) {
        FD_ZERO(&fds);
        FD_SET(fd, &fds);
        int ret = select(fd+1, &fds, &fds, NULL, &timeout);
        if (ret < 0) {
            break;
        } else if (ret == 0) {
            continue;
        } else {
            int clientfd = accept(fd, (struct sockaddr*)&client_addr, &addrlen);
            if (clientfd < 0) {
                printf("socket accept failed.\n");
                break;
            }

            printf("Accept: %s:%d\n", inet_ntoa(client_addr.sin_addr), htons(client_addr.sin_port));
            socket_process(clientfd);
        }
    }
}
Ejemplo n.º 2
0
int main()
{
	if (!socket_init())
		return -1;

	ncurses_init();

	ncurses_print("Welcome to the bedrock console.\n");
	ncurses_print("To exit type \"quit\"\n");

	while (console_running)
		socket_process();

	ncurses_shutdown();
	socket_shutdown();

	return 0;
}