home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
dax1.exe
/
CP
/
CPS
/
CPSEND.C
< prev
next >
Wrap
Text File
|
1992-07-15
|
7KB
|
166 lines
// ╔════════════════════════════════════════════════════════════════════╗
// ║ ║
// ║ module: cpsend.c ║
// ║ abstract: This module contains the support for sending messages ║
// ║ to client nodes. ║
// ║ ║
// ║ environment: NetWare 3.x v3.11 ║
// ║ Network C for NLMs SDK ║
// ║ CLib v3.11 ║
// ║ ║
// ║ 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/29/92 kl initial release. ║
// ╚════════════════════════════════════════════════════════════════════╝
#include <stdlib.h>
#include <string.h>
#include <nwmisc.h>
#include <process.h>
#include "cp/cpsys.h"
//------------------------------------------------------------------------
STATIC CPCOMMDATA sends[CPSNUMSENDELEM];
//------------------------------------------------------------------------
//
// This API locates one of the 'send' structures that is free
//
STATIC CPCOMMDATA *CPFindFreeCPCommData()
{
int i;
for(i=0; i < CPSNUMSENDELEM; ++i)
if(!sends[i].ecb.status || sends[i].ecb.status > 0xF000)
return &sends[i];
DIAG3("CPFindFreeCPCommData() couldn't!");
return NULL;
}
//------------------------------------------------------------------------
//
// This API initializes a send ECB. i.e. readies it for transport...
//
void CPInitSendPacket(WORD socket, // socket to send on
IPX_ECB *ecb, // the ecb
IPX_HEADER *hdr, // the ipx header
void *request, // the data portion
WORD sizeRequest) // the data portion size
{
//
// Note that since the socket is a parameter to the IPX CLIB
// functions, it can be init'ed here, or simply passed via Send.
// If you init here, then pass 0 when you call IpxSend...
//
ecb->socket = socket;
ecb->fragCount = 2;
ecb->fragList[0].fragAddress = hdr;
ecb->fragList[0].fragSize = sizeof( IPX_HEADER );
ecb->fragList[1].fragAddress = request;
ecb->fragList[1].fragSize = sizeRequest;
hdr->packetType = (char)4;
//
// The remaining fields requiring initialization, will be filled
// when a packet is sent. i.e. the destination net, node and socket
// of the IPX header, and immediateAddress field of ECB.
//
}
//------------------------------------------------------------------------
//
// This API gets the CP Layer ready to send data to the client
//
T_RC CPInitializeSendLogic()
{
int i;
//
// Get all of our send structures ready for sending replies.
//
for(i=0; i < CPSNUMSENDELEM; ++i){
CPInitSendPacket(0,
&sends[i].ecb,
&sends[i].ipx,
&sends[i].cpmsg,
sizeof sends[i].cpmsg);
}
return CP_SUCCESS;
}
//------------------------------------------------------------------------
//
// This API sends a reply to the client
//
T_RC CPSendMessage(UINT32 sessionID, void *data, unsigned length)
{
LONG tTime;
WORD startTicks,endTicks;
CPCOMMDATA *c = CPFindFreeCPCommData();
CPDATA *p = CPGetClientInfo(sessionID);
if( !p ) return CP_UNKNOWN_CLIENT;
if( !c ) return CP_TRANSPORT_BUSY;
c->cpmsg.cphdr = p->cphdr;
memmove(c->cpmsg.msg,data,min(CPMAXMSG,length));
//
// Set address of destination before sending...
//
*(InternetAddress *)&c->ipx.destNet = p->ipxaddr;
IpxGetLocalTarget((BYTE *)&c->ipx.destNet,&c->ecb, &tTime);
xDIAG4(CPprintf("CPSend: Sending to %08x:%08x%04x:%04x\n",
LongSwap(c->ipx.destNet),
LongSwap(*(LONG *)c->ipx.destNode),
IntSwap(*(WORD *)&c->ipx.destNode[4]),
IntSwap(c->ipx.destSocket)));
IpxSend(0,&c->ecb);
//
// wait tTime for the packet to get onto the wire.
//
startTicks = GetCurrentTicks(); // read start time
while( c->ecb.status ){
ThreadSwitch();
endTicks = GetCurrentTicks();
//
// Give it enough time to get there. Shouldn't take this
// long to get it out on the wire...
//
if( endTicks - startTicks > tTime ){
DIAG3("CPSendMessage() timed out!");
break;
}
}
if( c->ecb.status ) DIAG3("CPSendMessage() couldn't!");
return c->ecb.status ? CP_TRANSPORT_ERROR : CP_SUCCESS;
}
//------------------------------------------------------------------------
//
// This API shuts the send logic down
//
T_RC CPDeInitializeSendLogic()
{
int i;
//
// Get all of our send structures ready for sending replies.
//
for(i=0; i < CPSNUMSENDELEM; ++i){
while( sends[i].ecb.status > 0 && sends[i].ecb.status < 0x7f )
ThreadSwitch();
}
return CP_SUCCESS;
}