merging
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* testBlockingTCPSrv.cpp
|
||||
*
|
||||
* Created on: Jan 6, 2011
|
||||
* Author: Miha Vitorovic
|
||||
*/
|
||||
|
||||
#include "blockingTCP.h"
|
||||
#include "remote.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
|
||||
class ContextImpl : public Context {
|
||||
public:
|
||||
ContextImpl() :
|
||||
_tr(new TransportRegistry()),
|
||||
_timer(new Timer("server thread", lowPriority)) {}
|
||||
virtual ~ContextImpl() {
|
||||
delete _tr;
|
||||
delete _timer;
|
||||
}
|
||||
virtual Timer* getTimer() { return _timer; }
|
||||
virtual TransportRegistry* getTransportRegistry() { return _tr; }
|
||||
private:
|
||||
TransportRegistry* _tr;
|
||||
Timer* _timer;
|
||||
};
|
||||
|
||||
void testServerConnections() {
|
||||
ContextImpl ctx;
|
||||
|
||||
BlockingTCPAcceptor* srv = new BlockingTCPAcceptor(&ctx, CA_SERVER_PORT,
|
||||
1024);
|
||||
|
||||
cout<<"Press any key to stop the server...";
|
||||
char c = cin.peek();
|
||||
|
||||
delete srv;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
createFileLogger("testBlockingTCPSrv.log");
|
||||
|
||||
testServerConnections();
|
||||
}
|
||||
@@ -89,6 +89,8 @@ void testBlockingUDPSender() {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
delete transport;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <showConstructDestruct.h>
|
||||
#include <lock.h>
|
||||
#include <standardPVField.h>
|
||||
#include <memory>
|
||||
|
||||
#include <caConstants.h>
|
||||
#include <timer.h>
|
||||
|
||||
@@ -32,20 +32,23 @@ int main(int argc, char *argv[]) {
|
||||
osiSockAddr* addr;
|
||||
addr = vec->at(0);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(addr->ia.sin_port==555);
|
||||
assert(addr->ia.sin_addr.s_addr==(uint32_t)0x7F000001);
|
||||
assert(addr->ia.sin_port==htons(555));
|
||||
assert(addr->ia.sin_addr.s_addr==htonl(0x7F000001));
|
||||
assert(inetAddressToString(addr)=="127.0.0.1:555");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
addr = vec->at(1);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(addr->ia.sin_port==1234);
|
||||
assert(addr->ia.sin_addr.s_addr==(uint32_t)0x0A0A0C0B);
|
||||
assert(addr->ia.sin_port==htons(1234));
|
||||
assert(addr->ia.sin_addr.s_addr==htonl(0x0A0A0C0B));
|
||||
assert(inetAddressToString(addr)=="10.10.12.11:1234");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
addr = vec->at(2);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(addr->ia.sin_port==555);
|
||||
assert(addr->ia.sin_addr.s_addr==(uint32_t)0xC0A80304);
|
||||
assert(addr->ia.sin_port==htons(555));
|
||||
assert(addr->ia.sin_addr.s_addr==htonl(0xC0A80304));
|
||||
assert(inetAddressToString(addr)=="192.168.3.4:555");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
cout<<"\nPASSED!\n";
|
||||
@@ -57,26 +60,30 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
addr = vec1->at(0);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(addr->ia.sin_port==6789);
|
||||
assert(addr->ia.sin_addr.s_addr==(uint32_t)0xAC1037A0);
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
assert(addr->ia.sin_port==htons(6789));
|
||||
assert(addr->ia.sin_addr.s_addr==htonl(0xAC1037A0));
|
||||
assert(inetAddressToString(addr)=="172.16.55.160:6789");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
addr = vec1->at(1);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(addr->ia.sin_port==555);
|
||||
assert(addr->ia.sin_addr.s_addr==(uint32_t)0x7F000001);
|
||||
assert(addr->ia.sin_port==htons(555));
|
||||
assert(addr->ia.sin_addr.s_addr==htonl(0x7F000001));
|
||||
assert(inetAddressToString(addr)=="127.0.0.1:555");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
addr = vec1->at(2);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(addr->ia.sin_port==1234);
|
||||
assert(addr->ia.sin_addr.s_addr==(uint32_t)0x0A0A0C0B);
|
||||
assert(addr->ia.sin_port==htons(1234));
|
||||
assert(addr->ia.sin_addr.s_addr==htonl(0x0A0A0C0B));
|
||||
assert(inetAddressToString(addr)=="10.10.12.11:1234");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
addr = vec1->at(3);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(addr->ia.sin_port==555);
|
||||
assert(addr->ia.sin_addr.s_addr==(uint32_t)0xC0A80304);
|
||||
assert(addr->ia.sin_port==htons(555));
|
||||
assert(addr->ia.sin_addr.s_addr==htonl(0xC0A80304));
|
||||
assert(inetAddressToString(addr)=="192.168.3.4:555");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
cout<<"\nPASSED!\n";
|
||||
@@ -93,11 +100,13 @@ int main(int argc, char *argv[]) {
|
||||
cout<<"Testing \"intToIPv4Address\""<<endl;
|
||||
addr = intToIPv4Address(0x7F000001);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(inetAddressToString(addr)=="127.0.0.1");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
delete addr;
|
||||
|
||||
addr = intToIPv4Address(0x0A0A0C0B);
|
||||
assert(addr->ia.sin_family==AF_INET);
|
||||
assert(inetAddressToString(addr)=="10.10.12.11");
|
||||
cout<<'\t'<<inetAddressToString(addr, true)<<endl;
|
||||
|
||||
cout<<"\nPASSED!\n";
|
||||
@@ -110,9 +119,8 @@ int main(int argc, char *argv[]) {
|
||||
(char)0, (char)0, (char)0, (char)0, (char)0xFF, (char)0xFF,
|
||||
(char)0x0A, (char)0x0A, (char)0x0C, (char)0x0B };
|
||||
|
||||
|
||||
encodeAsIPv6Address(buff, addr);
|
||||
assert(strncmp(buff->getArray(),src,16)==0);
|
||||
assert(strncmp(buff->getArray(), src, 16)==0);
|
||||
cout<<"\nPASSED!\n";
|
||||
|
||||
// TODO add test for 'getBroadcastAddresses'
|
||||
|
||||
@@ -156,7 +156,7 @@ void* testWorker2(void* p)
|
||||
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
|
||||
usleep(1);
|
||||
}
|
||||
|
||||
#ifndef darwin
|
||||
//this thread sleeps a while and gets timeout on lock
|
||||
{
|
||||
sleep(1);
|
||||
@@ -167,7 +167,7 @@ void* testWorker2(void* p)
|
||||
NamedLock<osiSockAddr,comp_osiSockAddr> namedGuard(namedLockPattern);
|
||||
assert(!namedGuard.acquireSynchronizationObject(addr,timeout));
|
||||
}
|
||||
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user