home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
dax1.exe
/
CP
/
CPC
/
CPSEND.C
< prev
next >
Wrap
Text File
|
1992-07-15
|
6KB
|
152 lines
// ╔════════════════════════════════════════════════════════════════════╗
// ║ ║
// ║ module: cpsend.c ║
// ║ abstract: This module contains the APIs to send messages. ║
// ║ ║
// ║ environment: NetWare 3.x v3.11 ║
// ║ Network C for NLMs SDK v2.0d ║
// ║ CLib v3.11 ║
// ║ Network C for DOS v2.0 ║
// ║ NetWare C Interface DOS v1.2 ║
// ║ ║
// ║ This software is provided as is and carries no warranty ║
// ║ whatsoever. Novell disclaims and excludes any and all implied ║
// ║ warranties of merchantability, title and fitness for a particular ║
// ║ purpose. Novell does not warrant that the software will satisfy ║
// ║ your requirements or that the software is without defect or error ║
// ║ or that operation of the software will be uninterrupted. You are ║
// ║ using the software at your risk. The software is not a product ║
// ║ of Novell, Inc. or any of subsidiaries. ║
// ║ ║
// ╟────────────────────────────────────────────────────────────────────╢
// ║ maintenance history: ║
// ║ level date pi description ║
// ╟────────────────────────────────────────────────────────────────────╢
// ║ 001 01/24/92 kl initial release. ║
// ║ 002 07/14/92 kl windows port. ║
// ╚════════════════════════════════════════════════════════════════════╝
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#include "cp/cpsys.h"
#include <nwmisc.h>
//------------------------------------------------------------------------
//
// This API locates one of the 'send' structures that is free
//
STATIC CPCOMMDATA *CPFindFreeCPCommData(CPDATA *CPid)
{
int i;
for(i=0; i < CPCNUMSENDECBS; ++i)
if( !ECBISINUSE(&CPid->sends[i].ecb) ) return &CPid->sends[i];
return NULL;
}
//------------------------------------------------------------------------
//
// This API initializes a send ECB. i.e. readies it for transport...
//
void CPInitSendPacket(WORD socket,
ECB *ecb,
IPXHeader *packet,
void *request,
WORD sizeRequest,
IPXAddress *destination)
{
#if defined(DOSCLIENT) || defined(WINCLIENT)
packet->destination = *destination;
#elif defined(NLMCLIENT)
*(IPXAddress *)&packet->destNet = *destination;
#endif
packet->packetType = 4;
ECBFRAGCOUNT(ecb) = 2;
ECBSOCKET(ecb) = socket;
ECBFRAGADDR(ecb,0) = packet;
ECBFRAGSIZE(ecb,0) = sizeof(IPXHeader);
ECBFRAGADDR(ecb,1) = request;
ECBFRAGSIZE(ecb,1) = sizeRequest;
}
//------------------------------------------------------------------------
//
// This API gets the CP Layer ready to send data to the server
//
T_RC CPInitializeSendLogic(CPDATA *CPid)
{
int i;
//
// Get two send ECBs ready. One for sending requests, and one
// for sending replies. This implementation only needs one,
// since we don't support sending replies from the client.
//
for(i=0; i < CPCNUMSENDECBS; ++i){
CPInitSendPacket(CPid->skt,
&CPid->sends[i].ecb,
&CPid->sends[i].ipx,
&CPid->sends[i].cpmsg,
sizeof CPid->sends[i].cpmsg,
&CPid->ipxaddr);
}
return CP_SUCCESS;
}
//------------------------------------------------------------------------
//
// This API sends a request to the server
//
T_RC CPSendMessage(CPDATA *CPid, void *data, unsigned length)
{
int tTime;
WORD startTicks,endTicks;
CPCOMMDATA *c = CPFindFreeCPCommData(CPid);
if( !c ) return CP_TRANSPORT_BUSY;
if( CPid->sip != TRUE ) return CP_NO_SESSION_IN_PROGRESS;
c->cpmsg.cphdr = CPid->cphdr;
memmove(c->cpmsg.msg,data,min(CPMAXMSG,length));
#if defined(DOSCLIENT) || defined(WINCLIENT)
IPXGetLocalTarget((BYTE *)c->ipx.destination.network,
c->ecb.immediateAddress, &tTime);
#elif defined(NLMCLIENT)
IpxGetLocalTarget((char *)&c->ipx.destNet, &c->ecb, (LONG *)&tTime);
#endif
IPXSend(&c->ecb);
//
// wait tTime for the packet to get onto the wire.
//
startTicks = IPXGetIntervalMarker(); // read start time
while( ECBISINUSE(&c->ecb) ){
IPXRelinquishControl();
endTicks = IPXGetIntervalMarker();
//
// Give it enough time to get there. Shouldn't take this
// long to get it out on the wire...
//
if( endTicks - startTicks > tTime ) break;
}
xDIAG4(CPprintf(ECBISINUSE(&c->ecb) ? "returning with inuseflag set on send\n" : ""));
return (ECBISINUSE(&c->ecb) || COMPLETIONCODE(&c->ecb))
? CP_TRANSPORT_ERROR
: CP_SUCCESS;
}
#pragma off(unreferenced);
void CPDeInitializeSendLogic(CPDATA *CPid)
#pragma on(unreferenced);
{
int i;
//
// Wait for the send ECBs to finish sending.
//
for(i=0; i < CPCNUMSENDECBS; ++i){
while( ECBISINUSE(&CPid->sends[i].ecb) )
IPXRelinquishControl();
}
}