- using enum to specify command. BlockingTCPAcceptor.cpp: - added 'destroy()' to dtor - added parentheses to expressions blockingTCPCinnector.cpp: - fixed log message blockingTCPTransport.cpp: - added _socketAddress allocation - fixed waiting for timeout in 'waitUntilVerified' - fixed how many bytes are copied from the buffer responseHandlers.cpp: - added 'ConnectionValidationHandler' implementation - added 'ConnectionValidationHandler' to 'ServerResponseHandler' responseHandlers.h: - added 'ConnectionValidationHandler' declaration inetAddressUtil.cpp: - fixed all issues with sockaddr_in byte-order - removed function 'processAddressForList', using EPICSv3 'aToIPAddr' instead inetAddressUtilsTest.cpp: - fixed the tests in accordance with the correct function implementation testBlockingUDPClnt.cpp: - deleting transport at the end of the test testBlockingTCPSrv.cpp, testBlockingTCPClnt.cpp: - added tests (work in progress). Makefile: - added blockingTCP tests
135 lines
3.0 KiB
C++
135 lines
3.0 KiB
C++
/*
|
|
* testBlockingTCPClnt.cpp
|
|
*
|
|
* Created on: Jan 6, 2011
|
|
* Author: Miha Vitorovic
|
|
*/
|
|
|
|
#include "remote.h"
|
|
#include "blockingTCP.h"
|
|
#include "logger.h"
|
|
#include "inetAddressUtil.h"
|
|
#include "caConstants.h"
|
|
|
|
#include <timer.h>
|
|
|
|
#include <osiSock.h>
|
|
#include <errlog.h>
|
|
|
|
#include <iostream>
|
|
#include <cstdio>
|
|
|
|
using namespace epics::pvAccess;
|
|
using namespace epics::pvData;
|
|
|
|
using std::cout;
|
|
using std::endl;
|
|
using std::sscanf;
|
|
|
|
class ContextImpl : public Context {
|
|
public:
|
|
ContextImpl() :
|
|
_tr(new TransportRegistry()),
|
|
_timer(new Timer("client thread", lowPriority)) {}
|
|
virtual ~ContextImpl() {
|
|
delete _tr;
|
|
delete _timer;
|
|
}
|
|
virtual Timer* getTimer() { return _timer; }
|
|
virtual TransportRegistry* getTransportRegistry() { return _tr; }
|
|
private:
|
|
TransportRegistry* _tr;
|
|
Timer* _timer;
|
|
};
|
|
|
|
class DummyResponseHandler : public ResponseHandler {
|
|
public:
|
|
virtual void handleResponse(osiSockAddr* responseFrom,
|
|
Transport* transport, int8 version, int8 command, int payloadSize,
|
|
ByteBuffer* payloadBuffer) {
|
|
}
|
|
};
|
|
|
|
class DummyTransportClient : public TransportClient {
|
|
public:
|
|
DummyTransportClient() {
|
|
}
|
|
virtual ~DummyTransportClient() {
|
|
}
|
|
virtual void transportUnresponsive() {
|
|
errlogSevPrintf(errlogInfo, "unresponsive");
|
|
}
|
|
virtual void transportResponsive(Transport* transport) {
|
|
errlogSevPrintf(errlogInfo, "responsive");
|
|
}
|
|
virtual void transportChanged() {
|
|
errlogSevPrintf(errlogInfo, "changed");
|
|
}
|
|
virtual void transportClosed() {
|
|
errlogSevPrintf(errlogInfo, "closed");
|
|
}
|
|
};
|
|
|
|
class DummyTransportSender : public TransportSender {
|
|
public:
|
|
DummyTransportSender() {
|
|
for(int i = 0; i<20; i++)
|
|
data[i] = (char)(i+1);
|
|
count = 0;
|
|
}
|
|
|
|
virtual void send(ByteBuffer* buffer, TransportSendControl* control) {
|
|
// send the packet
|
|
count++;
|
|
control->startMessage(0, count);
|
|
buffer->put(data, 0, count);
|
|
//control->endMessage();
|
|
}
|
|
|
|
virtual void lock() {
|
|
}
|
|
virtual void unlock() {
|
|
}
|
|
private:
|
|
char data[20];
|
|
int count;
|
|
};
|
|
|
|
void testBlockingTCPSender() {
|
|
ContextImpl ctx;
|
|
BlockingTCPConnector connector(&ctx, 1024, 1.0);
|
|
|
|
DummyTransportClient dtc;
|
|
DummyTransportSender dts;
|
|
DummyResponseHandler drh;
|
|
|
|
osiSockAddr srvAddr;
|
|
|
|
srvAddr.ia.sin_family = AF_INET;
|
|
//srvAddr.ia.sin_port = htons(CA_SERVER_PORT);
|
|
if(aToIPAddr("192.168.71.132", CA_SERVER_PORT, &srvAddr.ia)<0) {
|
|
cout<<"error in aToIPAddr(...)"<<endl;
|
|
return;
|
|
}
|
|
|
|
Transport* transport = connector.connect(&dtc, &drh, &srvAddr,
|
|
CA_MAGIC_AND_VERSION, CA_DEFAULT_PRIORITY);
|
|
|
|
cout<<"Sending 10 messages..."<<endl;
|
|
|
|
for(int i = 0; i<10; i++) {
|
|
cout<<" Message: "<<i+1<<endl;
|
|
transport->enqueueSendRequest(&dts);
|
|
sleep(1);
|
|
}
|
|
|
|
delete transport;
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
createFileLogger("testBlockingTCPClnt.log");
|
|
|
|
testBlockingTCPSender();
|
|
return 0;
|
|
}
|