- 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
102 lines
2.2 KiB
C++
102 lines
2.2 KiB
C++
/*
|
|
* testBlockingUDPClnt.cpp
|
|
*
|
|
* Created on: Dec 28, 2010
|
|
* Author: Miha Vitorovic
|
|
*/
|
|
|
|
#include "remote.h"
|
|
#include "blockingUDP.h"
|
|
#include "logger.h"
|
|
#include "inetAddressUtil.h"
|
|
|
|
#include <osiSock.h>
|
|
|
|
#include <iostream>
|
|
#include <cstdio>
|
|
|
|
using namespace epics::pvAccess;
|
|
using namespace epics::pvData;
|
|
|
|
using std::cout;
|
|
using std::endl;
|
|
using std::sscanf;
|
|
|
|
static osiSockAddr sendTo;
|
|
|
|
class DummyResponseHandler : public ResponseHandler {
|
|
public:
|
|
virtual void handleResponse(osiSockAddr* responseFrom,
|
|
Transport* transport, int8 version, int8 command, int payloadSize,
|
|
ByteBuffer* payloadBuffer) {
|
|
}
|
|
};
|
|
|
|
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) {
|
|
// set recipient
|
|
sendTo.ia.sin_family = AF_INET;
|
|
sendTo.ia.sin_port = htons(65000);
|
|
if(aToIPAddr("192.168.71.129", 65000, &sendTo.ia)<0) {
|
|
cout<<"error in aToIPAddr(...)"<<endl;
|
|
return;
|
|
}
|
|
|
|
control->setRecipient(&sendTo);
|
|
|
|
// send the packet
|
|
count++;
|
|
control->startMessage((int8)(count+0x10), 0);
|
|
buffer->put(data, 0, count);
|
|
//control->endMessage();
|
|
}
|
|
|
|
virtual void lock() {
|
|
}
|
|
virtual void unlock() {
|
|
}
|
|
private:
|
|
char data[20];
|
|
int count;
|
|
};
|
|
|
|
void testBlockingUDPSender() {
|
|
BlockingUDPConnector connector(false, NULL, true);
|
|
|
|
DummyTransportSender dts;
|
|
DummyResponseHandler drh;
|
|
|
|
osiSockAddr bindAddr;
|
|
|
|
bindAddr.ia.sin_family = AF_INET;
|
|
bindAddr.ia.sin_port = htons(65001);
|
|
bindAddr.ia.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
Transport* transport = connector.connect(NULL, &drh, &bindAddr, 1, 50);
|
|
|
|
cout<<"Sending 10 packets..."<<endl;
|
|
|
|
for(int i = 0; i<10; i++) {
|
|
cout<<" Packet: "<<i+1<<endl;
|
|
transport->enqueueSendRequest(&dts);
|
|
sleep(1);
|
|
}
|
|
|
|
delete transport;
|
|
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
createFileLogger("testBlockingUDPClnt.log");
|
|
|
|
testBlockingUDPSender();
|
|
return (0);
|
|
}
|