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

📄 novos2.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <stddef.h>
#include <string.h>
#include <ctype.h>

#define INCL_DOSPROCESS
#define INCL_DOSSEMAPHORES
#define INCL_DOSERRORS
#include "os2.h"

#include "ipxcalls.h"
#include "spxcalls.h"
#include "spxerror.h"
#include "nwcalls.h"
#include "watcom.h"
#include "trperr.h"
#include "packet.h"
#include "trptypes.h"

#define FOREVER                 0x7FFFFFFF

#define _IPX_ASSIGNADDR( a, b ) \
                                a##Net = b##Net; \
                                AssignArray( a##Node, b##Node ); \
                                a##Socket = b##Socket

//#define InUse( ecb ) ( ( (ecb).status != 0 && (ecb).status != SPX_SUCCESSFUL ) )
#define InUse( ecb ) ( ( (ecb).status > 0x3000 && (ecb).status <= 0x3fff ) || (ecb).status == 0x1001)

#include "ipxstuff.h"

#ifdef DEBUG

void putstring( char *str )
{
    unsigned bytes;

    while( *str ) {
        DosWrite( 1, str, 1, &bytes );
        ++str;
    }
}

static char hexbuff[80];

char * hex( unsigned long num )
{
    char *p;

    p = &hexbuff[79];
    *p = 0;
    if( num == 0 ) {
      *--p = '0';
      return( p );
    }
    while( num != 0 ) {
        *--p = "0123456789abcdef"[ num & 15 ];
        num >>= 4;
    }
    return( p );
}

void puthex( unsigned long x )
{

    putstring( hex( x ) );
}

void putrc( char *func, WORD rc )
{
    if( rc == 0 ) return;
    putstring( func );
    putstring( " returned " );
    puthex( rc );
    putstring( "\r\n" );
}


void put1( unsigned char *c )
{
    if( *c < 0x10 ) putstring( "0" );
    puthex( *c );
}

void put2( unsigned char *c )
{
    put1( c );
    put1( c+1 );
}

void put4( unsigned char *c )
{
    put2( c );
    put2( c+2 );
}

void put6( unsigned char *c )
{
    put4( c );
    put2( c+4 );
}


void putnetaddr( SPX_HEADER *l ) {

    putstring( " source" );
    putstring( " net " );
    put4( (void *)&l->sourceNet );
    putstring( " node " );
    put6( (void *)&l->sourceNode );
    putstring( " socket " );
    puthex( l->sourceSocket );
    putstring( "\r\ndestination" );
    putstring( " net " );
    put4( (void *)&l->destNet );
    putstring( " node " );
    put6( (void *)&l->destNode );
    putstring( " socket " );
    puthex( (void *)&l->destSocket );
    putstring( "\r\n" );
}

void putconnstatus( WORD conn )
{
    SPX_SESSION stat;

    putstring( "Connection " );
    puthex( conn );
    putstring( " status " );
    if( SpxGetConnectionStatus( conn, &stat ) != 0 ) {
        putstring( "unknown" );
    } else {
        puthex( stat.sStatus );
        putstring( " id src " );
        puthex( stat.sSourceConnectID );
        putstring( " id dst " );
        puthex( stat.sDestConnectID );
    }
    putstring( "\r\n" );
}

#else

#define putrc( x,y )
#define putnetaddr( x )
#define puthex( x )
#define putstring( x )
#define putnetaddr( x )
#define putconnstatus( x )

#endif

#define NUM_REC_BUFFS   5

SPX_HEADER       SendHead;
SPX_HEADER       RecHead[ NUM_REC_BUFFS ];
SPX_HEADER       ConnHead;

SPX_ECB          SendECB;
SPX_ECB          ConnECB;
SPX_ECB          RecECB[ NUM_REC_BUFFS ];

char            Buffer[NUM_REC_BUFFS][MAX_DATA_SIZE];

USHORT          Connection;
USHORT          IPXSocket;
USHORT          SPXSocket;
USHORT          PartnerSPXSocket;
char            Listening;

struct {
        USHORT          checkSum;
        USHORT          packetLen;
        UCHAR           transportControl;
        UCHAR           packetType;
        ULONG           destNet;
        UCHAR           destNode[6];
        USHORT          destSocket;
        ULONG           sourceNet;
        UCHAR           sourceNode[6];
        USHORT          sourceSocket;
        USHORT          infoType;               /* high-low */
        USHORT          serverType;             /* high-low */
        UCHAR           name[48];
        LONG            addrNet;
        UCHAR           addrNode[6];
        USHORT          addrSocket;
        USHORT          intermediateNetworks;   /* high-low */
} SAPHead;

IPX_ECB          SAPECB;
IPX_HEADER       ServHead;
IPX_ECB          ServECB;
IPX_HEADER       RespHead;
IPX_ECB          RespECB;
ULONG           RecvSem = 0;
ULONG           SendSem = 0;

#define IPXRelinquishControl()  DosSleep( 1 )


static unsigned DoRemoteGet( char *rec, unsigned len )
{
    int         i;
    int         p;
    unsigned    recvd;
    unsigned    got;

putstring( "RemoteGet\r\n" );
putconnstatus( Connection );

    len = len;
    recvd = 0;
    for( ;; ) {
        DosSemSet( &RecvSem );
        i = NUM_REC_BUFFS-1;
        p = -1;
        for( ;; ) {
            if( i < 0 ) {
                if( p != -1 ) break;
                DosSemWait( &RecvSem, 1000 );
                i = NUM_REC_BUFFS-1;
            }
            if( !InUse( RecECB[i] ) ) {
                if( p == -1
                 || LOWER_SEQ( RecHead[i].sequenceNumber, RecHead[p].sequenceNumber ) ) {
                    p = i;
                }
            }
            --i;
        }
        got = _SWAPINT( RecHead[p].packetLen ) - sizeof( RecHead[p] );
        _fmemcpy( rec, Buffer[p], got );
        recvd += got;
        PostAListen( p );
        if( got != MAX_DATA_SIZE ) break;
        rec = (unsigned_8 *)rec + got;
    }

putstring( "Done RemoteGet\r\n" );
    return( recvd );
}

static unsigned DoRemotePut( char *snd, unsigned len )
{
    WORD        rc;

putstring( "RemotePut\r\n" );
putconnstatus( Connection );
    if( len == 0 ) {
        _INITSPXECB( Send, 1, NULL, 0 );
    } else {
        _INITSPXECB( Send, 2, snd, len );
    }
    SendECB.hsem = (HSEM) &SendSem;
    SendHead.connectionCtl |= 0x10;
    SendHead.packetLen = _SWAPINT( sizeof( SendHead ) + len );
    DosSemSet( &SendSem );
    rc = SpxSendSequencedPacket( Connection, &SendECB );
    putrc( "SPXSendSequencedPacket", rc );

    for( ;; ) {

⌨️ 快捷键说明

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