From 3363de82ede2d863eef6bf213f2b7f09efc25f51 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 30 Nov 2024 12:16:47 -0500 Subject: [PATCH] cwSocket.h/cpp : Change testMain() to take a cfg.. --- cwSocket.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- cwSocket.h | 2 +- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/cwSocket.cpp b/cwSocket.cpp index cbdb215..7292091 100644 --- a/cwSocket.cpp +++ b/cwSocket.cpp @@ -2,7 +2,10 @@ #include "cwLog.h" #include "cwCommonImpl.h" #include "cwMem.h" +#include "cwTest.h" +#include "cwObject.h" #include "cwThread.h" +#include "cwText.h" #include #include @@ -1255,7 +1258,11 @@ cw::rc_t cw::socksrv::stop( handle_t h ) return thread::pause( p->thH ); } -cw::rc_t cw::socksrv::test( const char* localNicDevice, sock::portNumber_t localPort, const char* remoteAddrIp, sock::portNumber_t remotePort, unsigned flags ) +cw::rc_t cw::socksrv::test( const char* localNicDevice, + sock::portNumber_t localPort, + const char* remoteAddrIp, + sock::portNumber_t remotePort, + unsigned flags ) { handle_t h; rc_t rc = kOkRC; @@ -1344,17 +1351,43 @@ cw::rc_t cw::socksrv::test( const char* localNicDevice, sock::portNumber_t loca return rcSelect(rc,rc1,rc2); } -cw::rc_t cw::socksrv::testMain( bool tcpFl, const char* localNicDevice, sock::portNumber_t localPort, const char* remoteAddrIp, sock::portNumber_t remotePort ) +cw::rc_t cw::socksrv::testMain( const object_t* cfg ) { - unsigned flags = 0; + rc_t rc = kOkRC; + const char* protocol_str = nullptr; + sock::portNumber_t localPort = 5688; + const char* remoteAddrIp = nullptr; + sock::portNumber_t remotePort = 5687; + const char* localNicDevice = nullptr; + unsigned flags = 0; - if( tcpFl ) + if((rc = cfg->getv("protocol",protocol_str, + "localPort",localPort )) != kOkRC ) + { + rc = cwLogError(rc,"Required arg. parse failed."); + goto errLabel; + } + + if((rc = cfg->getv_opt("remoteAddr",remoteAddrIp, + "remotePort",remotePort, + "nicDev",localNicDevice )) != kOkRC ) + { + rc = cwLogError(rc,"Optional arg. parse failed."); + goto errLabel; + } + + if( textIsEqual(protocol_str,"tcp") ) { flags |= sock::kTcpFl | sock::kStreamFl | sock::kReuseAddrFl | sock::kReusePortFl; if( remoteAddrIp == nullptr ) flags |= sock::kListenFl; + } + + rc = test(localNicDevice,localPort,remoteAddrIp,remotePort,flags); + +errLabel: - return test(localNicDevice,localPort,remoteAddrIp,remotePort,flags); + return rc; } diff --git a/cwSocket.h b/cwSocket.h index df5349d..26dbcfd 100644 --- a/cwSocket.h +++ b/cwSocket.h @@ -107,7 +107,7 @@ namespace cw rc_t stop( handle_t h ); rc_t test( const char* localNicDevice, sock::portNumber_t localPort, const char* remoteAddrIp, sock::portNumber_t remotePort, unsigned flags=0 ); - rc_t testMain( bool tcpFl, const char* localNicDevice, sock::portNumber_t localPort, const char* remoteAddrIp=nullptr, sock::portNumber_t remotePort=sock::kInvalidPortNumber ); + rc_t testMain( const object_t* cfg ); } }