/* TCPtecho.c - main, TCPtecho, reader, writer, mstime */ #include #include #include #include #include #include #include #include #include extern int errno; int TCPtecho(fd_set *pafds, int nfds, int ccount, int hcount); int reader(int fd, fd_set *pfdset); int writer(int fd, fd_set *pfdset); int errexit(const char *format, ...); int connectTCP(const char *host, const char *service); long mstime(u_long *); #define BUFSIZE 4096 /* write buffer size */ #define CCOUNT 64*1024 /* default character count */ #define USAGE "usage: TCPtecho [ -c count ] host1 host2...\n" char *hname[NOFILE]; /* fd to host name mapping */ int rc[NOFILE], wc[NOFILE]; /* read/write character counts */ char buf[BUFSIZE]; /* read/write data buffer */ /*------------------------------------------------------------------------ * main - concurrent TCP client for ECHO service timing *------------------------------------------------------------------------ */ int main(int argc, char *argv[]) { int ccount = CCOUNT; int i, hcount, maxfd, fd; int one = 1; fd_set afds; hcount = 0; maxfd = -1; for (i=1; i maxfd) maxfd = fd; hname[fd] = argv[i]; ++hcount; FD_SET(fd, &afds); } TCPtecho(&afds, maxfd+1, ccount, hcount); exit(0); } /*------------------------------------------------------------------------ * TCPtecho - time TCP ECHO requests to multiple servers *------------------------------------------------------------------------ */ int TCPtecho(fd_set *pafds, int nfds, int ccount, int hcount) { fd_set rfds, wfds; /* read/write fd sets */ fd_set rcfds, wcfds; /* read/write fd sets (copy) */ int fd, i; for (i=0; i