📄 ulibnmp.c
字号:
/*--------------------------------------------------------------------*/
/* u l i b n m p . c */
/* */
/* OS/2 named pipe support for UUCICO */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1989-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by the */
/* UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: ulibnmp.c 1.7 1993/10/03 22:09:09 ahd Exp $
* $Log: ulibnmp.c $
* Revision 1.7 1993/10/03 22:09:09 ahd
* Use unsigned long to display speed
*
* Revision 1.6 1993/10/03 20:37:34 ahd
* Delete redundant error messages
*
* Revision 1.5 1993/09/29 04:49:20 ahd
* Delete obsolete variable
*
* Revision 1.4 1993/09/27 00:45:20 ahd
* OS/2 16 bit support
*
* Revision 1.3 1993/09/25 03:07:56 ahd
* Various small bug fixes
*
* Revision 1.2 1993/09/24 03:43:27 ahd
* General bug fixes to make work
*
* Revision 1.1 1993/09/23 03:26:51 ahd
* Initial revision
*
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <time.h>
/*--------------------------------------------------------------------*/
/* OS/2 include files */
/*--------------------------------------------------------------------*/
#define INCL_DOSDEVIOCTL
#define INCL_BASE
#include <os2.h>
#include <limits.h>
#ifndef __OS2__
typedef USHORT APIRET ; // Define older API return type
#endif
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "ulibnmp.h"
#include "ssleep.h"
#include "catcher.h"
#include "commlib.h"
#include "pos2err.h"
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
currentfile();
static boolean carrierDetect = FALSE; /* Modem is not connected */
static boolean hangupNeeded = FALSE;
static BPS currentSpeed = 0;
static boolean passive;
#define FAR_NULL ((PVOID) 0L)
/*--------------------------------------------------------------------*/
/* Definitions of control structures for DOS API */
/*--------------------------------------------------------------------*/
static HPIPE pipeHandle;
static USHORT writeWait = 200;
static USHORT readWait = 50;
static int writes, reads, writeSpins, readSpins;
/*--------------------------------------------------------------------*/
/* p p a s s i v e o p e n l i n e */
/* */
/* Open a server pipe connection */
/*--------------------------------------------------------------------*/
#ifdef __TURBOC__
#pragma argsused
#endif
int ppassiveopenline(char *name, BPS baud, const boolean direct )
{
APIRET rc;
if (portActive) /* Was the port already active? */
closeline(); /* Yes --> Shutdown it before open */
#ifdef UDEBUG
printmsg(15, "ppassiveopenline: %s, %d", name, baud);
#endif
/*--------------------------------------------------------------------*/
/* Perform the open */
/*--------------------------------------------------------------------*/
#ifdef __OS2__
rc = DosCreateNPipe( (PSZ) "\\pipe\\uucp",
&pipeHandle,
NP_ACCESS_DUPLEX | NP_INHERIT | NP_NOWRITEBEHIND,
NP_NOWAIT | 1,
MAXPACK,
MAXPACK,
30000 );
#else
rc = DosMakeNmPipe( (PSZ) "\\pipe\\uucp",
&pipeHandle,
NP_ACCESS_DUPLEX | NP_INHERIT | NP_NOWRITEBEHIND,
NP_NOWAIT | 1,
MAXPACK,
MAXPACK,
30000 );
#endif
/*--------------------------------------------------------------------*/
/* Check the open worked. We translation the common obvious */
/* error of file in use to english, for all other errors are we */
/* report the raw error code. */
/*--------------------------------------------------------------------*/
if ( rc == ERROR_SHARING_VIOLATION)
{
printmsg(0,"Pipe %s already in use", name);
return TRUE;
}
else if ( rc )
{
printOS2error("DosCreateNPipe", rc );
return TRUE;
}
/*--------------------------------------------------------------------*/
/* Set baud rate */
/*--------------------------------------------------------------------*/
SIOSpeed(baud); // Just any old large number.
traceStart( name ); // Enable logging
portActive = TRUE; /* Record status for error handler */
passive = TRUE;
carrierDetect = FALSE; /* Modem is not connected */
return 0;
} /* ppassiveopenline */
/*--------------------------------------------------------------------*/
/* p W a i t F o r N e t C o n n e c t */
/* */
/* Wait for network connection */
/*--------------------------------------------------------------------*/
boolean pWaitForNetConnect(int timeout)
{
time_t stop;
stop = time( NULL ) + timeout;
do {
#ifdef __OS2__
APIRET rc = DosConnectNPipe( pipeHandle );
#else
APIRET rc = DosConnectNmPipe( pipeHandle );
#endif
if ( rc == 0 )
{
hangupNeeded = TRUE; /* Flag that the pipe is now dirty */
return TRUE;
}
else if ( rc == ERROR_PIPE_NOT_CONNECTED )
ssleep(5);
else {
printOS2error("DosConnectNPipe", rc );
return FALSE;
} /* else */
} while( (stop > time( NULL )) && ! terminate_processing );
return FALSE;
} /* pWaitForNetConnect */
/*--------------------------------------------------------------------*/
/* p a c t i v e o p e n l i n e */
/* */
/* Open a client pipe connection */
/*--------------------------------------------------------------------*/
#ifdef __TURBOC__
#pragma argsused
#endif
int pactiveopenline(char *name, BPS baud, const boolean direct )
{
APIRET rc;
#ifdef __OS2__
ULONG action;
#else
USHORT action;
#endif
if (portActive) /* Was the port already active? */
closeline(); /* Yes --> Shutdown it before open */
printmsg(15, "pactiveopenline: %s", name);
/*--------------------------------------------------------------------*/
/* Perform the open */
/*--------------------------------------------------------------------*/
rc = DosOpen( name,
&pipeHandle,
&action,
0L,
0 ,
FILE_OPEN ,
OPEN_FLAGS_FAIL_ON_ERROR |
OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE, 0L );
/*--------------------------------------------------------------------*/
/* Check the open worked. */
/*--------------------------------------------------------------------*/
if ( rc )
{
printOS2error("DosOpen", rc );
return TRUE;
}
/*--------------------------------------------------------------------*/
/* Set baud rate */
/*--------------------------------------------------------------------*/
SIOSpeed(57600);
traceStart( name ); // Enable logging
portActive = TRUE; /* Record status for error handler */
passive = FALSE;
carrierDetect = FALSE; /* Modem is not connected */
return 0;
} /* pactiveopenline */
/*--------------------------------------------------------------------*/
/* p s r e a d */
/* */
/* Read from the pipe */
/* */
/* Non-blocking read essential to "g" protocol. See "dcpgpkt.c" */
/* for description. */
/* */
/* This all changes in a multi-tasking system. Requests for I/O */
/* should get queued and an event flag given. Then the */
/* requesting process (e.g. gmachine()) waits for the event flag */
/* to fire processing either a read or a write. Could be */
/* implemented on VAX/VMS or DG but not MS-DOS. */
/* */
/* OS/2 we could multitask, but we just let the system provide */
/* a timeout for us with very little CPU usage. */
/*--------------------------------------------------------------------*/
unsigned int psread(char *output, unsigned int wanted, unsigned int timeout)
{
APIRET rc;
static char save[MAXPACK];
static USHORT bufsize = 0;
time_t stop_time ;
time_t now ;
reads++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -