BlockingTCPTransport: added TransportRegistry, using osiSock.h functions wherever possible blockingUDP.h: removed "using namespace" blockingUDPConnector.cpp: using osiSock.h functions wherever possible blockingUDPTransport: using osiSock.h functions wherever possible, delete -> delete[] remote.h: removed "using namespace" arrayFIFO.h: fixed default ctor, delete -> delete[] growingCircularBuffer.h: delete -> delete[] testBlockingUDPClnt.cpp: using osiSock.h functions wherever possible testBlockingUDPCSrv.cpp: using osiSock.h functions wherever possible
100 lines
2.1 KiB
C++
100 lines
2.1 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);
|
|
}
|
|
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
createFileLogger("testBlockingUDPClnt.log");
|
|
|
|
testBlockingUDPSender();
|
|
return (0);
|
|
}
|