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

📄 dial.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
                        break;                case 150:                        sp_code = B150;                        break;                case 300:                        sp_code = B300;                        break;                case 600:                        sp_code = B600;                        break;                case 1200:                        sp_code = B1200;                        break;                case 2400:                        sp_code = B2400;                        break;                case 4800:                        sp_code = B4800;                        break;                case 9600:                        sp_code = B9600;                        break;                default:                        er = ILL_BD;                        goto RTN;        }        if((fd = open(cul, O_EXCL | O_RDWR | O_NDELAY)) < 0) {                perror(cul);                er = L_PROB;                goto RTN;        }	if(call->device && call->dev_len !=0) {		strncpy(call->device, cul, call->dev_len);		if(strlen(cul) >= call->dev_len)			call->device[call->dev_len -1] = '\0';	}        if(!call->attr)                lvp = &lv;        else                lvp = call->attr;        lvp->c_cflag |= (CREAD | HUPCL);        if(!(lvp->c_cflag & CSIZE))                lvp->c_cflag |= CS8;        if( (call->telno == NULL ) && (call->modem) ) {                lvp->c_cflag |= CLOCAL;        } else                lvp->c_cflag &= ~CLOCAL;#ifdef  ddt        if(_debug == YES) say(stderr,"value of cflag = %o\n\r", lvp->c_cflag);#endif        lvp->c_cflag &= ~CBAUD;        lvp->c_cflag |= sp_code;        if((t = ioctl(fd, TCSETA, lvp)) < 0) {                perror("stty for remote");                er = L_PROB;                goto RTN;        }        if(call->telno) {		(void)alarm(30);                if((fdac = open(cua, O_WRONLY)) < 0) {                        perror(cua);                        er = A_PROB;                        goto RTN;                }		alrmcatch();                t = strlen(strcat(strcpy(b, call->telno), ACULAST));#ifdef ddt                if(_debug == YES)                        say(stderr, "dialing %s\n", b);#endif                w = write(fdac, b, (unsigned)t); /* dial the number */                x = errno;		p = &b[t-2];		for(; *p-- == '-'; t--);                if(w < t) {                        errno = x;                        if(w == -1)                                perror("write to acu");                        else                                say(stderr, "%s: Semaphore failure\n", cul);                        er = (errno == EINTR)? D_HUNG: A_PROB;			(void)close(fdac);                        goto RTN;                }                (void)close(fdac);      /* dialing is complete */#ifdef ddt                if(_debug == YES)                        say(stderr, "dialing complete\n");#endif        }        (void)alarm(20);        /* should answer within 20 seconds */        dum = open(cul, O_RDWR); /* wait here for carrier */        x = errno;	alrmcatch();        if(dum < 0) {                errno = x;#ifdef ddt                if(_debug == YES)                        perror(cul);#endif                er = (errno == EINTR)? NO_ANS: L_PROB;                goto RTN;        }        (void)close(dum);       /* the dummy open used for waiting*/        (void)fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NDELAY);RTN:        if(intflag == YES)                er = INTRPT;#ifdef ddt        if(_debug == YES)                say(stderr, "connect ends with er=%d, fd=%d\n", er, fd);#endif	if(er) {		close(fd);				return(er);	} else		return(fd);}/*************************************************************** *      find_dev: find a device pair with the wanted characteristics *            specified in line and baud arguments. *      Return pointer to device name for use in lock-out semaphore. *      The variables 'cua' and 'cul' will be set to contain the *              complete path names of the corresponding devices. *      If the L-devices list contains a '0' entry because the *              line is direct, the variable 'cua' is set to '\0'. ***************************************************************/static char*find_dev(iop, call)FILE *iop;CALL *call;{        char buf[50], typ[4], temp[15], *b;        int tspeed;#ifdef ddt        if(_debug == YES) {                say(stderr, "call find_dev(%o)\n", call);                dump(call, 0);        }#endif        if(call->telno == NULL)                (void)strcpy(typ, "DIR");        else                (void)strcpy(typ, "ACU");        while(fgets(buf, 50, iop) != NULL) {                if (strchr("# \t\n", buf[0]) != NULL)                        continue;                if(DIFFER(typ, strtok(buf, " \t")))                        continue;                (void)strcat(strcpy(cul,DEVDIR),strtok((char*)0," \t"));                if(*(b = strtok((char*)0, " \t")) == '0')                        cua[0] = '\0';                else {                        (void)strcat(strcpy(cua, DEVDIR), b);                } tspeed = atoi(strtok((char*)0," \t\n"));                if(call->line) {                        if(strchr((b=call->line), '/') == 0) {                                (void)strcpy(temp, DEVDIR);                                b = strcat(temp, call->line);                        }                        if(DIFFER(b, cul))                                continue;			if(call->baud < 0) {				/*found line, no baud rate requested, set */                        	call->baud = call->speed = tspeed;			} else if(tspeed != call->baud) {				/* found line at wrong speed, keep looking */				sperfg = 1;				continue;			} else {				/* found line at correct speed, clear error */				sperfg = 0;			}                }                if(call->telno) {                        if(call->speed != tspeed)                                continue;                }                if(call->baud > call->speed)                        continue;                ++found;                return(1+strrchr(cul, '/'));        }        return("");}voidundial(rfd)int rfd;{#ifdef ddt        if(_debug == YES)                say(stderr, "call undial(%d)\n", rfd);#endif        if(rfd > 0)                 (void)close(rfd);        if(lfd > 0) {                (void)close(lfd);                lfd = -1;                if(unlink(lock) < 0)                        say(stderr, "Can't unlink lock-file\r\n");#ifdef ddt                else if(_debug == YES)                        say(stderr, "Lock-file unlinked\r\n");#endif        }        return;}static void	/* DAG */alrmcatch(){        (void)alarm(UPDTE);        (void)utime(lock, (struct {long a,b;} *)0);        (void)signal(SIGALRM, alrmcatch);}static void	/* DAG */hupcatch(){        undial(rlfd);}static void	/* DAG */intcatch(){        intflag = YES;        (void)signal(SIGINT, intcatch);}#ifdef ddtstatic voiddump(arg, fd)CALL *arg;int fd;{        struct termio xv;        int i;        if(fd > 0) {                say(stderr, "\r\ndevice status for fd=%d\r\n", fd);                say(stderr, "F_GETFL=%o\r\n", fcntl(fd, F_GETFL,1));                if(ioctl(fd, TCGETA, &xv) < 0) {                        char buf[100];                        int x=errno;                        (void)sprintf(buf, "\rtdmp for fd=%d:", fd);                        errno = x;                        perror(buf);                        return;                }                say(stderr, "iflag=`%o',", xv.c_iflag);                say(stderr, "oflag=`%o',", xv.c_oflag);                say(stderr, "cflag=`%o',", xv.c_cflag);                say(stderr, "lflag=`%o',", xv.c_lflag);                say(stderr, "line=`%o'\r\n", xv.c_line);                say(stderr, "cc[0]=`%o',", xv.c_cc[0]);                for(i=1; i<8; ++i)                        say(stderr, "[%d]=`%o',", i, xv.c_cc[i]);                say(stderr, "\r\n");        }        say(stderr,"baud=%d, ",arg->baud);        say(stderr,"speed=%d, ",arg->speed);        say(stderr,"line=%s, ",arg->line? arg->line: "(null)");        say(stderr,"telno=%s\r\n",arg->telno? arg->telno: "(null)");}#endif

⌨️ 快捷键说明

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