added some urs code

This commit is contained in:
2014-08-25 16:18:17 +00:00
parent eb1511b817
commit 78f8b4a994
54 changed files with 779 additions and 259 deletions

View File

@ -70,6 +70,7 @@ libqsecmn_la_SOURCES = \
pma.c \
rbt.c \
rex.c \
sck.c \
sio.c \
sll.c \
slmb.c \

View File

@ -60,6 +60,7 @@ DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \
$(top_srcdir)/m4/ax_check_sign.m4 \
$(top_srcdir)/m4/ax_cxx_namespace.m4 \
$(top_srcdir)/m4/ax_numval.m4 $(top_srcdir)/m4/ax_pthread.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltdl.m4 \
@ -109,16 +110,16 @@ am__libqsecmn_la_SOURCES_DIST = alg-base64.c alg-rand.c alg-search.c \
fma.c fmt-intmax.c fmt-out.c fs.c fs-err.c fs-move.c glob.c \
hton.c ipad.c lda.c main.c mb8.c mbwc.c mbwc-str.c mem.c mux.c \
nwad.c nwad-skad.c nwif.c nwif-cfg.c nwio.c oht.c opt.c \
path-basename.c path-canon.c pio.c pma.c rbt.c rex.c sio.c \
sll.c slmb.c str-beg.c str-cat.c str-chr.c str-cnv.c str-cmp.c \
str-cpy.c str-del.c str-dup.c str-dyn.c str-end.c str-excl.c \
str-fcpy.c str-fmt.c str-fnmat.c str-incl.c str-join.c \
str-len.c str-pac.c str-pbrk.c str-put.c str-rev.c str-rot.c \
str-set.c str-spl.c str-spn.c str-str.c str-subst.c str-tok.c \
str-trm.c str-word.c task.c time.c tio.c tmr.c tre.c tre-ast.c \
tre-compile.c tre-match-backtrack.c tre-match-parallel.c \
tre-parse.c tre-stack.c uri.c utf8.c xma.c uni.c cp949.c \
cp950.c
path-basename.c path-canon.c pio.c pma.c rbt.c rex.c sck.c \
sio.c sll.c slmb.c str-beg.c str-cat.c str-chr.c str-cnv.c \
str-cmp.c str-cpy.c str-del.c str-dup.c str-dyn.c str-end.c \
str-excl.c str-fcpy.c str-fmt.c str-fnmat.c str-incl.c \
str-join.c str-len.c str-pac.c str-pbrk.c str-put.c str-rev.c \
str-rot.c str-set.c str-spl.c str-spn.c str-str.c str-subst.c \
str-tok.c str-trm.c str-word.c task.c time.c tio.c tmr.c tre.c \
tre-ast.c tre-compile.c tre-match-backtrack.c \
tre-match-parallel.c tre-parse.c tre-stack.c uri.c utf8.c \
xma.c uni.c cp949.c cp950.c
@ENABLE_BUNDLED_UNICODE_TRUE@am__objects_1 = uni.lo
@ENABLE_XCMGRS_TRUE@am__objects_2 = cp949.lo cp950.lo
am_libqsecmn_la_OBJECTS = alg-base64.lo alg-rand.lo alg-search.lo \
@ -127,7 +128,7 @@ am_libqsecmn_la_OBJECTS = alg-base64.lo alg-rand.lo alg-search.lo \
fs-move.lo glob.lo hton.lo ipad.lo lda.lo main.lo mb8.lo \
mbwc.lo mbwc-str.lo mem.lo mux.lo nwad.lo nwad-skad.lo nwif.lo \
nwif-cfg.lo nwio.lo oht.lo opt.lo path-basename.lo \
path-canon.lo pio.lo pma.lo rbt.lo rex.lo sio.lo sll.lo \
path-canon.lo pio.lo pma.lo rbt.lo rex.lo sck.lo sio.lo sll.lo \
slmb.lo str-beg.lo str-cat.lo str-chr.lo str-cnv.lo str-cmp.lo \
str-cpy.lo str-del.lo str-dup.lo str-dyn.lo str-end.lo \
str-excl.lo str-fcpy.lo str-fmt.lo str-fnmat.lo str-incl.lo \
@ -416,16 +417,16 @@ libqsecmn_la_SOURCES = alg-base64.c alg-rand.c alg-search.c alg-sort.c \
fmt-intmax.c fmt-out.c fs.c fs-err.c fs-move.c glob.c hton.c \
ipad.c lda.c main.c mb8.c mbwc.c mbwc-str.c mem.c mux.c nwad.c \
nwad-skad.c nwif.c nwif-cfg.c nwio.c oht.c opt.c \
path-basename.c path-canon.c pio.c pma.c rbt.c rex.c sio.c \
sll.c slmb.c str-beg.c str-cat.c str-chr.c str-cnv.c str-cmp.c \
str-cpy.c str-del.c str-dup.c str-dyn.c str-end.c str-excl.c \
str-fcpy.c str-fmt.c str-fnmat.c str-incl.c str-join.c \
str-len.c str-pac.c str-pbrk.c str-put.c str-rev.c str-rot.c \
str-set.c str-spl.c str-spn.c str-str.c str-subst.c str-tok.c \
str-trm.c str-word.c task.c time.c tio.c tmr.c tre.c tre-ast.c \
tre-compile.c tre-match-backtrack.c tre-match-parallel.c \
tre-parse.c tre-stack.c uri.c utf8.c xma.c $(am__append_1) \
$(am__append_2)
path-basename.c path-canon.c pio.c pma.c rbt.c rex.c sck.c \
sio.c sll.c slmb.c str-beg.c str-cat.c str-chr.c str-cnv.c \
str-cmp.c str-cpy.c str-del.c str-dup.c str-dyn.c str-end.c \
str-excl.c str-fcpy.c str-fmt.c str-fnmat.c str-incl.c \
str-join.c str-len.c str-pac.c str-pbrk.c str-put.c str-rev.c \
str-rot.c str-set.c str-spl.c str-spn.c str-str.c str-subst.c \
str-tok.c str-trm.c str-word.c task.c time.c tio.c tmr.c tre.c \
tre-ast.c tre-compile.c tre-match-backtrack.c \
tre-match-parallel.c tre-parse.c tre-stack.c uri.c utf8.c \
xma.c $(am__append_1) $(am__append_2)
libqsecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
libqsecmn_la_LIBADD = $(SOCKET_LIBS) $(QUADMATH_LIBS)
@ENABLE_CXX_TRUE@libqsecmnxx_la_SOURCES = \
@ -555,6 +556,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pma.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rbt.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rex.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sck.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slmb.Plo@am__quote@

