*** ttcp.c Thu Oct 18 11:42:36 2001 --- ttcp.jishac.c Wed Jan 16 16:00:40 2002 *************** *** 70,75 **** --- 70,76 ---- struct sockaddr_in sinme; struct sockaddr_in sinhim; struct sockaddr_in frominet; + struct linger linger_opt={0,0}; /* Socket SO_LINGER option - JISHAC */ int domain, fromlen; int fd; /* fd of network socket */ *************** *** 121,126 **** --- 122,128 ---- Options specific to -t:\n\ -n## number of source bufs written to network (default 2048)\n\ -D don't buffer TCP writes (sets TCP_NODELAY socket option)\n\ + -L ## set write linger timeout (sets SO_LINGER socket option)\n\ Options specific to -r:\n\ -B for -s, only output full blocks as specified by -l (for TAR)\n\ -T \"touch\": access each byte as it's read\n\ *************** *** 156,162 **** if (argc < 2) goto usage; ! while ((c = getopt(argc, argv, "drstuvBDTb:f:l:n:p:A:O:")) != -1) { switch (c) { case 'B': --- 158,164 ---- if (argc < 2) goto usage; ! while ((c = getopt(argc, argv, "drstuvBDTb:f:l:n:p:A:O:L:")) != -1) { switch (c) { case 'B': *************** *** 185,190 **** --- 187,201 ---- case 'l': buflen = atoi(optarg); break; + case 'L': + #if defined(SO_LINGER) + linger_opt.l_onoff = 1; + linger_opt.l_linger = atoi(optarg); + #else + fprintf(stderr, + "ttcp: -L option ignored: SO_LINGER socket option not supported\n"); + #endif + break; case 's': sinkmode = !sinkmode; break; *************** *** 316,321 **** --- 327,339 ---- #endif err("setsockopt"); } + #if defined(SO_LINGER) + if (linger_opt.l_onoff) { + if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof linger_opt) < 0) + err("setsockopt: linger"); + mes("linger"); + } + #endif #ifdef TCP_NODELAY if (nodelay) { struct protoent *p;