Esempio n. 1
0
File: daemon.c Progetto: GNS3/vpcs
static void 
daemon_proc(int sock, int fdtty)
{
	char *goodbye = "\r\nGood-bye\r\n";
	int sock_cli;
	struct sockaddr_in cli;
	int slen;
	int rc;
	int fsess = 1;

	slen = sizeof(cli);
	while (1) {
		cmd_quit = 0;
		sock_cli = accept(sock, (struct sockaddr *) &cli, (socklen_t *)&slen);
		if (sock_cli < 0) 
			continue;

		set_telnet_mode(sock_cli);
		set_nonblock(fdtty);

		/* to show the prompt if it is not the first connection */
		if (!fsess)
			rc = write(fdtty, "\n", 2);
		
		fsess = 0;
		while (!cmd_quit) {
			if ((rc = pipe_rw(fdtty, sock_cli)) < 0)
				break;
			rc = pipe_rw(sock_cli, fdtty);
			/* error */
			if (rc < 0)
				break;
			/* time out */
			if (rc == 0)
				continue;	
		}	
		pipe_rw(fdtty, sock_cli);
		rc = write(sock_cli, goodbye, strlen(goodbye));
		close(sock_cli);
	}
}
Esempio n. 2
0
File: pipe.c Progetto: A-L-E-X/RIOT
ssize_t pipe_write(pipe_t *pipe, const void *buf, size_t n)
{
    return pipe_rw(pipe->rb, (char *) buf, n,
                   &pipe->read_blocked, &pipe->write_blocked, (ringbuffer_op_t) ringbuffer_add);
}
Esempio n. 3
0
File: pipe.c Progetto: A-L-E-X/RIOT
ssize_t pipe_read(pipe_t *pipe, void *buf, size_t n)
{
    return pipe_rw(pipe->rb, (char *) buf, n,
                   &pipe->write_blocked, &pipe->read_blocked, ringbuffer_get);
}