Fix NetworkTest

Allow setting listen addr to "any".
This commit is contained in:
Stephen Seo 2019-09-18 13:56:04 +09:00
parent fefbfc8d70
commit 31c40d4739

View file

@ -57,11 +57,31 @@ int main(int argc, char **argv) {
--argc; ++argv; --argc; ++argv;
} }
if(!listenAddr) {
puts("ERROR: listenAddr was not specified");
return 1;
} else if(!listenPort) {
puts("ERROR: listenPort was not specified");
return 1;
} else if(isClient && !connectionAddr) {
puts("ERROR: connectionAddr was not specified");
return 1;
} else if(isClient && !connectionPort) {
puts("ERROR: connectionPort was not specified");
return 1;
}
UDPC_ConnectionId listenId;
UDPC_ConnectionId connectionId; UDPC_ConnectionId connectionId;
if(std::strcmp(listenAddr, "any") == 0) {
listenId = UDPC_create_id_anyaddr(std::atoi(listenPort));
} else {
listenId = UDPC_create_id(UDPC_strtoa(listenAddr), std::atoi(listenPort));
}
if(isClient) { if(isClient) {
connectionId = UDPC_create_id(UDPC_strtoa(connectionAddr), std::atoi(connectionPort)); connectionId = UDPC_create_id(UDPC_strtoa(connectionAddr), std::atoi(connectionPort));
} }
auto context = UDPC_init_threaded_update(UDPC_create_id(UDPC_strtoa(listenAddr), std::atoi(listenPort)), isClient ? 1 : 0); auto context = UDPC_init_threaded_update(listenId, isClient ? 1 : 0);
if(!context) { if(!context) {
puts("ERROR: context is NULL"); puts("ERROR: context is NULL");
return 1; return 1;