Skip to content

Commit

Permalink
hotplace rev.595 grooming
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Aug 30, 2024
1 parent 631ded2 commit 7239217
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangesLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# history

* Revision 595
* [changed] substitute cmdline_t with t_cmdline_t
Expand Down
10 changes: 10 additions & 0 deletions test/udpserver2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @author Soo Han, Kim (princeb612.kr@gmail.com)
# @desc
# Revision History
# Date Name Description
#

set (module udpserver2)
file (GLOB SOURCE_FILES *.cpp)

maketest (${module} SOURCE_FILES PROJECT_SDK_MODULE_DEPENDENCIES PROJECT_SDK_PLATFORM_DEPENDENCIES 0)
92 changes: 92 additions & 0 deletions test/udpserver2/sample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* vim: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab smarttab : */
/**
* @file {file}
* @author Soo Han, Kim (princeb612.kr@gmail.com)
* @desc see etc/udpclient
* @sa See in the following order : udpserver, udpserver2, dtlsserver
*
* Revision History
* Date Name Description
*/

#include <stdio.h>

#include <iostream>
#include <sdk/sdk.hpp>

using namespace hotplace;
using namespace hotplace::io;
using namespace hotplace::crypto;
using namespace hotplace::net;

test_case _test_case;
t_shared_instance<logger> _logger;

typedef struct _OPTION {
int verbose;
uint16 port;

_OPTION() : verbose(0), port(9000) {
// do nothing
}
} OPTION;
t_shared_instance<t_cmdline_t<OPTION>> _cmdline;

#define FILENAME_RUN _T (".run")

return_t echo_server(void* param) {
return_t ret = errorcode_t::success;
const OPTION& option = _cmdline->value();

// todo

return ret;
}

void run_server() {
_test_case.begin("echo server");

thread thread1(echo_server, nullptr);
std::string result;

__try2 { thread1.start(); }
__finally2 { thread1.wait(-1); }
}

int main(int argc, char** argv) {
#ifdef __MINGW32__
setvbuf(stdout, 0, _IOLBF, 1 << 20);
#endif

_cmdline.make_share(new t_cmdline_t<OPTION>);
*_cmdline << t_cmdarg_t<OPTION>("-v", "verbose", [](OPTION& o, char* param) -> void { o.verbose = 1; }).optional()
<< t_cmdarg_t<OPTION>("-p", "port (9000)", [](OPTION& o, char* param) -> void { o.port = atoi(param); }).optional().preced();
_cmdline->parse(argc, argv);

const OPTION& option = _cmdline->value();

logger_builder builder;
builder.set(logger_t::logger_stdout, option.verbose).set(logger_t::logger_flush_time, 0).set(logger_t::logger_flush_size, 0);
_logger.make_share(builder.build());

#if defined _WIN32 || defined _WIN64
winsock_startup();
#endif
openssl_startup();
openssl_thread_setup();

run_server();

openssl_thread_end();
openssl_cleanup();

#if defined _WIN32 || defined _WIN64
winsock_cleanup();
#endif

_logger->flush();

_test_case.report();
_cmdline->help();
return _test_case.result();
}

0 comments on commit 7239217

Please sign in to comment.