finished QSE::TcpServerL
This commit is contained in:
parent
19df0af32a
commit
afe36ac593
20
qse/configure
vendored
20
qse/configure
vendored
@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.69 for qse 0.8.0.
|
||||
# Generated by GNU Autoconf 2.69 for qse 0.8.1.
|
||||
#
|
||||
# Report bugs to <Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)>.
|
||||
#
|
||||
@ -590,8 +590,8 @@ MAKEFLAGS=
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='qse'
|
||||
PACKAGE_TARNAME='qse'
|
||||
PACKAGE_VERSION='0.8.0'
|
||||
PACKAGE_STRING='qse 0.8.0'
|
||||
PACKAGE_VERSION='0.8.1'
|
||||
PACKAGE_STRING='qse 0.8.1'
|
||||
PACKAGE_BUGREPORT='Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)'
|
||||
PACKAGE_URL='http://code.abiyo.net/@qse'
|
||||
|
||||
@ -1401,7 +1401,7 @@ if test "$ac_init_help" = "long"; then
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures qse 0.8.0 to adapt to many kinds of systems.
|
||||
\`configure' configures qse 0.8.1 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@ -1471,7 +1471,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of qse 0.8.0:";;
|
||||
short | recursive ) echo "Configuration of qse 0.8.1:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@ -1610,7 +1610,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
qse configure 0.8.0
|
||||
qse configure 0.8.1
|
||||
generated by GNU Autoconf 2.69
|
||||
|
||||
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@ -2394,7 +2394,7 @@ cat >config.log <<_ACEOF
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by qse $as_me 0.8.0, which was
|
||||
It was created by qse $as_me 0.8.1, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@ -3269,7 +3269,7 @@ fi
|
||||
|
||||
# Define the identity of the package.
|
||||
PACKAGE='qse'
|
||||
VERSION='0.8.0'
|
||||
VERSION='0.8.1'
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
@ -24085,7 +24085,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by qse $as_me 0.8.0, which was
|
||||
This file was extended by qse $as_me 0.8.1, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@ -24152,7 +24152,7 @@ _ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
|
||||
ac_cs_version="\\
|
||||
qse config.status 0.8.0
|
||||
qse config.status 0.8.1
|
||||
configured by $0, generated by GNU Autoconf 2.69,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
@ -4,7 +4,7 @@ dnl Make sure you change the version information
|
||||
dnl in include/qse/conf_*.h whenever you change the version
|
||||
dnl here. Those files don't depend on autoconf, thus requiring
|
||||
dnl manual change.
|
||||
AC_INIT([qse],[0.8.0],[Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)],[],[http://code.abiyo.net/@qse])
|
||||
AC_INIT([qse],[0.8.1],[Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)],[],[http://code.abiyo.net/@qse])
|
||||
|
||||
AC_CONFIG_HEADER([include/qse/config.h])
|
||||
AC_CONFIG_AUX_DIR([ac])
|
||||
|
@ -190,34 +190,57 @@ class TcpServerL<RT(ARGS...)>: public TcpServer
|
||||
{
|
||||
public:
|
||||
TcpServerL () QSE_CPP_NOEXCEPT: __lfunc(nullptr) {}
|
||||
|
||||
template <typename T>
|
||||
TcpServerL (T&& f) QSE_CPP_NOEXCEPT: __lfunc(nullptr)
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO: are there any ways to achieve this without memory allocation?
|
||||
this->__lfunc = new TCallable<T> (QSE_CPP_RVREF(f));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// upon failure, i set this->__lfunc to null.
|
||||
// this->handle_client() will return failure for this.
|
||||
this->__lfunc = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
~TcpServerL () QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (this->__lfunc) delete this->__lfunc;
|
||||
}
|
||||
|
||||
static int call_func (qse_thr_t* thr, void* ctx)
|
||||
{
|
||||
TcpServerL* t = (TcpServerL*)ctx;
|
||||
return t->__lfunc->invoke(t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int handle_client (Socket* sock, SocketAddress* addr)
|
||||
int setClientHandler (T&& f) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (this->__state == QSE_THR_RUNNING) return -1;
|
||||
if (this->__lfunc) delete this->__lfunc;
|
||||
Callable* lf;
|
||||
|
||||
try
|
||||
{
|
||||
// TODO: are there any ways to achieve this without memory allocation?
|
||||
//this->__lfunc = new TCallable<T> (QSE_CPP_RVREF(f));
|
||||
// TODO: this->__lfunc = new TCallable<T> (QSE_CPP_RVREF(f));
|
||||
lf = new TCallable<T> (QSE_CPP_RVREF(f));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
this->__lfunc = nullptr;
|
||||
return -1;
|
||||
}
|
||||
return this->__lfunc->invoke (sock, addr);
|
||||
|
||||
if (this->__lfunc) delete this->__lfunc;
|
||||
this->__lfunc = lf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_client (Socket* sock, SocketAddress* addr)
|
||||
{
|
||||
if (!this->__lfunc)
|
||||
{
|
||||
//this->setErrorCode (TcpServer::E_ENOMEM or E_EINVAL??);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return this->__lfunc->invoke(sock, addr);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -13,7 +13,9 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
#if defined(QSE_LANG_CPP11)
|
||||
QSE::TcpServerL<int(QSE::Socket*,QSE::SocketAddress*)>* g_server;
|
||||
#else
|
||||
|
||||
class ClientHandler
|
||||
{
|
||||
@ -26,10 +28,23 @@ qse_printf (QSE_T("XXXXXXXXXXXXXXXXXXXXXXXXXX\n"));
|
||||
};
|
||||
|
||||
static QSE::TcpServerF<ClientHandler>* g_server;
|
||||
#endif
|
||||
|
||||
static int test1 (void)
|
||||
{
|
||||
#if defined(QSE_LANG_CPP11)
|
||||
int x, y;
|
||||
|
||||
QSE::TcpServerL<int(QSE::Socket*,QSE::SocketAddress*)> server (
|
||||
([&x, &y](QSE::Socket* clisock, QSE::SocketAddress* cliaddr) {
|
||||
qse_printf (QSE_T("hello word......\n"));
|
||||
return 0;
|
||||
})
|
||||
);
|
||||
#else
|
||||
QSE::TcpServerF<ClientHandler> server;
|
||||
#endif
|
||||
|
||||
server.setThreadStackSize (256000);
|
||||
g_server = &server;
|
||||
server.start (QSE_T("0.0.0.0:9998"));
|
||||
@ -37,27 +52,6 @@ static int test1 (void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test2 (void)
|
||||
{
|
||||
#if defined(QSE_LANG_CPP11)
|
||||
|
||||
QSE::TcpServerL<int(QSE::Thread*)> server;
|
||||
thr5.setStackSize (64000);
|
||||
|
||||
if (server.start(
|
||||
([](QSE::Socket* clisock, QSE::SocketAddress* cliaddr) {
|
||||
return 0;
|
||||
})
|
||||
) <= -1)
|
||||
{
|
||||
qse_printf (QSE_T("cannot start server\n"));
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void handle_sigint (int sig, siginfo_t* siginfo, void* ctx)
|
||||
{
|
||||
if (g_server) g_server->stop ();
|
||||
|
Loading…
Reference in New Issue
Block a user