⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strclithread.c

📁 UNIX环境下多线程的网络编程例子
💻 C
字号:
#include	"unpthread.h"void	*copyto(void *);static int	sockfd;		/* global for both threads to access */static FILE	*fp;voidstr_cli(FILE *fp_arg, int sockfd_arg){	char		recvline[MAXLINE];	pthread_t	tid;	sockfd = sockfd_arg;	/* copy arguments to externals */	fp = fp_arg;	Pthread_create(&tid, NULL, copyto, NULL);	while (Readline(sockfd, recvline, MAXLINE) > 0)		Fputs(recvline, stdout);}void *copyto(void *arg){	char	sendline[MAXLINE];	while (Fgets(sendline, MAXLINE, fp) != NULL)		Writen(sockfd, sendline, strlen(sendline));	Shutdown(sockfd, SHUT_WR);	/* EOF on stdin, send FIN */	return(NULL);		/* 4return (i.e., thread terminates) when end-of-file on stdin */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -