📄 ulibnmp.c
字号:
/*--------------------------------------------------------------------*/
/* Determine if our internal buffer has the data */
/*--------------------------------------------------------------------*/
if (bufsize >= wanted)
{
memmove( output, save, wanted );
bufsize -= wanted;
if ( bufsize ) /* Any data left over? */
memmove( save, &save[wanted], bufsize ); /* Yes --> Save it*/
return wanted + bufsize;
} /* if */
/*--------------------------------------------------------------------*/
/* Determine when to stop processing */
/*--------------------------------------------------------------------*/
if ( timeout == 0 )
{
stop_time = 0;
now = 1; /* Any number greater than stop time */
}
else {
time( & now );
stop_time = now + timeout;
}
/*--------------------------------------------------------------------*/
/* Try to read any needed data into the buffer */
/*--------------------------------------------------------------------*/
do {
USHORT needed = (USHORT) wanted - bufsize;
#ifdef __OS2__
ULONG received = 0;
#else
USHORT received = 0;
#endif
/*--------------------------------------------------------------------*/
/* Handle an aborted program */
/*--------------------------------------------------------------------*/
if ( terminate_processing )
{
static boolean recurse = FALSE;
if ( ! recurse )
{
printmsg(2,"sread: User aborted processing");
recurse = TRUE;
}
return 0;
}
readSpins++;
ddelay(readWait);
/*--------------------------------------------------------------------*/
/* Read the data from the named pipe */
/*--------------------------------------------------------------------*/
rc = DosRead( pipeHandle, &save[bufsize], needed, &received );
if ( rc == ERROR_NO_DATA)
{
received = 0;
}
else if ( rc )
{
printmsg(0,"psread: Read from pipe for %d bytes failed.",
needed);
printOS2error("DosRead", rc );
bufsize = 0;
return 0;
}
#ifdef UDEBUG
printmsg(15,"psread: Want %d characters, received %d, total %d in buffer",
(int) wanted, (int) received, (int) bufsize + received);
#endif
/*--------------------------------------------------------------------*/
/* Log the newly received data */
/*--------------------------------------------------------------------*/
traceData( &save[bufsize], received, FALSE );
/*--------------------------------------------------------------------*/
/* If we got the data, return it to the caller */
/*--------------------------------------------------------------------*/
bufsize += received;
if ( bufsize == wanted )
{
memmove( output, save, bufsize);
bufsize = 0;
return wanted;
} /* if */
/*--------------------------------------------------------------------*/
/* Update the clock for the next pass */
/*--------------------------------------------------------------------*/
if (stop_time > 0)
time( &now );
} while (stop_time > now);
/*--------------------------------------------------------------------*/
/* We don't have enough data; report what we do have */
/*--------------------------------------------------------------------*/
return bufsize;
} /* nsread */
/*--------------------------------------------------------------------*/
/* p s w r i t e */
/* */
/* Write to the named pipe */
/*--------------------------------------------------------------------*/
int pswrite(const char *input, unsigned int len)
{
char *data = (char *) input;
unsigned int left = len;
#ifdef __OS2__
ULONG bytes;
#else
size_t bytes;
#endif
APIRET rc;
hangupNeeded = TRUE; /* Flag that the pipe is now dirty */
writes ++;
/*--------------------------------------------------------------------*/
/* Write the data out as the queue becomes available */
/*--------------------------------------------------------------------*/
do {
rc = DosWrite( pipeHandle, data + len - left, left, &bytes);
if (rc)
{
printOS2error("DosWrite", rc );
return bytes;
} /*if */
left -= bytes;
ddelay( writeWait );
writeSpins ++;
} while( left > 0 );
/*--------------------------------------------------------------------*/
/* Log the data written */
/*--------------------------------------------------------------------*/
traceData( data, len, TRUE);
/*--------------------------------------------------------------------*/
/* Return bytes written to the pipe to the caller */
/*--------------------------------------------------------------------*/
return len;
} /* nswrite */
#ifdef __TURBOC__
#pragma argsused
#endif
/*--------------------------------------------------------------------*/
/* p s s e n d b r k */
/* */
/* send a break signal out the pipe */
/*--------------------------------------------------------------------*/
void pssendbrk(unsigned int duration)
{
printmsg(0,"pssendbrk: BREAK not supported with named pipes");
} /* nssendbrk */
/*--------------------------------------------------------------------*/
/* p c l o s e l i n e */
/* */
/* Close the named pipe down */
/*--------------------------------------------------------------------*/
void pcloseline(void)
{
APIRET rc;
if ( ! portActive )
panic();
portActive = FALSE; /* flag pipe closed for error handler */
hangupNeeded = FALSE; /* Don't fiddle with pipe any more */
printmsg(4,
"pcloseline: Read delay %d ms, Write delay %d ms",
(int) readWait,
(int) writeWait );
printmsg(4,
"pcloseline: %d reads (%d waits), %d writes (%d waits)",
(int) reads,
(int) readSpins - reads,
(int) writes,
(int) writeSpins - writes );
/*--------------------------------------------------------------------*/
/* Actually close the pipe */
/*--------------------------------------------------------------------*/
rc = DosClose( pipeHandle );
if ( rc )
printOS2error("DosClose", rc );
/*--------------------------------------------------------------------*/
/* Stop logging the data to disk */
/*--------------------------------------------------------------------*/
traceStop();
} /* pcloseline */
/*--------------------------------------------------------------------*/
/* p h a n g u p */
/* */
/* Hangup the link. No operation on network. */
/*--------------------------------------------------------------------*/
void phangup( void )
{
if ( passive && hangupNeeded)
{
#ifdef __OS2__
DosDisConnectNPipe( pipeHandle );
#else
DosDisConnectNmPipe( pipeHandle );
#endif
hangupNeeded = FALSE;
}
return;
} /* phangup */
/*--------------------------------------------------------------------*/
/* p S I O S p e e d */
/* */
/* Re-specify the speed of an opened pipe; no operation, actually. */
/*--------------------------------------------------------------------*/
#ifdef __TURBOC__
#pragma argsused
#endif
void pSIOSpeed(BPS baud)
{
currentSpeed = baud;
return;
} /* pSIOSpeed */
/*--------------------------------------------------------------------*/
/* p f l o w c o n t r o l */
/* */
/* Enable/Disable in band (XON/XOFF) flow control */
/*--------------------------------------------------------------------*/
#ifdef __TURBOC__
#pragma argsused
#endif
void pflowcontrol( boolean flow )
{
return;
} /* pflowcontrol */
/*--------------------------------------------------------------------*/
/* n G e t S p e e d */
/* */
/* Report current speed of communications connection */
/*--------------------------------------------------------------------*/
BPS pGetSpeed( void )
{
return currentSpeed;
} /* nGetSpeed */
/*--------------------------------------------------------------------*/
/* p C D */
/* */
/* Return status of carrier detect */
/*--------------------------------------------------------------------*/
boolean pCD( void )
{
return carrierDetect;
} /* pCD */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -