acksend.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 112 行
C
112 行
#ifndef lintstatic char *sccsid = "@(#)acksend.c 4.1 (ULTRIX) 7/2/90";#endif lint/************************************************************************ * * * Copyright (c) 1988 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* * Copyright (c) 1985 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. *static char sccsid[] = "@(#)acksend.c 2.4 (Berkeley) 5/27/86"; */#include "globals.h"#include <protocols/timed.h>#define RECEIVED 0#define LOST 1#define SECFORACK 1 /* seconds */#define USECFORACK 0 /* microseconds */#define MAXCOUNT 5struct tsp *answer;/* * Acksend implements reliable datagram transmission by using sequence * numbers and retransmission when necessary. * `name' is the name of the destination * `addr' is the address to send to * If `name' is ANYADDR, this routine implements reliable broadcast. */struct tsp *acksend(message, addr, name, ack, net)struct tsp *message;struct sockaddr_in *addr;char *name;int ack;struct netinfo *net;{ int count; int flag; extern u_short sequence; struct timeval tout; struct tsp *readmsg(); count = 0; message->tsp_vers = TSPVERSION; message->tsp_seq = sequence; if (trace) { fprintf(fd, "acksend: "); if (name == ANYADDR) fprintf(fd, "broadcast: "); else fprintf(fd, "%s: ", name); print(message, addr); } bytenetorder(message); do { if (sendto(sock, (char *)message, sizeof(struct tsp), 0, addr, sizeof(struct sockaddr_in)) < 0) { syslog(LOG_ERR, "acksend: sendto: %m"); exit(1); } tout.tv_sec = SECFORACK; tout.tv_usec = USECFORACK; answer = readmsg(ack, name, &tout, net); if (answer != NULL) { if (answer->tsp_seq != sequence) { if (trace) fprintf(fd, "acksend: seq # %d != %d\n", answer->tsp_seq, sequence); continue; } flag = RECEIVED; } else { flag = LOST; if (++count == MAXCOUNT) { break; } } } while (flag != RECEIVED); sequence++; return(answer);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?