cwTcpSocketTest.cpp : Added use of initAddr() in test_udp_srv() added send() in srvReceiveCallback().

This commit is contained in:
kevin 2023-07-25 20:18:55 -04:00
parent 34df8aa992
commit daa990944f

View File

@ -236,15 +236,22 @@ namespace cw
{ {
handle_t srvH; handle_t srvH;
unsigned cbN; unsigned cbN;
struct sockaddr_in remoteAddr;
} app_t; } app_t;
void srvReceiveCallback( void* arg, const void* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr ) void srvReceiveCallback( void* arg, const void* data, unsigned dataByteCnt, const struct sockaddr_in* fromAddr )
{ {
app_t* p = static_cast<app_t*>(arg); app_t* p = static_cast<app_t*>(arg);
send(p->srvH, data, dataByteCnt, &p->remoteAddr );
char addrBuf[ INET_ADDRSTRLEN ]; char addrBuf[ INET_ADDRSTRLEN ];
socket::addrToString( fromAddr, addrBuf, INET_ADDRSTRLEN ); socket::addrToString( fromAddr, addrBuf, INET_ADDRSTRLEN );
p->cbN += 1; p->cbN += 1;
printf("%i %s %s\n", p->cbN, addrBuf, (const char*)data ); printf("%i %s %s\n", p->cbN, addrBuf, (const char*)data );
} }
} }
} }
@ -270,8 +277,15 @@ cw::rc_t cw::net::srv::test_udp_srv( socket::portNumber_t localPort, const char*
timeOutMs, timeOutMs,
nullptr, nullptr,
socket::kInvalidPortNumber )) != kOkRC ) socket::kInvalidPortNumber )) != kOkRC )
{
return rc; return rc;
}
if((rc = socket::initAddr( remoteAddr, remotePort, &app.remoteAddr )) != kOkRC )
{
cwLogError(rc,"Address initialization failed.");
goto errLabel;
}
if((rc = srv::start( app.srvH )) != kOkRC ) if((rc = srv::start( app.srvH )) != kOkRC )
goto errLabel; goto errLabel;