From mboxrd@z Thu Jan 1 00:00:00 1970 From: lm@mcvoy.com (Larry McVoy) Date: Fri, 22 Aug 2014 10:51:05 -0700 Subject: [TUHS] networking on unix before uucp In-Reply-To: References: <20140822155701.GB19006@mercury.ccil.org> <7C276A71-2110-41C8-8BF7-3529321B11DC@ronnatalie.com> Message-ID: <20140822175105.GH784@mcvoy.com> On Sat, Aug 23, 2014 at 04:11:42AM +1000, Dave Horsfall wrote: > On Fri, 22 Aug 2014, Ronald Natalie wrote: > > > I hate the socket interface, at least once you use it's goofy interface > > on UNIX, it works mostly like a file descriptor. > > In a previous slavery we had a simple socket library; the application did > little more than say whether it was a client or a server etc. I wish I > could steal that code now... lmbench has one: /* * Get a TCP socket, bind it, figure out the port, * and advertise the port as program "prog". * * XXX - it would be nice if you could advertise ascii strings. */ int tcp_server(int prog, int rdwr) /* * Unadvertise the socket */ int tcp_done(int prog) /* * Accept a connection and return it */ int tcp_accept(int sock, int rdwr) /* * Connect to the TCP socket advertised as "prog" on "host" and * return the connected socket. * * Hacked Thu Oct 27 1994 to cache pmap_getport calls. This saves * about 4000 usecs in loopback lat_connect calls. I suppose we * should time gethostbyname() & pmap_getprot(), huh? */ int tcp_connect(char *host, int prog, int rdwr) void sock_optimize(int sock, int flags) int sockport(int s) I swiped all that code and we use it in bitkeeper. sock = tcp_server(0, port, 0); if (sock == -1) exit(1); verbose((stderr, "started server on port %d\n", sockport(sock))); while (1) { if ((nsock = tcp_accept(sock)) < 0) continue; peer = peeraddr(nsock); verbose((stderr, "connection from %s\n", peer)); fin = fdopen(nsock, "r"); fout = fdopen(nsock, "w"); info_cmds(fin, fout, dashx); fclose(fin); fclose(fout); verbose((stderr, "%s is done\n", peer)); } -- --- Larry McVoy lm at mcvoy.com http://www.mcvoy.com/lm