Ejemplo n.º 1
0
void str_echo(int connfd)
{
	ssize_t n;
	char line[MAXLINE];
	
	heartbeat_serv(connfd,1,5);
	for (;;)
	{
		if ((n = readline(connfd,line,MAXLINE)) == 0)
		{
			return;
		}
		writen(connfd,line,n);
	}
}
Ejemplo n.º 2
0
void
str_echo(int sockfd)
{
	ssize_t		n;
	char		line[MAXLINE];

	heartbeat_serv(sockfd, 1, 5);

	for ( ; ; ) {
		if ((n = readline(sockfd, line, MAXLINE)) < 0) {
			perror("readline error");
			exit(1);
		} else if (n == 0) {
			return;		/* connection closed by other end */
		}

		if (writen(sockfd, line, n) != n) {
			perror("writen error");
			exit(1);
		}
	}
}