From 3eb8b83a3313b78881040a18d911e80718672095 Mon Sep 17 00:00:00 2001 From: bebopagogo Date: Fri, 27 Dec 2019 13:53:32 -0500 Subject: [PATCH] working on normCast Win32 support --- examples/normCast.cpp | 36 ++++++++++++++++++++++++------------ include/normApi.h | 6 +++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/examples/normCast.cpp b/examples/normCast.cpp index 3a9a13d..d864677 100644 --- a/examples/normCast.cpp +++ b/examples/normCast.cpp @@ -273,10 +273,7 @@ bool NormCaster::Start(bool sender, bool receiver) NormSetBackoffFactor(norm_session, 0); // Pick a random instance id for now - struct timeval currentTime; - gettimeofday(¤tTime, NULL); - srand(currentTime.tv_usec); // seed random number generator - NormSessionId instanceId = (NormSessionId)rand(); + NormSessionId instanceId = NormGetRandomSessionId(); if (!NormStartSender(norm_session, instanceId, bufferSize, segmentSize, blockSize, numParity)) { fprintf(stderr, "normCast error: unable to start NORM sender\n"); @@ -298,7 +295,7 @@ bool NormCaster::TxReady() const // NORM_TX_QUEUE_VACANCY notifications (tracked by the "norm_tx_vacancy" variable, // _and_ (if ack-based flow control is enabled) the norm_tx_queue_count or // norm_stream_buffer_count status. - if (norm_tx_vacancy) + if (norm_tx_vacancy) { if (norm_tx_queue_count >= norm_tx_queue_max) return false; // still waiting for ACK @@ -617,6 +614,8 @@ int main(int argc, char* argv[]) bool silentReceiver = false; double txloss = 0.0; bool loopback = false; + + TRACE("parsing command-line ...\n"); NormCaster normCast; @@ -861,20 +860,30 @@ int main(int argc, char* argv[]) Usage(); return -1; } + + TRACE("calling NormCreateInstance() ...\n"); // TBD - should provide more error checking of calls NormInstanceHandle normInstance = NormCreateInstance(); + TRACE("calling NormSetDebugLevel() ...\n"); NormSetDebugLevel(debugLevel); - if (NULL != debugLog) - NormOpenDebugLog(normInstance, debugLog); + if (NULL != debugLog) + { + TRACE("calling NormOpenDebugLog() ...\n"); + NormOpenDebugLog(normInstance, debugLog); + } + TRACE("calling NormSetCacheDirectory() (recv:%d) ...\n", recv); // TBD - enhance NORM to support per-session or perhaps per-sender rx cache directories? if (recv) NormSetCacheDirectory(normInstance, normCast.GetRxCacheDirectory()); + TRACE("calling SetLoopback() ...\n"); normCast.SetLoopback(loopback); - normCast.SetFlushing(flushing); + TRACE("calling SetFlushing() ...\n"); + normCast.SetFlushing(flushing); + TRACE("calling OpenNormSession() ...\n"); if (!normCast.OpenNormSession(normInstance, sessionAddr, sessionPort, (NormNodeId)nodeId)) { fprintf(stderr, "normCast error: unable to open NORM session\n"); @@ -896,17 +905,18 @@ int main(int argc, char* argv[]) if (trace) normCast.SetNormMessageTrace(true); + TRACE("calling Start() ...\n"); // TBD - set NORM session parameters normCast.Start(send, recv); + TRACE("calling SendFiles() ...\n"); if (normCast.TxFilePending()) normCast.SendFiles(); #ifdef WIN32 - HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); - Win32InputHandler inputHandler; - inputHandler.Open(); + //Win32InputHandler inputHandler; + //inputHandler.Open(); HANDLE handleArray[2]; - handleArray[0] = NormGetDescriptor(instance); + handleArray[0] = NormGetDescriptor(normInstance); bool inputNeeded = false; // set this to 'true', and uncomment next line for STDIN input notification //handleArray[1] = inputHandler.GetEventHandle(); #else @@ -916,6 +926,7 @@ int main(int argc, char* argv[]) FD_ZERO(&fdsetInput); #endif // if/else WIN32/UNIX + TRACE("entering main loop ...\n"); while (normCast.IsRunning()) { // TBD - could add "stdin" as a descriptor to monitor @@ -924,6 +935,7 @@ int main(int argc, char* argv[]) bool normEventPending = false; bool inputEventPending = false; #ifdef WIN32 + TRACE("calling MsgWaitForMultipleObjectsEx() ...\n"); DWORD handleCount = inputNeeded ? 2 : 1; DWORD waitStatus = MsgWaitForMultipleObjectsEx(handleCount, // number of handles in array diff --git a/include/normApi.h b/include/normApi.h index 412e20b..9ee1d00 100644 --- a/include/normApi.h +++ b/include/normApi.h @@ -338,9 +338,9 @@ bool NormPresetObjectInfo(NormSessionHandle sessionHandle, // FEC O UINT16 segmentSize, UINT16 numData, UINT16 numParity); - -NORM_API_LINKAGE -void NormSetId(NormSessionHandle sessionHandle, NormNodeId normId); +// non-public on purpose +//NORM_API_LINKAGE +//void NormSetId(NormSessionHandle sessionHandle, NormNodeId normId); // This does not affect the rx_socket binding if already bound (sender or receiver already started) // (i.e., just affects where NORM packets are sent)