cdev-1.7.2n
This commit is contained in:
+173
@@ -0,0 +1,173 @@
|
||||
#include <EarlyDeath.h>
|
||||
#include <cdevMessage.h>
|
||||
#include <clipMagicNumber.h>
|
||||
#include <xdrClass.h>
|
||||
|
||||
int GlobalDone = 0;
|
||||
cdevReactor GlobalReactor;
|
||||
|
||||
// *****************************************************************************
|
||||
// * EarlyDeathHandler::EarlyDeathHandler
|
||||
// * Default constructor for the EarlyDeathHandler class
|
||||
// *****************************************************************************
|
||||
EarlyDeathHandler::EarlyDeathHandler ( void )
|
||||
: stream()
|
||||
{
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * open:
|
||||
// * Established a connection with the host specified by remote_sap
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::open ( const cdevAddr & addr )
|
||||
{
|
||||
int result = stream.connect (addr);
|
||||
if (result != -1)
|
||||
{
|
||||
if((result = GlobalReactor.registerHandler(this, READ_MASK|WRITE_MASK|EXCEPT_MASK))==-1)
|
||||
{
|
||||
handleClose();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * ~EarlyDeathHandler:
|
||||
// * Default destructor for the EarlyDeathHandler object.
|
||||
// *****************************************************************************
|
||||
EarlyDeathHandler::~EarlyDeathHandler (void)
|
||||
{
|
||||
GlobalReactor.extractHandler(this);
|
||||
handleClose();
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * EarlyDeathHandler::getHandle
|
||||
// * Allows the caller to obtain the file identifier of the socket.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::getHandle (void) const
|
||||
{
|
||||
return stream.getHandle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleClose:
|
||||
// * Closes the stream.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::handleClose (void)
|
||||
{
|
||||
stream.close();
|
||||
fprintf(stdout, "=> Closing the EarlyDeath handler\n");
|
||||
fflush(stdout);
|
||||
GlobalDone = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleInput :
|
||||
// * This function is called when data is ready to be read from a connected
|
||||
// * socket. This function will read the data from the socket, and will then
|
||||
// * submit the buffer to the ServerInterface class for processing.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::handleInput (void)
|
||||
{
|
||||
char buf[1000];
|
||||
|
||||
fprintf(stdout, "=> Receiving unwanted input\n");
|
||||
fflush(stdout);
|
||||
|
||||
while(stream.recv(buf, 1000)>0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleOutput :
|
||||
// * This function is called when data is ready to be transmitted to a
|
||||
// * connected socket. This function will read the data from the queue,
|
||||
// * translate it to XDR, and then transmit it to the client.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::handleOutput ( void )
|
||||
{
|
||||
static int count = 0;
|
||||
|
||||
long length = 72;
|
||||
long packets = 1;
|
||||
long magic = CLIP_MAGIC_NUMBER;
|
||||
char * deviceList = "device1";
|
||||
cdevMessageBinary msg (1, 12, 0, 100, 200, 22, 14, 1, (char **)&deviceList, (char *)"get funky");
|
||||
XDR_Writer writer (2400);
|
||||
char * msgBuf = NULL;
|
||||
size_t msgLen = 0;
|
||||
|
||||
msg.streamOut(&msgBuf, &msgLen);
|
||||
|
||||
fflush (stdout);
|
||||
writer.put(magic);
|
||||
writer.put(length);
|
||||
writer.put(packets);
|
||||
writer.put(msgLen);
|
||||
writer.put((void *)msgBuf, msgLen);
|
||||
|
||||
if(++count < 100) fprintf(stdout, "=> I have sent %i bytes...\n", stream.send(writer.buf, 80));
|
||||
else fprintf(stdout, "=> I have sent %i bytes and now I'm quitting\n", stream.send(writer.buf, 40));
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
if(count>=100) GlobalDone = -1;
|
||||
return GlobalDone;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleExcept :
|
||||
// * This function is called when out of band data has been received from
|
||||
// * the server. It will terminate the connection with the server.
|
||||
// *****************************************************************************
|
||||
int EarlyDeathHandler::handleExcept ( void )
|
||||
{
|
||||
fprintf(stdout, "=> I have received a terminator from the server\n");
|
||||
fflush(stdout);
|
||||
stream.close();
|
||||
GlobalDone = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int main ( int argc, char ** argv)
|
||||
{
|
||||
fprintf(stdout, "\n\
|
||||
=> **********************************************************************\n\
|
||||
=> * This is a test of the cdevGenericServer server-side software. *\n\
|
||||
=> * This application will transmit a partial packet to the server *\n\
|
||||
=> * and will then immediately terminate. The developer should inspect *\n\
|
||||
=> * the behavior of the server and ensure that it responds properly. *\n\
|
||||
=> * *\n\
|
||||
=> * The correct response to this sort of event would be to terminate *\n\
|
||||
=> * the connection and remove the client from the server. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
|
||||
if(argc<3)
|
||||
{
|
||||
fprintf(stdout, "\
|
||||
=> Insufficient parameters\n\
|
||||
=> Format is : %s host port\n\
|
||||
=> Terminating\n", argv[0]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
EarlyDeathHandler handler;
|
||||
cdevInetAddr addr(atoi(argv[2]), argv[1]);
|
||||
handler.open(addr);
|
||||
while(!GlobalDone) GlobalReactor.handleEvents();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef _EARLY_DEATH_H_
|
||||
#define _EARLY_DEATH_H_ 1
|
||||
|
||||
#include "cdevEventHandler.h"
|
||||
#include "cdevAddr.h"
|
||||
#include "cdevSocketConnector.h"
|
||||
#include "cdevReactor.h"
|
||||
#include "fifo.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * EarlyDeathHandler:
|
||||
// * This class provides the mechanisms that will be used to service the
|
||||
// * requests of a client.
|
||||
// *****************************************************************************
|
||||
class EarlyDeathHandler : public cdevEventHandler
|
||||
{
|
||||
protected:
|
||||
cdevSocketConnector stream;
|
||||
|
||||
public:
|
||||
EarlyDeathHandler (void);
|
||||
~EarlyDeathHandler (void);
|
||||
virtual int open (const cdevAddr &addr);
|
||||
virtual int getHandle (void) const;
|
||||
virtual int handleClose (void);
|
||||
virtual int handleInput (void);
|
||||
virtual int handleOutput (void);
|
||||
virtual int handleExcept (void);
|
||||
};
|
||||
|
||||
#endif /* _EARLY_DEATH_H_ */
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Server Early Death Test"
|
||||
OUTPUTDIR = $(BASEBIN)
|
||||
CXXINCLUDES = -I./
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
TARGETS = $(OUTPUTDIR)/EarlyDeath
|
||||
BINARIES = $(TARGETS)
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(OUTPUTDIR)/EarlyDeath : $(OBJDIR)/EarlyDeath.o
|
||||
$(LINK.cc) $^ $(LIBS) -o $@
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Server Early Death Test
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\EarlyDeath.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
|
||||
targets : $(BINARIES)
|
||||
|
||||
$(BASEBIN)\EarlyDeath.exe : .exec\$(TARGETDIR)\EarlyDeath.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib $(CDEVLIB)\cdevGenericServer.lib \
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
Reference in New Issue
Block a user