cdev-1.7.2n
This commit is contained in:
+171
@@ -0,0 +1,171 @@
|
||||
#include <BadMagic.h>
|
||||
#include <cdevMessage.h>
|
||||
#include <clipMagicNumber.h>
|
||||
#include <xdrClass.h>
|
||||
|
||||
int GlobalDone = 0;
|
||||
cdevReactor GlobalReactor;
|
||||
|
||||
// *****************************************************************************
|
||||
// * BadMagicHandler::BadMagicHandler
|
||||
// * Default constructor for the BadMagicHandler class
|
||||
// *****************************************************************************
|
||||
BadMagicHandler::BadMagicHandler ( void )
|
||||
: stream()
|
||||
{
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * open:
|
||||
// * Established a connection with the host specified by remote_sap
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::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;
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * ~BadMagicHandler:
|
||||
// * Default destructor for the BadMagicHandler object.
|
||||
// *****************************************************************************
|
||||
BadMagicHandler::~BadMagicHandler (void)
|
||||
{
|
||||
GlobalReactor.extractHandler(this);
|
||||
handleClose();
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * BadMagicHandler::getHandle
|
||||
// * Allows the caller to obtain the file identifier of the socket.
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::getHandle (void) const
|
||||
{
|
||||
return stream.getHandle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * handleClose:
|
||||
// * Closes the stream.
|
||||
// *****************************************************************************
|
||||
int BadMagicHandler::handleClose (void)
|
||||
{
|
||||
stream.close();
|
||||
fprintf(stdout, "=> Closing the BadMagic 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 BadMagicHandler::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 BadMagicHandler::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);
|
||||
|
||||
count++;
|
||||
if(count==50) magic++;
|
||||
fflush (stdout);
|
||||
writer.put(magic);
|
||||
writer.put(length);
|
||||
writer.put(packets);
|
||||
writer.put(msgLen);
|
||||
writer.put((void *)msgBuf, msgLen);
|
||||
|
||||
fprintf(stdout, "=> I have sent %i bytes...\n", stream.send(writer.buf, 80));
|
||||
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 BadMagicHandler::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 group of packets to the server *\n\
|
||||
=> * and will then transmit a packet with a bad magic number. The *\n\
|
||||
=> * should immediately terminate the client connection as soon as the *\n\
|
||||
=> * packet with the invalid magic number is received. *\n\
|
||||
=> **********************************************************************\n\n");
|
||||
|
||||
if(argc<3)
|
||||
{
|
||||
fprintf(stdout, "\
|
||||
=> Insufficient parameters\n\
|
||||
=> Format is : %s host port\n\
|
||||
=> Terminating\n", argv[0]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
BadMagicHandler handler;
|
||||
cdevInetAddr addr(atoi(argv[2]), argv[1]);
|
||||
handler.open(addr);
|
||||
while(!GlobalDone) GlobalReactor.handleEvents();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#ifndef _BAD_MAGIC_H_
|
||||
#define _BAD_MAGIC_H_ 1
|
||||
|
||||
#include "cdevEventHandler.h"
|
||||
#include "cdevAddr.h"
|
||||
#include "cdevSocketConnector.h"
|
||||
#include "cdevReactor.h"
|
||||
#include "fifo.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// * BadMagicHandler:
|
||||
// * This class provides the mechanisms that will be used to service the
|
||||
// * requests of a client.
|
||||
// *****************************************************************************
|
||||
class BadMagicHandler : public cdevEventHandler
|
||||
{
|
||||
protected:
|
||||
cdevSocketConnector stream;
|
||||
|
||||
public:
|
||||
BadMagicHandler (void);
|
||||
~BadMagicHandler (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 /* _BAD_MAGIC_H_ */
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
ARCH = OS
|
||||
SHOBJ = YES
|
||||
|
||||
include ../../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Server Bad Magic Number Test"
|
||||
OUTPUTDIR = $(BASEBIN)
|
||||
CXXINCLUDES = -I./
|
||||
LIBS = -L$(CDEVLIB) -lcdevGenericServer $(CDEVLIBS) $(OSLIBS)
|
||||
|
||||
TARGETS = $(OUTPUTDIR)/BadMagic
|
||||
BINARIES = $(TARGETS)
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(OUTPUTDIR)/BadMagic : $(OBJDIR)/BadMagic.o
|
||||
$(LINK.cc) $^ $(LIBS) -o $@
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Server Bad Magic Number Test
|
||||
ARCH = WINNT-4.0
|
||||
SHOBJ = YES
|
||||
|
||||
BINARIES = $(BASEBIN)\BadMagic.exe
|
||||
|
||||
include ..\..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXINCLUDES = /I .\\
|
||||
|
||||
targets : $(BINARIES)
|
||||
|
||||
$(BASEBIN)\BadMagic.exe : .exec\$(TARGETDIR)\BadMagic.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