View File

@ -377,11 +377,7 @@ int qse_nwio_init (
int flags, const qse_nwio_tmout_t* tmout)
{
qse_skad_t addr;
#if defined(HAVE_SOCKLEN_T)
socklen_t addrlen;
#else
int addrlen;
#endif
qse_sck_len_t addrlen;
int family, type, tmp;
QSE_MEMSET (nwio, 0, QSE_SIZEOF(*nwio));
@ -744,11 +740,7 @@ int qse_nwio_init (
if (wait_for_data (nwio, &nwio->tmout.c, 1) <= -1) goto oops;
else
{
#if defined(HAVE_SOCKLEN_T)
socklen_t xlen;
#else
int xlen;
#endif
qse_sck_len_t xlen;
xlen = QSE_SIZEOF(xret);
if (getsockopt (nwio->handle, SOL_SOCKET, SO_ERROR, (char*)&xret, &xlen) <= -1)
{
@ -766,7 +758,7 @@ int qse_nwio_init (
{
xret = connect (nwio->handle, (struct sockaddr*)&addr, addrlen);
if (xret <= -1)
{
{
nwio->errnum = skerr_to_errnum (errno);
goto oops;
}
@ -810,18 +802,7 @@ oops:
nwio->tio = QSE_NULL;
}
#if defined(_WIN32)
if (nwio->handle != INVALID_SOCKET) closesocket (nwio->handle);
#elif defined(__OS2__)
if (nwio->handle >= 0) soclose (nwio->handle);
#elif defined(__DOS__)
/* TODO: */
#else
if (nwio->handle >= 0) QSE_CLOSE (nwio->handle);
#endif
if (qse_isvalidsckhnd(nwio->handle)) qse_closesckhnd (nwio->handle);
return -1;
}
@ -835,15 +816,7 @@ void qse_nwio_fini (qse_nwio_t* nwio)
nwio->tio = QSE_NULL;
}
#if defined(_WIN32)
closesocket (nwio->handle);
#elif defined(__OS2__)
/* TODO: */
#elif defined(__DOS__)
/* TODO: */
#else
QSE_CLOSE (nwio->handle);
#endif
qse_closesckhnd (nwio->handle);
}
qse_mmgr_t* qse_nwio_getmmgr (qse_nwio_t* nwio)
@ -1031,11 +1004,7 @@ reread:
if (nwio->status & STATUS_UDP_CONNECT)
{
qse_skad_t addr;
#if defined(HAVE_SOCKLEN_T)
socklen_t addrlen;
#else
int addrlen;
#endif
qse_sck_len_t addrlen;
addrlen = QSE_SIZEOF(addr);

202
qse/lib/cmn/sck.c Normal file
View File

@ -0,0 +1,202 @@
/*
* $Id$
*
Copyright 2006-2014 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/sck.h>
#if defined(_WIN32)
# include <winsock2.h>
# include <ws2tcpip.h> /* sockaddr_in6 */
# include <windows.h>
#elif defined(__OS2__)
# if defined(TCPV40HDRS)
# define BSD_SELECT
# endif
# include <types.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <sys/ioctl.h>
# include <nerrno.h>
# if defined(TCPV40HDRS)
# define USE_SELECT
# include <sys/select.h>
# else
# include <unistd.h>
# endif
#elif defined(__DOS__)
/* TODO: consider watt-32 */
#else
# include "syscall.h"
# include <sys/socket.h>
# include <netinet/in.h>
# if defined(HAVE_NETINET_SCTP_H)
# include <netinet/sctp.h>
# endif
#endif
QSE_INLINE int qse_isvalidsckhnd (qse_sck_hnd_t handle)
{
#if defined(_WIN32)
return handle != QSE_INVALID_SCKHND;
#elif defined(__OS2__)
return handle >= 0;
#elif defined(__DOS__)
/* TODO: */
return 0;
#else
return handle >= 0;
#endif
}
QSE_INLINE void qse_closesckhnd (qse_sck_hnd_t handle)
{
#if defined(_WIN32)
closesocket (handle);
#elif defined(__OS2__)
soclose (handle);
#elif defined(__DOS__)
/* TODO: */
#else
QSE_CLOSE (handle);
#endif
}
#if 0
qse_sck_hnd_t
int qse_sck_open (qse_mmgr_t* mmgr, qse_sck_type_t type)
{
}
void qse_sck_close (qse_sck_t* sck)
{
}
int qse_sck_init (qse_sck_t* sck, qse_mmgr_t* mmgr, qse_sck_type_t type)
{
int domain, type, proto = 0;
switch (type)
{
case QSE_SCK_TCP4:
domain = AF_INET;
type = SOCK_STREAM;
break;
case QSE_SCK_TCP6:
domain = AF_INET6;
type = SOCK_STREAM;
break;
case QSE_SCK_UDP4:
domain = AF_INET;
type = SOCK_DGRAM;
break;
case QSE_SCK_UDP6:
domain = AF_INET6;
type = SOCK_DGRAM;
break;
case QSE_SCK_SCTP4:
domain = AF_INET;
type = SCOK_SEQPACKET;
proto = IPPROTO_SCTP;
break;
case QSE_SCK_SCTP6:
domain = AF_INET6;
type = SCOK_SEQPACKET;
proto = IPPROTO_SCTP;
break;
case QSE_SCK_SCTP4:
domain = AF_INET;
type = SCOK_STREAM;
proto = IPPROTO_SCTP;
break;
case QSE_SCK_SCTP6:
domain = AF_INET6;
type = SCOK_STREAM;
proto = IPPROTO_SCTP;
break;
#if 0
case QSE_SCK_RAW4:
domain = AF_INET;
type = SOCK_RAW;
break;
case QSE_SCK_RAW6:
domain = AF_INET6;
type = SOCK_RAW;
break;
case QSE_SCK_PACKET:
domain = AF_PACKET;
type = SOCK_RAW;
proto = qse_hton16(ETH_P_ALL);
break;
case QSE_SCK_PACKET:
domain = AF_PACKET;
type = SOCK_DGRAM; /* cooked packet with the link level header removed */
proto = qse_hton16(ETH_P_ALL);
break;
case QSE_SCK_ARP:
domain = AF_PACKET;
type = SOCK_RAW;
proto = qse_hton16(ETH_P_ARP);
proto =
#endif
}
sck->handle = socket (domain, type, proto);
}
void qse_sck_fini (qse_sck_t* sck)
{
#if defined(_WIN32)
closesocket (sck->handle);
#elif defined(__OS2__)
soclose (sck->handle);
#elif defined(__DOS__)
/* TODO: */
#else
QSE_CLOSE (sck->handle);
#endif
}
qse_ssize_t qse_recvsocket ()
qse_ssize_t recvfromsocket ()
qse_ssize_t sendsocket ()
qse_ssize_t sendtosocket ()
#endif