reorganized strjoin and related functions

added qse_thr_t
This commit is contained in:
2015-09-23 13:34:04 +00:00
parent e11704ce16
commit e4a3026dc1
21 changed files with 1094 additions and 230 deletions

View File

@ -93,4 +93,4 @@ QSE_EXPORT void qse_shutsckhnd (
#endif

View File

@ -1094,6 +1094,18 @@ QSE_EXPORT qse_size_t qse_mbsxjoin (
...
);
QSE_EXPORT qse_size_t qse_mbsjoinv (
qse_mchar_t* buf,
va_list ap
);
QSE_EXPORT qse_size_t qse_mbsxjoinv (
qse_mchar_t* buf,
qse_size_t size,
va_list ap
);
/*
* The qse_wcsjoin() function joins a list of wide-charcter strings into
* a buffer. The list of strings is terminated by QSE_NULL.
@ -1116,17 +1128,28 @@ QSE_EXPORT qse_size_t qse_wcsxjoin (
...
);
QSE_EXPORT qse_size_t qse_strjoin (
qse_char_t* buf,
...
QSE_EXPORT qse_size_t qse_wcsjoinv (
qse_wchar_t* buf,
va_list ap
);
QSE_EXPORT qse_size_t qse_strxjoin (
qse_char_t* buf,
qse_size_t size,
...
QSE_EXPORT qse_size_t qse_wcsxjoinv (
qse_wchar_t* buf,
qse_size_t size,
va_list ap
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_strjoin qse_mbsjoin
# define qse_strxjoin qse_mbsxjoin
# define qse_strjoinv(buf,ap) qse_mbsjoinv(buf,ap)
# define qse_strxjoinv(buf,size,ap) qse_mbsxjoinv(buf,size,ap)
#else
# define qse_strjoin qse_wcsjoin
# define qse_strxjoin qse_wcsxjoin
# define qse_strjoinv(buf,ap) qse_wcsjoinv(buf,ap)
# define qse_strxjoinv(buf,size,ap) qse_wcsxjoinv(buf,size,ap)
#endif
/* ---------------------------------------------------- */

View File

@ -892,6 +892,9 @@
/* Patch level */
#undef QSE_PACKAGE_VERSION_PATCH
/* Define if pthread_t is signed */
#undef QSE_PTHREAD_T_IS_SIGNED
/* sizeof(char) */
#undef QSE_SIZEOF_CHAR
@ -922,6 +925,9 @@
/* sizeof(off_t) */
#undef QSE_SIZEOF_OFF_T
/* sizeof(pthread_t) */
#undef QSE_SIZEOF_PTHREAD_T
/* sizeof(short) */
#undef QSE_SIZEOF_SHORT
@ -1006,6 +1012,9 @@
/* The size of `off_t', as computed by sizeof. */
#undef SIZEOF_OFF_T
/* The size of `pthread_t', as computed by sizeof. */
#undef SIZEOF_PTHREAD_T
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT

View File

@ -1,6 +1,7 @@
pkgincludedir = $(includedir)/qse/sys
pkginclude_HEADERS =
pkginclude_HEADERS = \
thr.h
if ENABLE_CXX
pkginclude_HEADERS += \

View File

@ -117,7 +117,7 @@ am__can_run_installinfo = \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__pkginclude_HEADERS_DIST = SocketAddress.hpp
am__pkginclude_HEADERS_DIST = thr.h SocketAddress.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@ -343,7 +343,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
pkginclude_HEADERS = $(am__append_1)
pkginclude_HEADERS = thr.h $(am__append_1)
all: all-am
.SUFFIXES:

View File

@ -36,22 +36,38 @@ QSE_BEGIN_NAMESPACE(QSE)
class SocketAddress
{
public:
int getFamily () const;
void* getStorage (int* len);
SocketAddress ();
SocketAddress (int family);
SocketAddress (const qse_skad_t* skad);
SocketAddress (const qse_nwad_t* nwad);
SocketAddress (const struct sockaddr* ptr, int len);
int getFamily () const;
int getStorageSize () const
qse_skad_t* getAddrPtr()
{
return &this->skad;
}
const qse_skad_t* getAddrPtr() const
{
return &this->skad;
}
int getAddrSize () const
{
return qse_skadsize(&this->skad);
}
void setIpaddr (const qse_ip4ad_t* ipaddr);
void setIpaddr (const qse_ip6ad_t* ipaddr);
qse_uint16_t getPort() const; // in network-byte order
void setPort (qse_uint16_t port); // in network-byte order
int set (const qse_skad_t* skad);
int set (const void* ptr, int len);
int set (const qse_skad_t* skad);
int set (const qse_nwad_t* nwad);
int set (const struct sockaddr* ptr, int len); // treat ptr as a pointer to struct sockaddr
protected:
qse_skad_t skad;

232
qse/include/qse/sys/thr.h Normal file
View File

@ -0,0 +1,232 @@
/*
* $Id$
*
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EQSERESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QSE_CMN_THR_H_
#define _QSE_CMN_THR_H_
#include <qse/types.h>
#include <qse/macros.h>
/**
* The qse_thr_t type defines a thread object.
*/
typedef struct qse_thr_t qse_thr_t;
/**
* The qse_thr_routine_t type defines a thread routine that can be passed to
* qse_thr_open() and qse_thr_start(). When it is executed, the pointer to the
* calling thread object is passed as its first argument.
*/
typedef int (*qse_thr_routine_t) (qse_thr_t*);
enum qse_thr_state_t
{
QSE_THR_INCUBATING,
QSE_THR_RUNNING,
QSE_THR_TERMINATED,
QSE_THR_ABORTED
};
typedef enum qse_thr_state_t qse_thr_state_t;
enum qse_thr_flag_t
{
QSE_THR_DETACHED = (1 << 0),
QSE_THR_NEW_ROUTINE = (1 << 1)
};
typedef enum qse_thr_flag_t qse_thr_flag_t;
#if defined(_WIN32)
/* <winnt.h> => typedef PVOID HANDLE; */
typedef void* qse_thr_hnd_t;
#elif defined(__OS2__)
/* not implemented */
# error not implemented
#elif defined(__DOS__)
/* not implemented */
# error not implemented
#elif defined(__BEOS__)
/*typedef thread_id qse_thr_hnd_t;*/
typdef qse_int32_t qse_thr_hnd_t;
#else
#if (QSE_SIZEOF_PTHREAD_T == QSE_SIZEOF_INT)
#if defined(QSE_PTHREAD_T_IS_SIGNED)
typedef int qse_thr_hnd_t;
#else
typedef unsigned int qse_thr_hnd_t;
#endif
#elif (QSE_SIZEOF_PTHREAD_T == QSE_SIZEOF_LONG)
#if defined(QSE_PTHREAD_T_IS_SIGNED)
typedef long qse_thr_hnd_t;
#else
typedef unsigned long qse_thr_hnd_t;
#endif
#else
typedef int qse_thr_hnd_t;
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* The qse_thr_open() function instantiates a thread object. The function
* pointed to by \a routine is executed when qse_thr_start() is called.
*
*/
qse_thr_t* qse_thr_open (
qse_mmgr_t* mmgr,
qse_size_t xtnsize,
qse_thr_routine_t routine
);
/**
* The qse_thr_close() function destroys a thread object. Make sure that the
* thread routine has been terminated properly.
*/
void qse_thr_close (
qse_thr_t* thr
);
int qse_thr_init (
qse_thr_t* thr,
qse_mmgr_t* mmgr,
qse_thr_routine_t routine
);
void qse_thr_fini (
qse_thr_t* thr
);
qse_size_t qse_thr_getstacksize (
qse_thr_t* thr
);
/**
* The qse_thr_setstacksize() function sets the stack size of a thread.
* It must be called before a thread routine gets started.
*/
void qse_thr_setstacksize (
qse_thr_t* thr,
qse_size_t num
);
/**
* The qse_thr_start() executes a thread routine in a new thread of control.
* A new temporary thread routine can be passed as the third argument to
* override the main thread routine for a single invocation if \a flags contains
* the #QSE_THR_NEW_ROUTINE bit.
*
* QSE_THR_DETACHED, when set in \a flags, puts the thread in a detached state.
* Otherwise, the thread is joinable.
*
* \return 0 on success, -1 on failure
*/
int qse_thr_start (
qse_thr_t* thr,
int flags, /**< 0 or bitwise-or of QSE_THR_NEW_ROUTINE and QSE_THR_DETACHED */
...
);
/**
* The qse_thr_stop() function aborts a thread.
* \return 0 on success, -1 on failure
*/
int qse_thr_stop (qse_thr_t* thr);
/**
* The qse_thr_join() function waits for thread termination.
* \return 0 on success, -1 on failure
*/
int qse_thr_join (qse_thr_t* thr);
/**
* The qse_thr_detach() function detaches a thread.
* \return 0 on success, -1 on failure
*/
int qse_thr_detach (qse_thr_t* thr);
/**
* The qse_thr_kill() function sends a signal to a thread.
*/
int qse_thr_kill (qse_thr_t* thr, int sig);
/**
* The qse_thr_blocksig() function causes a therad to block the signal \a sig.
*/
int qse_thr_blocksig (qse_thr_t* thr, int sig);
/**
* The qse_thr_unblocksig() function causes a therad to unblock the signal \a sig.
*/
int qse_thr_unblocksig (qse_thr_t* thr, int sig);
/**
* The qse_thr_blockallsigs() function causes a therad to block all signals.
*/
int qse_thr_blockallsigs (qse_thr_t* thr);
/**
* The qse_thr_unblockallsigs() function causes a therad to unblock all signals.
*/
int qse_thr_unblockallsigs (qse_thr_t* thr);
/**
* The qse_thr_gethnd() function returns the native thread handle.
*/
qse_thr_hnd_t qse_thr_gethnd (
qse_thr_t* thr
);
/**
* The qse_thr_getretcode() returns the return code a thread rountine
* that has been terminated. If no thread routine has been started and
* terminated, 0 is returned.
*/
int qse_thr_getretcode (
qse_thr_t* thr
);
/**
* The qse_thr_state() function returns the current state.
*/
qse_thr_state_t qse_thr_getstate (
qse_thr_t* thr
);
/**
* The qse_getcurthrhnd() function returns the native handle to the
* calling thread.
*/
qse_thr_hnd_t qse_getcurthrhnd (void);
#ifdef __cplusplus
}
#endif
#endif