started adding nwio
This commit is contained in:
@ -135,6 +135,8 @@ static int find_rio_in (
|
||||
return -1;
|
||||
}
|
||||
|
||||
QSE_MEMSET (p, 0, QSE_SIZEOF(*p));
|
||||
|
||||
p->name = QSE_AWK_STRDUP (run->awk, name);
|
||||
if (p->name == QSE_NULL)
|
||||
{
|
||||
@ -146,6 +148,7 @@ static int find_rio_in (
|
||||
p->type = (io_type | io_mask);
|
||||
p->mode = io_mode;
|
||||
p->rwcmode = QSE_AWK_RIO_CLOSE_FULL;
|
||||
/*
|
||||
p->handle = QSE_NULL;
|
||||
p->next = QSE_NULL;
|
||||
p->rwcstate = 0;
|
||||
@ -155,6 +158,7 @@ static int find_rio_in (
|
||||
p->in.len = 0;
|
||||
p->in.eof = 0;
|
||||
p->in.eos = 0;
|
||||
*/
|
||||
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
||||
|
||||
@ -718,6 +722,8 @@ int qse_awk_rtx_writeio_str (
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
QSE_MEMSET (p, 0, QSE_SIZEOF(*p));
|
||||
|
||||
p->name = QSE_AWK_STRDUP (run->awk, name);
|
||||
if (p->name == QSE_NULL)
|
||||
@ -730,12 +736,14 @@ int qse_awk_rtx_writeio_str (
|
||||
p->type = (io_type | io_mask);
|
||||
p->mode = io_mode;
|
||||
p->rwcmode = QSE_AWK_RIO_CLOSE_FULL;
|
||||
/*
|
||||
p->handle = QSE_NULL;
|
||||
p->next = QSE_NULL;
|
||||
p->rwcstate = 0;
|
||||
|
||||
p->out.eof = 0;
|
||||
p->out.eos = 0;
|
||||
*/
|
||||
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
||||
n = handler (run, QSE_AWK_RIO_OPEN, p, QSE_NULL, 0);
|
||||
|
@ -765,6 +765,20 @@ qse_bool_t qse_awk_rtx_isstop (qse_awk_rtx_t* rtx)
|
||||
return (rtx->exit_level == EXIT_ABORT || rtx->awk->stopall);
|
||||
}
|
||||
|
||||
void qse_awk_rtx_getrio (qse_awk_rtx_t* rtx, qse_awk_rio_t* rio)
|
||||
{
|
||||
rio->pipe = rtx->rio.handler[QSE_AWK_RIO_PIPE];
|
||||
rio->file = rtx->rio.handler[QSE_AWK_RIO_FILE];
|
||||
rio->console = rtx->rio.handler[QSE_AWK_RIO_CONSOLE];
|
||||
}
|
||||
|
||||
void qse_awk_rtx_setrio (qse_awk_rtx_t* rtx, const qse_awk_rio_t* rio)
|
||||
{
|
||||
rtx->rio.handler[QSE_AWK_RIO_PIPE] = rio->pipe;
|
||||
rtx->rio.handler[QSE_AWK_RIO_FILE] = rio->file;
|
||||
rtx->rio.handler[QSE_AWK_RIO_CONSOLE] = rio->console;
|
||||
}
|
||||
|
||||
qse_awk_rcb_t* qse_awk_rtx_poprcb (qse_awk_rtx_t* rtx)
|
||||
{
|
||||
qse_awk_rcb_t* top = rtx->rcb;
|
||||
@ -917,7 +931,7 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
|
||||
}
|
||||
else rtx->pattern_range_state = QSE_NULL;
|
||||
|
||||
if (rio != QSE_NULL)
|
||||
if (rio)
|
||||
{
|
||||
rtx->rio.handler[QSE_AWK_RIO_PIPE] = rio->pipe;
|
||||
rtx->rio.handler[QSE_AWK_RIO_FILE] = rio->file;
|
||||
|
@ -91,11 +91,10 @@ typedef struct xtn_t
|
||||
} str;
|
||||
} u;
|
||||
} out;
|
||||
} s; /* script/source handling */
|
||||
|
||||
} s;
|
||||
} xtn_t;
|
||||
|
||||
|
||||
typedef struct rxtn_t
|
||||
{
|
||||
unsigned int seed;
|
||||
@ -124,11 +123,6 @@ typedef struct rxtn_t
|
||||
#endif
|
||||
} rxtn_t;
|
||||
|
||||
#if defined(QSE_CHAR_IS_WCHAR)
|
||||
static qse_cmgr_t* getcmgr_from_cmgrtab (
|
||||
qse_awk_rtx_t* rtx, const qse_char_t* ioname);
|
||||
#endif
|
||||
|
||||
static qse_flt_t custom_awk_pow (qse_awk_t* awk, qse_flt_t x, qse_flt_t y)
|
||||
{
|
||||
#if defined(HAVE_POWL) && (QSE_SIZEOF_LONG_DOUBLE > QSE_SIZEOF_DOUBLE)
|
||||
@ -798,6 +792,7 @@ int qse_awk_parsestd (
|
||||
}
|
||||
|
||||
/*** RTX_OPENSTD ***/
|
||||
|
||||
static qse_ssize_t awk_rio_pipe (
|
||||
qse_awk_rtx_t* rtx, qse_awk_rio_cmd_t cmd, qse_awk_rio_arg_t* riod,
|
||||
qse_char_t* data, qse_size_t size)
|
||||
@ -811,7 +806,7 @@ static qse_ssize_t awk_rio_pipe (
|
||||
|
||||
if (riod->mode == QSE_AWK_RIO_PIPE_READ)
|
||||
{
|
||||
/* TODO: should we specify ERRTOOUT? */
|
||||
/* TODO: should ERRTOOUT be unset? */
|
||||
flags = QSE_PIO_READOUT |
|
||||
QSE_PIO_ERRTOOUT;
|
||||
}
|
||||
@ -825,7 +820,12 @@ static qse_ssize_t awk_rio_pipe (
|
||||
QSE_PIO_ERRTOOUT |
|
||||
QSE_PIO_WRITEIN;
|
||||
}
|
||||
else return -1; /* TODO: any way to set the error number? */
|
||||
else
|
||||
{
|
||||
/* this must not happen */
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EINTERN, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle = qse_pio_open (
|
||||
rtx->awk->mmgr,
|
||||
@ -838,7 +838,7 @@ static qse_ssize_t awk_rio_pipe (
|
||||
|
||||
#if defined(QSE_CHAR_IS_WCHAR)
|
||||
{
|
||||
qse_cmgr_t* cmgr = getcmgr_from_cmgrtab (rtx, riod->name);
|
||||
qse_cmgr_t* cmgr = qse_awk_rtx_getcmgrstd (rtx, riod->name);
|
||||
if (cmgr)
|
||||
{
|
||||
qse_pio_setcmgr (handle, QSE_PIO_IN, cmgr);
|
||||
@ -951,7 +951,7 @@ static qse_ssize_t awk_rio_file (
|
||||
|
||||
#if defined(QSE_CHAR_IS_WCHAR)
|
||||
{
|
||||
qse_cmgr_t* cmgr = getcmgr_from_cmgrtab (rtx, riod->name);
|
||||
qse_cmgr_t* cmgr = qse_awk_rtx_getcmgrstd (rtx, riod->name);
|
||||
if (cmgr) qse_sio_setcmgr (handle, cmgr);
|
||||
}
|
||||
#endif
|
||||
@ -1587,7 +1587,7 @@ static int fnc_time (qse_awk_rtx_t* rtx, const qse_cstr_t* fnm)
|
||||
}
|
||||
|
||||
#if defined(QSE_CHAR_IS_WCHAR)
|
||||
static qse_cmgr_t* getcmgr_from_cmgrtab (
|
||||
qse_cmgr_t* qse_awk_rtx_getcmgrstd (
|
||||
qse_awk_rtx_t* rtx, const qse_char_t* ioname)
|
||||
{
|
||||
rxtn_t* rxtn;
|
||||
|
@ -47,6 +47,7 @@ libqsecmn_la_SOURCES = \
|
||||
mbwc-str.c \
|
||||
mem.c \
|
||||
nwad.c \
|
||||
nwio.c \
|
||||
oht.c \
|
||||
opt.c \
|
||||
path-basename.c \
|
||||
|
@ -82,17 +82,18 @@ libqsecmn_la_LIBADD =
|
||||
am_libqsecmn_la_OBJECTS = alg-rand.lo alg-search.lo alg-sort.lo \
|
||||
assert.lo chr.lo cp949.lo cp950.lo dll.lo env.lo gdl.lo htb.lo \
|
||||
lda.lo fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo hton.lo \
|
||||
ipad.lo main.lo mbwc.lo mbwc-str.lo mem.lo nwad.lo oht.lo \
|
||||
opt.lo path-basename.lo path-canon.lo pio.lo pma.lo rbt.lo \
|
||||
rex.lo sio.lo sll.lo slmb.lo stdio.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-dynm.lo str-dynw.lo str-end.lo str-excl.lo \
|
||||
str-fcpy.lo str-fnmat.lo str-incl.lo str-len.lo str-pac.lo \
|
||||
str-pbrk.lo str-put.lo str-rev.lo str-rot.lo str-set.lo \
|
||||
str-spl.lo str-spn.lo str-str.lo str-subst.lo str-tok.lo \
|
||||
str-trm.lo str-word.lo time.lo tio.lo tio-get.lo tio-put.lo \
|
||||
tre.lo tre-ast.lo tre-compile.lo tre-match-backtrack.lo \
|
||||
tre-match-parallel.lo tre-parse.lo tre-stack.lo utf8.lo xma.lo
|
||||
ipad.lo main.lo mbwc.lo mbwc-str.lo mem.lo nwad.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 slmb.lo stdio.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-dynm.lo str-dynw.lo str-end.lo \
|
||||
str-excl.lo str-fcpy.lo str-fnmat.lo str-incl.lo str-len.lo \
|
||||
str-pac.lo str-pbrk.lo str-put.lo str-rev.lo str-rot.lo \
|
||||
str-set.lo str-spl.lo str-spn.lo str-str.lo str-subst.lo \
|
||||
str-tok.lo str-trm.lo str-word.lo time.lo tio.lo tio-get.lo \
|
||||
tio-put.lo tre.lo tre-ast.lo tre-compile.lo \
|
||||
tre-match-backtrack.lo tre-match-parallel.lo tre-parse.lo \
|
||||
tre-stack.lo utf8.lo xma.lo
|
||||
libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS)
|
||||
libqsecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
@ -326,6 +327,7 @@ libqsecmn_la_SOURCES = \
|
||||
mbwc-str.c \
|
||||
mem.c \
|
||||
nwad.c \
|
||||
nwio.c \
|
||||
oht.c \
|
||||
opt.c \
|
||||
path-basename.c \
|
||||
@ -489,6 +491,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwad.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nwio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oht.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/opt.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/path-basename.Plo@am__quote@
|
||||
|
@ -40,6 +40,9 @@
|
||||
#elif defined(__DOS__)
|
||||
# include <dos.h>
|
||||
# include <dosfunc.h>
|
||||
#elif defined(vms) || defined(__vms)
|
||||
# include <starlet.h> /* (SYS$...) */
|
||||
# include <ssdef.h> /* (SS$...) */
|
||||
#else
|
||||
# include "syscall.h"
|
||||
#endif
|
||||
@ -165,6 +168,9 @@ void qse_assert_failed (
|
||||
regs.h.al = 249;
|
||||
intdos (®s, ®s);
|
||||
}
|
||||
#elif defined(vms) || defined(__vms)
|
||||
sys$exit (SS$_ABORT); /* this condition code can be shown with
|
||||
* 'show symbol $status' from the command-line. */
|
||||
#else
|
||||
QSE_KILL (QSE_GETPID(), SIGABRT);
|
||||
QSE_EXIT (1);
|
||||
|
659
qse/lib/cmn/nwio.c
Normal file
659
qse/lib/cmn/nwio.c
Normal file
@ -0,0 +1,659 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2011 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 vernwion 3 of
|
||||
the License, or (at your option) any later vernwion.
|
||||
|
||||
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/nwio.h>
|
||||
#include "mem.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* TODO: */
|
||||
#elif defined(__OS2__)
|
||||
/* TODO: */
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
#else
|
||||
# include "syscall.h"
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
|
||||
static qse_ssize_t socket_input (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size);
|
||||
static qse_ssize_t socket_output (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size);
|
||||
|
||||
static int nwad_to_sockaddr (const qse_nwad_t* nwad, int* family, void* addr)
|
||||
{
|
||||
int addrsize = -1;
|
||||
|
||||
switch (nwad->type)
|
||||
{
|
||||
case QSE_NWAD_IN4:
|
||||
{
|
||||
struct sockaddr_in* in;
|
||||
|
||||
in = (struct sockaddr_in*)addr;
|
||||
addrsize = QSE_SIZEOF(*in);
|
||||
QSE_MEMSET (in, 0, addrsize);
|
||||
|
||||
*family = AF_INET;
|
||||
in->sin_family = AF_INET;
|
||||
in->sin_addr.s_addr = nwad->u.in4.addr.value;
|
||||
in->sin_port = nwad->u.in4.port;
|
||||
break;
|
||||
}
|
||||
|
||||
case QSE_NWAD_IN6:
|
||||
{
|
||||
#if defined(AF_INET6)
|
||||
struct sockaddr_in6* in;
|
||||
|
||||
in = (struct sockaddr_in6*)addr;
|
||||
addrsize = QSE_SIZEOF(*in);
|
||||
QSE_MEMSET (in, 0, addrsize);
|
||||
|
||||
*family = AF_INET6;
|
||||
in->sin6_family = AF_INET6;
|
||||
memcpy (&in->sin6_addr, &nwad->u.in6.addr, QSE_SIZEOF(nwad->u.in6.addr));
|
||||
in->sin6_scope_id = nwad->u.in6.scope;
|
||||
in->sin6_port = nwad->u.in6.port;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return addrsize;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
static qse_nwio_errnum_t syserr_to_errnum (DWORD e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case ERROR_NOT_ENOUGH_MEMORY:
|
||||
case ERROR_OUTOFMEMORY:
|
||||
return QSE_NWIO_ENOMEM;
|
||||
|
||||
case ERROR_INVALID_PARAMETER:
|
||||
case ERROR_INVALID_HANDLE:
|
||||
case ERROR_INVALID_NAME:
|
||||
return QSE_NWIO_EINVAL;
|
||||
|
||||
case ERROR_ACCESS_DENIED:
|
||||
return QSE_NWIO_EACCES;
|
||||
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
return QSE_NWIO_ENOENT;
|
||||
|
||||
case ERROR_ALREADY_EXISTS:
|
||||
case ERROR_FILE_EXISTS:
|
||||
return QSE_NWIO_EEXIST;
|
||||
|
||||
case ERROR_BROKEN_PIPE:
|
||||
return QSE_NWIO_EPIPE;
|
||||
|
||||
default:
|
||||
return QSE_NWIO_ESYSERR;
|
||||
}
|
||||
}
|
||||
#elif defined(__OS2__)
|
||||
static qse_nwio_errnum_t syserr_to_errnum (APIRET e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case ERROR_NOT_ENOUGH_MEMORY:
|
||||
return QSE_NWIO_ENOMEM;
|
||||
|
||||
case ERROR_INVALID_PARAMETER:
|
||||
case ERROR_INVALID_HANDLE:
|
||||
case ERROR_INVALID_NAME:
|
||||
return QSE_NWIO_EINVAL;
|
||||
|
||||
case ERROR_ACCESS_DENIED:
|
||||
return QSE_NWIO_EACCES;
|
||||
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
return QSE_NWIO_ENOENT;
|
||||
|
||||
case ERROR_ALREADY_EXISTS:
|
||||
return QSE_NWIO_EEXIST;
|
||||
|
||||
case ERROR_BROKEN_PIPE:
|
||||
return QSE_NWIO_EPIPE;
|
||||
|
||||
default:
|
||||
return QSE_NWIO_ESYSERR;
|
||||
}
|
||||
}
|
||||
#elif defined(__DOS__)
|
||||
static qse_nwio_errnum_t syserr_to_errnum (int e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case ENOMEM:
|
||||
return QSE_NWIO_ENOMEM;
|
||||
|
||||
case EINVAL:
|
||||
return QSE_NWIO_EINVAL;
|
||||
|
||||
case EACCES:
|
||||
return QSE_NWIO_EACCES;
|
||||
|
||||
case ENOENT:
|
||||
return QSE_NWIO_ENOENT;
|
||||
|
||||
case EEXIST:
|
||||
return QSE_NWIO_EEXIST;
|
||||
|
||||
|
||||
default:
|
||||
return QSE_NWIO_ESYSERR;
|
||||
}
|
||||
}
|
||||
#else
|
||||
static qse_nwio_errnum_t syserr_to_errnum (int e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case ENOMEM:
|
||||
return QSE_NWIO_ENOMEM;
|
||||
|
||||
case EINVAL:
|
||||
return QSE_NWIO_EINVAL;
|
||||
|
||||
case EACCES:
|
||||
return QSE_NWIO_EACCES;
|
||||
|
||||
case ENOENT:
|
||||
return QSE_NWIO_ENOENT;
|
||||
|
||||
case EEXIST:
|
||||
return QSE_NWIO_EEXIST;
|
||||
|
||||
case EINTR:
|
||||
return QSE_NWIO_EINTR;
|
||||
|
||||
case EPIPE:
|
||||
return QSE_NWIO_EPIPE;
|
||||
|
||||
#if defined(ECONNREFUSED) || defined(ENETUNREACH)
|
||||
#if defined(ECONNREFUSED)
|
||||
case ECONNREFUSED:
|
||||
#endif
|
||||
#if defined(ENETUNREACH)
|
||||
case ENETUNREACH:
|
||||
#endif
|
||||
return QSE_NWIO_ECONN;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return QSE_NWIO_ESYSERR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static qse_nwio_errnum_t tio_errnum_to_nwio_errnum (qse_tio_t* tio)
|
||||
{
|
||||
switch (tio->errnum)
|
||||
{
|
||||
case QSE_TIO_ENOMEM:
|
||||
return QSE_NWIO_ENOMEM;
|
||||
case QSE_TIO_EINVAL:
|
||||
return QSE_NWIO_EINVAL;
|
||||
case QSE_TIO_EACCES:
|
||||
return QSE_NWIO_EACCES;
|
||||
case QSE_TIO_ENOENT:
|
||||
return QSE_NWIO_ENOENT;
|
||||
case QSE_TIO_EILSEQ:
|
||||
return QSE_NWIO_EILSEQ;
|
||||
case QSE_TIO_EICSEQ:
|
||||
return QSE_NWIO_EICSEQ;
|
||||
case QSE_TIO_EILCHR:
|
||||
return QSE_NWIO_EILCHR;
|
||||
default:
|
||||
return QSE_NWIO_EOTHER;
|
||||
}
|
||||
}
|
||||
|
||||
qse_nwio_t* qse_nwio_open (
|
||||
qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_nwad_t* nwad, int flags)
|
||||
{
|
||||
qse_nwio_t* nwio;
|
||||
|
||||
nwio = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_nwio_t) + xtnsize);
|
||||
if (nwio == QSE_NULL) return QSE_NULL;
|
||||
|
||||
if (qse_nwio_init (nwio, mmgr, nwad, flags) <= -1)
|
||||
{
|
||||
QSE_MMGR_FREE (mmgr, nwio);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
return nwio;
|
||||
}
|
||||
|
||||
void qse_nwio_close (qse_nwio_t* nwio)
|
||||
{
|
||||
qse_nwio_fini (nwio);
|
||||
QSE_MMGR_FREE (nwio->mmgr, nwio);
|
||||
}
|
||||
|
||||
int qse_nwio_init (
|
||||
qse_nwio_t* nwio, qse_mmgr_t* mmgr, const qse_nwad_t* nwad, int flags)
|
||||
{
|
||||
union
|
||||
{
|
||||
struct sockaddr_in in4;
|
||||
struct sockaddr_in6 in6;
|
||||
} addr;
|
||||
int addrlen;
|
||||
int family;
|
||||
|
||||
QSE_MEMSET (nwio, 0, QSE_SIZEOF(*nwio));
|
||||
nwio->mmgr = mmgr;
|
||||
nwio->flags = flags;
|
||||
|
||||
addrlen = nwad_to_sockaddr (nwad, &family, &addr);
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* TODO: */
|
||||
#elif defined(__OS2__)
|
||||
/* TODO: */
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
#else
|
||||
nwio->handle = socket (family, SOCK_STREAM, 0);
|
||||
if (nwio->handle <= -1)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (errno);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
#if defined(FD_CLOEXEC)
|
||||
{
|
||||
int tmp = fcntl (nwio->handle, F_GETFD);
|
||||
if (tmp >= 0) fcntl (nwio->handle, F_SETFD, tmp | FD_CLOEXEC);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (flags & QSE_NWIO_LISTEN)
|
||||
{
|
||||
qse_nwio_hnd_t handle;
|
||||
|
||||
if (bind (nwio->handle, (struct sockaddr*)&addr, addrlen) <= -1 ||
|
||||
listen (nwio->handle, 10) <= -1)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (errno);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
/* TODO: socklen_t */
|
||||
handle = accept (nwio->handle, &addr, &addrlen);
|
||||
if (handle <= -1)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (errno);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
close (nwio->handle);
|
||||
nwio->handle = handle;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (connect (nwio->handle, (struct sockaddr*)&addr, addrlen) <= -1)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (errno);
|
||||
goto oops;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (flags & QSE_NWIO_TEXT)
|
||||
{
|
||||
int topt = 0;
|
||||
|
||||
if (flags & QSE_NWIO_IGNOREMBWCERR) topt |= QSE_TIO_IGNOREMBWCERR;
|
||||
if (flags & QSE_NWIO_NOAUTOFLUSH) topt |= QSE_TIO_NOAUTOFLUSH;
|
||||
|
||||
nwio->tio = qse_tio_open (mmgr, QSE_SIZEOF(qse_nwio_t*), topt);
|
||||
if (nwio->tio == QSE_NULL)
|
||||
{
|
||||
nwio->errnum = QSE_NWIO_ENOMEM;
|
||||
goto oops;
|
||||
}
|
||||
|
||||
/* store the back-reference to nwio in the extension area.*/
|
||||
*(qse_nwio_t**)QSE_XTN(nwio->tio) = nwio;
|
||||
|
||||
if (qse_tio_attachin (nwio->tio, socket_input, QSE_NULL, 4096) <= -1 ||
|
||||
qse_tio_attachout (nwio->tio, socket_output, QSE_NULL, 4096) <= -1)
|
||||
{
|
||||
if (nwio->errnum == QSE_NWIO_ENOERR)
|
||||
nwio->errnum = tio_errnum_to_nwio_errnum (nwio->tio);
|
||||
goto oops;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
if (nwio->tio) qse_tio_close (nwio->tio);
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* TODO: */
|
||||
#elif defined(__OS2__)
|
||||
/* TODO: */
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
#else
|
||||
close (nwio->handle);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
void qse_nwio_fini (qse_nwio_t* nwio)
|
||||
{
|
||||
/*if (qse_nwio_flush (nwio) <= -1) return -1;*/
|
||||
qse_nwio_flush (nwio);
|
||||
if (nwio->tio)
|
||||
{
|
||||
qse_tio_close (nwio->tio);
|
||||
nwio->tio = QSE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
qse_nwio_errnum_t qse_nwio_geterrnum (const qse_nwio_t* nwio)
|
||||
{
|
||||
return nwio->errnum;
|
||||
}
|
||||
|
||||
qse_cmgr_t* qse_nwio_getcmgr (qse_nwio_t* nwio)
|
||||
{
|
||||
return nwio->tio? qse_tio_getcmgr (nwio->tio): QSE_NULL;
|
||||
}
|
||||
|
||||
void qse_nwio_setcmgr (qse_nwio_t* nwio, qse_cmgr_t* cmgr)
|
||||
{
|
||||
if (nwio->tio) qse_tio_setcmgr (nwio->tio, cmgr);
|
||||
}
|
||||
|
||||
qse_nwio_hnd_t qse_nwio_gethandle (const qse_nwio_t* nwio)
|
||||
{
|
||||
return QSE_NWIO_HANDLE(nwio);
|
||||
}
|
||||
|
||||
qse_ubi_t qse_nwio_gethandleasubi (const qse_nwio_t* nwio)
|
||||
{
|
||||
qse_ubi_t ubi;
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* TODO: */
|
||||
#elif defined(__OS2__)
|
||||
/* TODO: */
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
#else
|
||||
ubi.i = nwio->handle;
|
||||
#endif
|
||||
return ubi;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_nwio_flush (qse_nwio_t* nwio)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
|
||||
if (nwio->tio)
|
||||
{
|
||||
nwio->errnum = QSE_NWIO_ENOERR;
|
||||
n = qse_tio_flush (nwio->tio);
|
||||
if (n <= -1 && nwio->errnum == QSE_NWIO_ENOERR)
|
||||
nwio->errnum = tio_errnum_to_nwio_errnum (nwio->tio);
|
||||
}
|
||||
else n = 0;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void qse_nwio_purge (qse_nwio_t* nwio)
|
||||
{
|
||||
if (nwio->tio) qse_tio_purge (nwio->tio);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- */
|
||||
|
||||
static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
DWORD count;
|
||||
#elif defined(__OS2__)
|
||||
ULONG count;
|
||||
APIRET rc;
|
||||
#elif defined(__DOS__)
|
||||
int n;
|
||||
#else
|
||||
qse_ssize_t n;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(DWORD)))
|
||||
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(DWORD);
|
||||
|
||||
if (ReadFile(nwio->handle, buf, (DWORD)size, &count, QSE_NULL) == FALSE)
|
||||
{
|
||||
/* ReadFile receives ERROR_BROKEN_PIPE when the write end
|
||||
* is closed in the child process */
|
||||
if (GetLastError() == ERROR_BROKEN_PIPE) return 0;
|
||||
nwio->errnum = syserr_to_errnum(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
return (qse_ssize_t)count;
|
||||
|
||||
#elif defined(__OS2__)
|
||||
|
||||
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(ULONG)))
|
||||
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(ULONG);
|
||||
|
||||
rc = DosRead (nwio->handle, buf, (ULONG)size, &count);
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
if (rc == ERROR_BROKEN_PIPE) return 0; /* TODO: check this */
|
||||
nwio->errnum = syserr_to_errnum(rc);
|
||||
return -1;
|
||||
}
|
||||
return (qse_ssize_t)count;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: verify this */
|
||||
|
||||
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(unsigned int)))
|
||||
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(unsigned int);
|
||||
|
||||
n = read (nwio->handle, buf, size);
|
||||
if (n <= -1) nwio->errnum = syserr_to_errnum(errno);
|
||||
return n;
|
||||
|
||||
#else
|
||||
|
||||
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(size_t)))
|
||||
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(size_t);
|
||||
|
||||
reread:
|
||||
n = recv (nwio->handle, buf, size, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
{
|
||||
if (nwio->flags & QSE_NWIO_READNORETRY)
|
||||
nwio->errnum = QSE_NWIO_EINTR;
|
||||
else goto reread;
|
||||
}
|
||||
else
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (errno);
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_ssize_t qse_nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
|
||||
{
|
||||
if (nwio->tio == QSE_NULL)
|
||||
return nwio_read (nwio, buf, size);
|
||||
else
|
||||
{
|
||||
qse_ssize_t n;
|
||||
|
||||
nwio->errnum = QSE_NWIO_ENOERR;
|
||||
n = qse_tio_read (nwio->tio, buf, size);
|
||||
if (n <= -1 && nwio->errnum == QSE_NWIO_ENOERR)
|
||||
nwio->errnum = tio_errnum_to_nwio_errnum (nwio->tio);
|
||||
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
static qse_ssize_t nwio_write (qse_nwio_t* nwio, const void* data, qse_size_t size)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
DWORD count;
|
||||
#elif defined(__OS2__)
|
||||
ULONG count;
|
||||
APIRET rc;
|
||||
#elif defined(__DOS__)
|
||||
int n;
|
||||
#else
|
||||
qse_ssize_t n;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(DWORD)))
|
||||
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(DWORD);
|
||||
|
||||
if (WriteFile (nwio->handle, data, (DWORD)size, &count, QSE_NULL) == FALSE)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
return (qse_ssize_t)count;
|
||||
|
||||
#elif defined(__OS2__)
|
||||
|
||||
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(ULONG)))
|
||||
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(ULONG);
|
||||
|
||||
rc = DosWrite (nwio->handle, (PVOID)data, (ULONG)size, &count);
|
||||
if (rc != NO_ERROR)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum(rc);
|
||||
return -1;
|
||||
}
|
||||
return (qse_ssize_t)count;
|
||||
|
||||
#elif defined(__DOS__)
|
||||
|
||||
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(unsigned int)))
|
||||
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(unsigned int);
|
||||
|
||||
n = write (nwio->handle, data, size);
|
||||
if (n <= -1) nwio->errnum = syserr_to_errnum (errno);
|
||||
return n;
|
||||
|
||||
#else
|
||||
|
||||
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(size_t)))
|
||||
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(size_t);
|
||||
|
||||
rewrite:
|
||||
n = send (nwio->handle, data, size, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
{
|
||||
if (nwio->flags & QSE_NWIO_WRITENORETRY)
|
||||
nwio->errnum = QSE_NWIO_EINTR;
|
||||
else goto rewrite;
|
||||
}
|
||||
else
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (errno);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_ssize_t qse_nwio_write (qse_nwio_t* nwio, const void* data, qse_size_t size)
|
||||
{
|
||||
if (nwio->tio == QSE_NULL)
|
||||
return nwio_write (nwio, data, size);
|
||||
else
|
||||
{
|
||||
qse_ssize_t n;
|
||||
|
||||
nwio->errnum = QSE_NWIO_ENOERR;
|
||||
n = qse_tio_write (nwio->tio, data, size);
|
||||
if (n <= -1 && nwio->errnum == QSE_NWIO_ENOERR)
|
||||
nwio->errnum = tio_errnum_to_nwio_errnum (nwio->tio);
|
||||
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- */
|
||||
|
||||
static qse_ssize_t socket_input (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size)
|
||||
{
|
||||
if (cmd == QSE_TIO_DATA)
|
||||
{
|
||||
qse_nwio_t* nwio;
|
||||
|
||||
nwio = *(qse_nwio_t**)QSE_XTN(tio);
|
||||
QSE_ASSERT (nwio != QSE_NULL);
|
||||
|
||||
return nwio_read (nwio, buf, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static qse_ssize_t socket_output (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size)
|
||||
{
|
||||
if (cmd == QSE_TIO_DATA)
|
||||
{
|
||||
qse_nwio_t* nwio;
|
||||
|
||||
nwio = *(qse_nwio_t**)QSE_XTN(tio);
|
||||
QSE_ASSERT (nwio != QSE_NULL);
|
||||
|
||||
return nwio_write (nwio, buf, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -575,6 +575,7 @@ int qse_pio_init (
|
||||
|
||||
QSE_MEMSET (pio, 0, QSE_SIZEOF(*pio));
|
||||
pio->mmgr = mmgr;
|
||||
pio->flags = flags;
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx */
|
||||
@ -1886,7 +1887,6 @@ create_process:
|
||||
}
|
||||
}
|
||||
|
||||
pio->option = 0;
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
@ -1961,8 +1961,9 @@ void qse_pio_fini (qse_pio_t* pio)
|
||||
qse_pio_end (pio, QSE_PIO_OUT);
|
||||
qse_pio_end (pio, QSE_PIO_IN);
|
||||
|
||||
pio->option &= ~QSE_PIO_WAIT_NOBLOCK;
|
||||
pio->option &= ~QSE_PIO_WAIT_NORETRY;
|
||||
/* when closing, enable blocking and retrying */
|
||||
pio->flags &= ~QSE_PIO_WAITNOBLOCK;
|
||||
pio->flags &= ~QSE_PIO_WAITNORETRY;
|
||||
qse_pio_wait (pio);
|
||||
}
|
||||
|
||||
@ -1971,16 +1972,6 @@ qse_pio_errnum_t qse_pio_geterrnum (const qse_pio_t* pio)
|
||||
return pio->errnum;
|
||||
}
|
||||
|
||||
int qse_pio_getoption (const qse_pio_t* pio)
|
||||
{
|
||||
return pio->option;
|
||||
}
|
||||
|
||||
void qse_pio_setoption (qse_pio_t* pio, int opt)
|
||||
{
|
||||
pio->option = opt;
|
||||
}
|
||||
|
||||
qse_cmgr_t* qse_pio_getcmgr (qse_pio_t* pio, qse_pio_hid_t hid)
|
||||
{
|
||||
return pio->pin[hid].tio?
|
||||
@ -2090,7 +2081,7 @@ reread:
|
||||
{
|
||||
if (errno == EINTR)
|
||||
{
|
||||
if (pio->option & QSE_PIO_READ_NORETRY)
|
||||
if (pio->flags & QSE_PIO_READNORETRY)
|
||||
pio->errnum = QSE_PIO_EINTR;
|
||||
else goto reread;
|
||||
}
|
||||
@ -2188,7 +2179,7 @@ rewrite:
|
||||
{
|
||||
if (errno == EINTR)
|
||||
{
|
||||
if (pio->option & QSE_PIO_WRITE_NORETRY)
|
||||
if (pio->flags & QSE_PIO_WRITENORETRY)
|
||||
pio->errnum = QSE_PIO_EINTR;
|
||||
else goto rewrite;
|
||||
}
|
||||
@ -2235,9 +2226,14 @@ qse_ssize_t qse_pio_flush (qse_pio_t* pio, qse_pio_hid_t hid)
|
||||
return n;
|
||||
}
|
||||
|
||||
void qse_pio_purge (qse_pio_t* pio, qse_pio_hid_t hid)
|
||||
{
|
||||
if (pio->pin[hid].tio) qse_tio_purge (pio->pin[hid].tio);
|
||||
}
|
||||
|
||||
void qse_pio_end (qse_pio_t* pio, qse_pio_hid_t hid)
|
||||
{
|
||||
if (pio->pin[hid].tio != QSE_NULL)
|
||||
if (pio->pin[hid].tio)
|
||||
{
|
||||
qse_tio_close (pio->pin[hid].tio);
|
||||
pio->pin[hid].tio = QSE_NULL;
|
||||
@ -2271,7 +2267,7 @@ int qse_pio_wait (qse_pio_t* pio)
|
||||
}
|
||||
|
||||
w = WaitForSingleObject (pio->child,
|
||||
((pio->option & QSE_PIO_WAIT_NOBLOCK)? 0: INFINITE)
|
||||
((pio->flags & QSE_PIO_WAITNOBLOCK)? 0: INFINITE)
|
||||
);
|
||||
if (w == WAIT_TIMEOUT)
|
||||
{
|
||||
@ -2327,7 +2323,7 @@ int qse_pio_wait (qse_pio_t* pio)
|
||||
|
||||
rc = DosWaitChild (
|
||||
DCWA_PROCESSTREE,
|
||||
((pio->option & QSE_PIO_WAIT_NOBLOCK)? DCWW_NOWAIT: DCWW_WAIT),
|
||||
((pio->flags & QSE_PIO_WAITNOBLOCK)? DCWW_NOWAIT: DCWW_WAIT),
|
||||
&child_rc,
|
||||
&ppid,
|
||||
pio->child
|
||||
@ -2367,7 +2363,7 @@ int qse_pio_wait (qse_pio_t* pio)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pio->option & QSE_PIO_WAIT_NOBLOCK) opt |= WNOHANG;
|
||||
if (pio->flags & QSE_PIO_WAITNOBLOCK) opt |= WNOHANG;
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -2385,7 +2381,7 @@ int qse_pio_wait (qse_pio_t* pio)
|
||||
}
|
||||
else if (errno == EINTR)
|
||||
{
|
||||
if (pio->option & QSE_PIO_WAIT_NORETRY)
|
||||
if (pio->flags & QSE_PIO_WAITNORETRY)
|
||||
pio->errnum = QSE_PIO_EINTR;
|
||||
else continue;
|
||||
}
|
||||
@ -2397,7 +2393,7 @@ int qse_pio_wait (qse_pio_t* pio)
|
||||
if (n == 0)
|
||||
{
|
||||
/* when WNOHANG is not specified, 0 can't be returned */
|
||||
QSE_ASSERT (pio->option & QSE_PIO_WAIT_NOBLOCK);
|
||||
QSE_ASSERT (pio->flags & QSE_PIO_WAITNOBLOCK);
|
||||
|
||||
ret = 255 + 1;
|
||||
/* the child process is still alive */
|
||||
|
@ -44,11 +44,6 @@ static qse_ssize_t file_input (
|
||||
static qse_ssize_t file_output (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size);
|
||||
|
||||
static qse_ssize_t socket_input (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size);
|
||||
static qse_ssize_t socket_output (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size);
|
||||
|
||||
static qse_sio_errnum_t fio_errnum_to_sio_errnum (qse_fio_t* fio)
|
||||
{
|
||||
switch (fio->errnum)
|
||||
@ -129,7 +124,7 @@ qse_sio_t* qse_sio_openstd (
|
||||
if (sio)
|
||||
{
|
||||
DWORD mode;
|
||||
if (GetConsoleMode (sio->u.file.handle, &mode) == TRUE &&
|
||||
if (GetConsoleMode (sio->file.handle, &mode) == TRUE &&
|
||||
GetConsoleOutputCP() == CP_UTF8)
|
||||
{
|
||||
sio->status |= STATUS_UTF8_CONSOLE;
|
||||
@ -163,10 +158,10 @@ int qse_sio_init (
|
||||
* this function, a user can specify a sio flag enumerator not
|
||||
* present in the fio flag enumerator. mask off such an enumerator. */
|
||||
if (qse_fio_init (
|
||||
&sio->u.file, mmgr, file,
|
||||
&sio->file, mmgr, file,
|
||||
(flags & ~QSE_FIO_RESERVED), mode) <= -1)
|
||||
{
|
||||
sio->errnum = fio_errnum_to_sio_errnum (&sio->u.file);
|
||||
sio->errnum = fio_errnum_to_sio_errnum (&sio->file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -176,7 +171,7 @@ int qse_sio_init (
|
||||
if (qse_tio_init(&sio->tio.io, mmgr, topt) <= -1)
|
||||
{
|
||||
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
|
||||
qse_fio_fini (&sio->u.file);
|
||||
qse_fio_fini (&sio->file);
|
||||
return -1;
|
||||
}
|
||||
/* store the back-reference to sio in the extension area.*/
|
||||
@ -189,7 +184,7 @@ int qse_sio_init (
|
||||
if (sio->errnum == QSE_SIO_ENOERR)
|
||||
sio->errnum = tio_errnum_to_sio_errnum (&sio->tio.io);
|
||||
qse_tio_fini (&sio->tio.io);
|
||||
qse_fio_fini (&sio->u.file);
|
||||
qse_fio_fini (&sio->file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -211,7 +206,7 @@ int qse_sio_initstd (
|
||||
if (n >= 0)
|
||||
{
|
||||
DWORD mode;
|
||||
if (GetConsoleMode (sio->u.file.handle, &mode) == TRUE &&
|
||||
if (GetConsoleMode (sio->file.handle, &mode) == TRUE &&
|
||||
GetConsoleOutputCP() == CP_UTF8)
|
||||
{
|
||||
sio->status |= STATUS_UTF8_CONSOLE;
|
||||
@ -227,7 +222,7 @@ void qse_sio_fini (qse_sio_t* sio)
|
||||
/*if (qse_sio_flush (sio) <= -1) return -1;*/
|
||||
qse_sio_flush (sio);
|
||||
qse_tio_fini (&sio->tio.io);
|
||||
qse_fio_fini (&sio->u.file);
|
||||
qse_fio_fini (&sio->file);
|
||||
}
|
||||
|
||||
qse_sio_errnum_t qse_sio_geterrnum (const qse_sio_t* sio)
|
||||
@ -247,13 +242,13 @@ void qse_sio_setcmgr (qse_sio_t* sio, qse_cmgr_t* cmgr)
|
||||
|
||||
qse_sio_hnd_t qse_sio_gethandle (const qse_sio_t* sio)
|
||||
{
|
||||
/*return qse_fio_gethandle (&sio->u.file);*/
|
||||
return QSE_FIO_HANDLE(&sio->u.file);
|
||||
/*return qse_fio_gethandle (&sio->file);*/
|
||||
return QSE_FIO_HANDLE(&sio->file);
|
||||
}
|
||||
|
||||
qse_ubi_t qse_sio_gethandleasubi (const qse_sio_t* sio)
|
||||
{
|
||||
return qse_fio_gethandleasubi (&sio->u.file);
|
||||
return qse_fio_gethandleasubi (&sio->file);
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_flush (qse_sio_t* sio)
|
||||
@ -453,7 +448,7 @@ qse_ssize_t qse_sio_putwcs (qse_sio_t* sio, const qse_wchar_t* str)
|
||||
for (cur = str, left = qse_wcslen(str); left > 0; cur += count, left -= count)
|
||||
{
|
||||
if (WriteConsoleW (
|
||||
sio->u.file.handle, cur, left,
|
||||
sio->file.handle, cur, left,
|
||||
&count, QSE_NULL) == FALSE)
|
||||
{
|
||||
sio->errnum = QSE_SIO_ESYSERR;
|
||||
@ -506,7 +501,7 @@ qse_ssize_t qse_sio_putwcsn (
|
||||
for (cur = str, left = size; left > 0; cur += count, left -= count)
|
||||
{
|
||||
if (WriteConsoleW (
|
||||
sio->u.file.handle, cur, left,
|
||||
sio->file.handle, cur, left,
|
||||
&count, QSE_NULL) == FALSE)
|
||||
{
|
||||
sio->errnum = QSE_SIO_ESYSERR;
|
||||
@ -544,10 +539,10 @@ int qse_sio_getpos (qse_sio_t* sio, qse_sio_pos_t* pos)
|
||||
{
|
||||
qse_fio_off_t off;
|
||||
|
||||
off = qse_fio_seek (&sio->u.file, 0, QSE_FIO_CURRENT);
|
||||
off = qse_fio_seek (&sio->file, 0, QSE_FIO_CURRENT);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
sio->errnum = fio_errnum_to_sio_errnum (&sio->u.file);
|
||||
sio->errnum = fio_errnum_to_sio_errnum (&sio->file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -560,10 +555,10 @@ int qse_sio_setpos (qse_sio_t* sio, qse_sio_pos_t pos)
|
||||
qse_fio_off_t off;
|
||||
|
||||
if (qse_sio_flush(sio) <= -1) return -1;
|
||||
off = qse_fio_seek (&sio->u.file, pos, QSE_FIO_BEGIN);
|
||||
off = qse_fio_seek (&sio->file, pos, QSE_FIO_BEGIN);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
sio->errnum = fio_errnum_to_sio_errnum (&sio->u.file);
|
||||
sio->errnum = fio_errnum_to_sio_errnum (&sio->file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -577,12 +572,12 @@ int qse_sio_seek (qse_sio_t* sio, qse_sio_seek_t pos)
|
||||
* can move to the end of the stream also.... */
|
||||
|
||||
if (qse_sio_flush(sio) <= -1) return -1;
|
||||
return (qse_fio_seek (&sio->u.file,
|
||||
return (qse_fio_seek (&sio->file,
|
||||
0, QSE_FIO_END) == (qse_fio_off_t)-1)? -1: 0;
|
||||
|
||||
/* TODO: write this function */
|
||||
if (qse_sio_flush(sio) <= -1) return -1;
|
||||
return (qse_fio_seek (&sio->u.file,
|
||||
return (qse_fio_seek (&sio->file,
|
||||
0, QSE_FIO_BEGIN) == (qse_fio_off_t)-1)? -1: 0;
|
||||
|
||||
}
|
||||
@ -600,8 +595,8 @@ static qse_ssize_t file_input (
|
||||
sio = *(qse_sio_t**)QSE_XTN(tio);
|
||||
QSE_ASSERT (sio != QSE_NULL);
|
||||
|
||||
n = qse_fio_read (&sio->u.file, buf, size);
|
||||
if (n <= -1) sio->errnum = fio_errnum_to_sio_errnum (&sio->u.file);
|
||||
n = qse_fio_read (&sio->file, buf, size);
|
||||
if (n <= -1) sio->errnum = fio_errnum_to_sio_errnum (&sio->file);
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -619,61 +614,11 @@ static qse_ssize_t file_output (
|
||||
sio = *(qse_sio_t**)QSE_XTN(tio);
|
||||
QSE_ASSERT (sio != QSE_NULL);
|
||||
|
||||
n = qse_fio_write (&sio->u.file, buf, size);
|
||||
if (n <= -1) sio->errnum = fio_errnum_to_sio_errnum (&sio->u.file);
|
||||
n = qse_fio_write (&sio->file, buf, size);
|
||||
if (n <= -1) sio->errnum = fio_errnum_to_sio_errnum (&sio->file);
|
||||
return n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- */
|
||||
|
||||
#if 0
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <winsock2.h>
|
||||
#else
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
static qse_ssize_t socket_input (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size)
|
||||
{
|
||||
|
||||
if (cmd == QSE_TIO_DATA)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
qse_sio_t* sio;
|
||||
|
||||
sio = *(qse_sio_t**)QSE_XTN(tio);
|
||||
QSE_ASSERT (sio != QSE_NULL);
|
||||
|
||||
n = recv (sio->u.sck, buf, size, 0);
|
||||
if (n <= -1) sio->errnum = syserr_to_errnum (errno);
|
||||
return n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static qse_ssize_t socket_output (
|
||||
qse_tio_t* tio, qse_tio_cmd_t cmd, void* buf, qse_size_t size)
|
||||
{
|
||||
if (cmd == QSE_TIO_DATA)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
qse_sio_t* sio;
|
||||
|
||||
sio = *(qse_sio_t**)QSE_XTN(tio);
|
||||
QSE_ASSERT (sio != QSE_NULL);
|
||||
|
||||
n = send (sio->u.sck, buf, size, 0);
|
||||
if (n <= -1) sio->errnum = syserr_to_errnum (errno);
|
||||
return n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -21,7 +21,8 @@
|
||||
#include "sed.h"
|
||||
#include "../cmn/mem.h"
|
||||
|
||||
const qse_char_t* qse_sed_dflerrstr (qse_sed_t* sed, qse_sed_errnum_t errnum)
|
||||
const qse_char_t* qse_sed_dflerrstr (
|
||||
const qse_sed_t* sed, qse_sed_errnum_t errnum)
|
||||
{
|
||||
static const qse_char_t* errstr[] =
|
||||
{
|
||||
|
@ -233,11 +233,10 @@ void qse_sed_fini (
|
||||
);
|
||||
|
||||
const qse_char_t* qse_sed_dflerrstr (
|
||||
qse_sed_t* sed,
|
||||
const qse_sed_t* sed,
|
||||
qse_sed_errnum_t errnum
|
||||
);
|
||||
|
||||
|
||||
#ifdef USE_REX
|
||||
/**
|
||||
* The qse_sed_getmaxdepth() gets the maximum processing depth.
|
||||
|
Reference in New Issue
Block a user