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

📄 ptydrv.c

📁 VxWorks操作系统内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    pPseudoDev = (PSEUDO_DEV *)pMasterDev;    tyDevRemove ( (TY_DEV_ID)pMasterDev);    free (pPseudoDev);    return (OK);    }/********************************************************************************* ptyMasterOpen - open the Master side of a pseudo terminal** ARGSUSED1*/LOCAL int ptyMasterOpen    (    PSEUDO_DEV *pPseudoDev,    char *name,    int mode    )    {    return ((int) pPseudoDev);    }/********************************************************************************* ptySlaveOpen - open the Slave side of a pseudo terminal** ARGSUSED1*/LOCAL int ptySlaveOpen    (    PSEUDO_DEV *pPseudoDev,    char *name,    int mode    )    {    return ((int) pPseudoDev - (OFFSET(PSEUDO_DEV, slaveDev)));    }/********************************************************************************* ptySlaveClose - close the Slave side of a pseudo terminal** Closing the slave side should cause the master to read 0 bytes.** RETURNS: OK*/LOCAL STATUS ptySlaveClose    (    PSEUDO_DEV *pPseudoDev    )    {    pPseudoDev->ateof = FALSE;	/* indicate to master read of close */    semGive (&pPseudoDev->masterReadSyncSem);     if(_func_selWakeupAll != NULL)     	{    	/* wake up any process waiting so they read the 0 bytes */	(* _func_selWakeupAll) (&pPseudoDev->masterSelWakeupList, SELREAD);    	}    return (OK);    }/********************************************************************************* ptyMasterClose - close the Master side of a pseudo terminal** Closing the master side will cause the slave's read to return ERROR.** RETURNS: OK*/LOCAL STATUS ptyMasterClose    (    PSEUDO_DEV *pPseudoDev    )    {    tyIoctl ((TY_DEV_ID) pPseudoDev, FIOCANCEL, 0 /*XXX*/);    return (OK);    }/********************************************************************************* ptySlaveRead - slave read routine** The slave device simply calls tyRead to get data out of the ring buffer.** RETURNS: whatever tyRead returns (number of bytes actually read)*/LOCAL int ptySlaveRead    (    PSEUDO_DEV *pPseudoDev,    char *buffer,    int maxbytes    )    {    int i;    i=tyRead ((TY_DEV_ID) pPseudoDev, buffer, maxbytes);    if (_func_selWakeupAll != NULL)     	{    	/* When anything gets read from the slave and the buffer is below         * the threshhold wake processes waiting         * on SELWRITE of master pty fd          */ 	if (rngNBytes (pPseudoDev->tyDev.rdBuf) < ptyWrtThreshold )      		(* _func_selWakeupAll) (&pPseudoDev->masterSelWakeupList, SELWRITE );    	}    return(i); 	    }/********************************************************************************* ptyMasterRead - master read routine** The master read routine calls tyITx to empty the pseudo terminal's buffer.** RETURNS: number of characters actually read*/LOCAL int ptyMasterRead    (    PSEUDO_DEV *pPseudoDev,    char *buffer,               /* where to return characters read */    int maxbytes    )    {    int i;    char ch;    pPseudoDev->ateof = TRUE;    for (i = 0; i == 0;)	{	while ((i < maxbytes) && (tyITx ((TY_DEV_ID) pPseudoDev, &ch) == OK))	    buffer [i++] = ch;	if (!pPseudoDev->ateof)	    break;	if (i == 0)	    semTake (&pPseudoDev->masterReadSyncSem, WAIT_FOREVER);	}        return (i);    }/********************************************************************************* ptySlaveWrite - pseudo terminal Slave write routine** This routine simply calls tyWrite.** RETURNS: whatever tyWrite returns (number of bytes actually written)*/LOCAL int ptySlaveWrite    (    PSEUDO_DEV *pPseudoDev,    char *buffer,    int nbytes    )    {    int written;         written = tyWrite ((TY_DEV_ID) pPseudoDev, buffer, nbytes);        if(_func_selWakeupAll != NULL)     	{    	/* When anything gets written to the slave wake processes waiting         * on SELREAD of master pty fd          */ 	if(rngNBytes(pPseudoDev->tyDev.wrtBuf))   			(* _func_selWakeupAll) (&pPseudoDev->masterSelWakeupList, SELREAD);    	}    return(written);	    }/********************************************************************************* ptyMasterWrite - pseudo terminal Master write routine** This routine calls tyIRd to put data in the pseudo terminals ring buffer.** RETURNS: nbytes*/LOCAL int ptyMasterWrite    (    PSEUDO_DEV *pPseudoDev,    char *buffer,    int nbytes    )    {    int i;    for (i = 0; i < nbytes; i++)	if (tyIRd ((TY_DEV_ID) pPseudoDev, buffer [i]) == ERROR)	    break;	        return (i);    }/********************************************************************************* ptySlaveIoctl - special device control*/LOCAL STATUS ptySlaveIoctl    (    PSEUDO_DEV *pPseudoDev,     /* device to control */    int request,                /* request code */    int arg                     /* some argument */    )    {    return (tyIoctl ((TY_DEV_ID) pPseudoDev, request, arg));    }/********************************************************************************* ptyMasterIoctl - special device control*/LOCAL STATUS ptyMasterIoctl    (    PSEUDO_DEV *pPseudoDev,     /* device to control */    int request,                /* request code */    int arg                     /* some argument */    )    {	switch (request)	{		   case FIOSELECT:		if ( _func_selPtyAdd != NULL )		   	_func_selPtyAdd(pPseudoDev, arg);  		break;       	   case FIOUNSELECT:		if ( _func_selPtyDelete != NULL )		   	_func_selPtyDelete(pPseudoDev, arg);  		break;	   default:	    	return (tyIoctl ((TY_DEV_ID) pPseudoDev, request, arg));	}	return(OK);    }/********************************************************************************* ptyMasterStartup - start up the Master read routine*/LOCAL void ptyMasterStartup    (    PSEUDO_DEV *pPseudoDev    )    {    semGive (&pPseudoDev->masterReadSyncSem);    }#undef PTY_DEBUG#ifdef PTY_DEBUGextern DL_LIST 	iosDvList;			/* list of I/O device headers *//*********************************************************************************  ptyShow - show the state of the Pty Buffers */void ptyShow(void){    PSEUDO_DEV *pDevHdr;    int rd,wrt;	    logMsg("%-20s %-8s %-8s\n", "name","read","write",0,0,0);    for (pDevHdr = (PSEUDO_DEV *) DLL_FIRST (&iosDvList); pDevHdr != NULL;		pDevHdr = (PSEUDO_DEV *) DLL_NEXT (&pDevHdr->tyDev.devHdr.node))    {	        if( pDevHdr->tyDev.devHdr.drvNum == ptyMasterDrvNum )	{			rd = rngNBytes (pDevHdr->tyDev.rdBuf);		wrt = rngNBytes (pDevHdr->tyDev.wrtBuf);				logMsg("%-20s %-8d %-8d\n", pDevHdr->tyDev.devHdr.name, wrt,rd,0,0,0);	}     }}#endif

⌨️ 快捷键说明

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