#include "normApi.h"
#include "protoDefs.h"
#include "protoDebug.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
const char DIR_DELIMITER = '\\';
#else
const char DIR_DELIMITER = '/';
#endif
int main(int argc, char* argv[])
{
if (argc != 2)
{
fprintf(stderr, "normFileSend error: invalid argument(s)\n");
fprintf(stderr, "Usage: normFileSend <file>\n");
return -1;
}
const char* filePath = argv[1];
const char* fileName = strrchr(filePath, DIR_DELIMITER);
if (fileName)
fileName++;
else
fileName = filePath;
NormInstanceHandle instance = NormCreateInstance();
NormSessionHandle session = NormCreateSession(instance,
"224.1.2.3",
6003,
1);
NormSetRxPortReuse(session, true);
NormSetMulticastLoopback(session, true);
NormSetMessageTrace(session, true);
struct timeval currentTime;
ProtoSystemTime(currentTime);
srand(currentTime.tv_sec);
NormSetTxRate(session, 25600.0e+03);
NormSessionId sessionId = (NormSessionId)rand();
NormStartSender(session, sessionId, 1024*1024, 1400, 64, 16);
NormObjectHandle txFile =
NormFileEnqueue(session, filePath,
fileName, strlen(fileName));
bool keepGoing = true;
while (keepGoing)
{
NormEvent theEvent;
if (!NormGetNextEvent(instance, &theEvent)) continue;
switch (theEvent.type)
{
case NORM_TX_QUEUE_VACANCY:
fprintf(stderr, "normFileSend: NORM_TX_QUEUE_VACANCY event...\n");
break;
case NORM_TX_QUEUE_EMPTY:
fprintf(stderr, "normFileSend: NORM_TX_QUEUE_EMPTY event...\n");
break;
case NORM_TX_OBJECT_PURGED:
fprintf(stderr, "normFileSend: NORM_TX_OBJECT_PURGED event ...\n");
break;
case NORM_TX_FLUSH_COMPLETED:
fprintf(stderr, "normFileSend: NORM_TX_FLUSH_COMPLETED event ...\n");
keepGoing = false; break;
default:
TRACE("normFileSend: Got event type: %d\n", theEvent.type);
} }
NormStopSender(session);
NormDestroySession(session);
NormDestroyInstance(instance);
fprintf(stderr, "normFileSend: Done.\n");
return 0;
}