예제 #1
0
파일: child.c 프로젝트: bailili/learngit
void recv_request(int newfd)
{
	char buf[2048];
	int ret;
	while(1)
	{
		bzero(buf,sizeof(buf));
		ret=recv(newfd,buf,sizeof(buf),0);
		if(ret==0)
		{
			break;
		}
		if(strncmp("cd",buf,2)==0)
		{
			do_cd(newfd,buf);
	}else if(strncmp("ls",buf,2)==0)
	{
		do_ls(newfd,buf);
	}else if(strncmp("puts",buf,4)==0)
	{
		do_puts(newfd);
	}else if(strncmp("gets",buf,4)==0)
	{
		do_gets(newfd,buf);
	}else if(strncmp("remove",buf,6)==0)
	{
		do_remove(newfd,buf);
	}else if(strncmp("pwd",buf,3)==0)
	{
		do_pwd(newfd,buf);
	}else{
		continue;
	}
	}
}
예제 #2
0
void client_handle(psession_t ps)
{

	socket_t fd_client = ps -> sess_sfd ;
	int cmd_len = 0 ;
	int recv_ret ;
	while(1 )
	{
		bzero(ps -> sess_buf, BUF_SIZE);
		recv_ret = recv(fd_client, &cmd_len, sizeof(int),0);
		if(cmd_len == 0 || recv_ret == 0)
		{
			printf("client exit !\n");
			close(ps ->sess_sfd);
			free(ps);
			exit(1);
		}
		recvn(fd_client, ps->sess_buf, cmd_len);
		if(strncmp("cd", ps ->sess_buf, 2) == 0)
		{
			do_cd(ps);
		}else if(strncmp("ls", ps ->sess_buf, 2) == 0)
		{
			do_ls(ps);
		}else if( strncmp("puts", ps ->sess_buf, 4)== 0)
		{
			do_puts(ps);
		}else if( strncmp("gets", ps ->sess_buf, 4)== 0)
		{
			do_gets(ps);

		}else if( strncmp("remove", ps ->sess_buf, 6)== 0)
		{
			do_remove(ps);

		}else if(strncmp("pwd", ps ->sess_buf, 3) == 0) 
		{
			do_pwd(ps);

		}else 
		{
			continue ;
		}


	}
}