enhanced error handling of sio,pio,tio

This commit is contained in:
2012-02-12 13:20:39 +00:00
parent 3df521f7a9
commit a2346f6e4b
21 changed files with 1104 additions and 525 deletions

View File

@ -28,49 +28,62 @@
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/tio.h>
enum qse_fio_open_flag_t
enum qse_fio_flag_t
{
/** request text-based based IO */
QSE_FIO_TEXT = (1 << 0),
QSE_FIO_IGNOREMBWCERR = (1 << 1), /* useful if QSE_FIO_TEXT is set */
QSE_FIO_NOAUTOFLUSH = (1 << 2), /* useful if QSE_FIO_TEXT is set */
/* (1 << 0) to (1 << 7) reserved for qse_sio_flag_t.
* see <qse/cmn/sio.h>. nerver use this value. */
QSE_FIO_RESERVED = 0xFF,
/** treat the file name pointer as a handle pointer */
QSE_FIO_HANDLE = (1 << 3),
QSE_FIO_HANDLE = (1 << 8),
/** treate the file name pointer as a pointer to file name
* template to use when making a temporary file name */
QSE_FIO_TEMPORARY = (1 << 4),
QSE_FIO_TEMPORARY = (1 << 9),
/** don't close an I/O handle in qse_fio_fini() and qse_fio_close() */
QSE_FIO_NOCLOSE = (1 << 5),
QSE_FIO_NOCLOSE = (1 << 10),
/* normal open flags */
QSE_FIO_READ = (1 << 8),
QSE_FIO_WRITE = (1 << 9),
QSE_FIO_APPEND = (1 << 10),
QSE_FIO_READ = (1 << 14),
QSE_FIO_WRITE = (1 << 15),
QSE_FIO_APPEND = (1 << 16),
QSE_FIO_CREATE = (1 << 11),
QSE_FIO_TRUNCATE = (1 << 12),
QSE_FIO_EXCLUSIVE = (1 << 13),
QSE_FIO_SYNC = (1 << 14),
QSE_FIO_CREATE = (1 << 17),
QSE_FIO_TRUNCATE = (1 << 18),
QSE_FIO_EXCLUSIVE = (1 << 19),
QSE_FIO_SYNC = (1 << 20),
/* do not follow a symbolic link, only on a supported platform */
QSE_FIO_NOFOLLOW = (1 << 15),
QSE_FIO_NOFOLLOW = (1 << 23),
/* for WIN32 only. harmless(no effect) when used on other platforms */
QSE_FIO_NOSHREAD = (1 << 20),
QSE_FIO_NOSHWRITE = (1 << 21),
QSE_FIO_NOSHDELETE = (1 << 22),
QSE_FIO_NOSHREAD = (1 << 24),
QSE_FIO_NOSHWRITE = (1 << 25),
QSE_FIO_NOSHDELETE = (1 << 26),
/* hints to OS. harmless(no effect) when used on unsupported platforms */
QSE_FIO_RANDOM = (1 << 23), /* hint that access be random */
QSE_FIO_SEQUENTIAL = (1 << 24) /* hint that access is sequential */
QSE_FIO_RANDOM = (1 << 27), /* hint that access be random */
QSE_FIO_SEQUENTIAL = (1 << 28) /* hint that access is sequential */
};
enum qse_fio_errnum_t
{
QSE_FIO_ENOERR = 0, /**< no error */
QSE_FIO_ENOMEM, /**< out of memory */
QSE_FIO_EINVAL, /**< invalid parameter */
QSE_FIO_EACCES, /**< access denied */
QSE_FIO_ENOENT, /**< no such file */
QSE_FIO_EEXIST, /**< already exist */
QSE_FIO_EINTR, /**< interrupted */
QSE_FIO_ENOIMPL, /**< not implemented */
QSE_FIO_ESUBSYS, /**< subsystem(system call) error */
QSE_FIO_EOTHER /**< other error */
};
typedef enum qse_fio_errnum_t qse_fio_errnum_t;
enum qse_fio_std_t
{
QSE_FIO_STDIN = 0,
@ -126,13 +139,10 @@ typedef struct qse_fio_lck_t qse_fio_lck_t;
struct qse_fio_t
{
/* note that qse_fio_t is instantiated statically
* in sio.c. make sure that you update the static instantiation
* when you change the structure of qse_fio_t */
QSE_DEFINE_COMMON_FIELDS (fio)
qse_fio_hnd_t handle;
int flags; /* extra flags */
qse_tio_t* tio;
qse_fio_errnum_t errnum;
qse_fio_hnd_t handle;
int flags; /* extra flags */
};
struct qse_fio_lck_t
@ -200,23 +210,6 @@ void qse_fio_fini (
qse_fio_t* fio
);
/**
* The qse_fio_getcmgr() funcfion returns the current character manager.
* It returns #QSE_NULL is @a fio is not opened with #QSE_FIO_TEXT.
*/
qse_cmgr_t* qse_fio_getcmgr (
qse_fio_t* fio
);
/**
* The qse_fio_setcmgr() funcfion changes the character manager to @a cmgr.
* The character manager is used only if @a fio is opened with #QSE_FIO_TEXT.
*/
void qse_fio_setcmgr (
qse_fio_t* fio,
qse_cmgr_t* cmgr
);
/**
* The qse_fio_gethandle() function returns the native file handle.
*/
@ -224,15 +217,8 @@ qse_fio_hnd_t qse_fio_gethandle (
qse_fio_t* fio
);
/**
* The qse_fio_sethandle() function sets the file handle
* Avoid using this function if you don't know what you are doing.
* You may have to retrieve the previous handle using qse_fio_gethandle()
* to take relevant actions before resetting it with qse_fio_sethandle().
*/
void qse_fio_sethandle (
qse_fio_t* fio,
qse_fio_hnd_t handle
qse_ubi_t qse_fio_gethandleasubi (
qse_fio_t* fio
);
/**
@ -273,15 +259,6 @@ qse_ssize_t qse_fio_write (
qse_size_t size
);
/**
* The qse_fio_flush() function flushes data. It is useful if #QSE_FIO_TEXT is
* set for the file handle @a fio.
*/
qse_ssize_t qse_fio_flush (
qse_fio_t* fio
);
/**
* The qse_fio_chmod() function changes the file mode.
*

View File

@ -126,15 +126,22 @@ enum qse_pio_option_t
enum qse_pio_errnum_t
{
QSE_PIO_ENOERR = 0, /**< no error */
QSE_PIO_ENOMEM, /**< out of memory */
QSE_PIO_EINVAL, /**< invalid parameter */
QSE_PIO_ENOHND, /**< no handle available */
QSE_PIO_ECHILD, /**< the child is not valid */
QSE_PIO_EINTR, /**< interrupted */
QSE_PIO_EPIPE, /**< broken pipe */
QSE_PIO_EACCES, /**< access denied */
QSE_PIO_ENOENT, /**< no such file */
QSE_PIO_ESUBSYS /**< subsystem(system call) error */
QSE_PIO_EEXIST, /**< already exist */
QSE_PIO_EINTR, /**< interrupted */
QSE_PIO_ENOHND, /**< no handle available */
QSE_PIO_ECHILD, /**< the child is not valid */
QSE_PIO_EPIPE, /**< broken pipe */
QSE_PIO_EILSEQ, /**< illegal sequence */
QSE_PIO_EICSEQ, /**< incomplete sequence */
QSE_PIO_EILCHR, /**< illegal character */
QSE_PIO_ESUBSYS, /**< subsystem error */
QSE_PIO_EOTHER /**< unknown error */
};
typedef enum qse_pio_errnum_t qse_pio_errnum_t;
@ -281,15 +288,6 @@ qse_pio_errnum_t qse_pio_geterrnum (
qse_pio_t* pio /**< pio object */
);
/**
* The qse_pio_geterrmsg() function returns the pointer to a constant string
* describing the last error occurred.
* @return error message
*/
const qse_char_t* qse_pio_geterrmsg (
qse_pio_t* pio /**< pio object */
);
/**
* The qse_pio_getcmgr() function returns the current character manager.
* It returns #QSE_NULL is @a pio is not opened with #QSE_PIO_TEXT.

View File

@ -32,39 +32,52 @@
enum qse_sio_flag_t
{
QSE_SIO_IGNOREMBWCERR = QSE_FIO_IGNOREMBWCERR,
QSE_SIO_NOAUTOFLUSH = QSE_FIO_NOAUTOFLUSH,
/* ensure that these enumerators never overlap with
* qse_fio_flag_t enumerators. you can use values between
* (1<<0) and (1<<7) inclusive reserved in qse_fio_flag_t.
* the range is represented by QSE_FIO_RESERVED. */
QSE_SIO_URI = (1 << 0),
QSE_SIO_IGNOREMBWCERR = (1 << 1),
QSE_SIO_NOAUTOFLUSH = (1 << 2),
/* ensure that the following enumerators are one of
* qse_fio_flags_t enumerators */
QSE_SIO_HANDLE = QSE_FIO_HANDLE,
QSE_SIO_TEMPORARY = QSE_FIO_TEMPORARY,
QSE_SIO_NOCLOSE = QSE_FIO_NOCLOSE,
QSE_SIO_READ = QSE_FIO_READ,
QSE_SIO_WRITE = QSE_FIO_WRITE,
QSE_SIO_APPEND = QSE_FIO_APPEND,
QSE_SIO_CREATE = QSE_FIO_CREATE,
QSE_SIO_TRUNCATE = QSE_FIO_TRUNCATE,
QSE_SIO_EXCLUSIVE = QSE_FIO_EXCLUSIVE,
QSE_SIO_SYNC = QSE_FIO_SYNC,
QSE_SIO_NOFOLLOW = QSE_FIO_NOFOLLOW,
QSE_SIO_NOSHREAD = QSE_FIO_NOSHREAD,
QSE_SIO_NOSHWRITE = QSE_FIO_NOSHWRITE,
QSE_SIO_NOSHDELETE = QSE_FIO_NOSHDELETE,
QSE_SIO_RANDOM = QSE_FIO_RANDOM,
QSE_SIO_SEQUENTIAL = QSE_FIO_SEQUENTIAL
};
typedef qse_tio_errnum_t qse_sio_errnum_t;
#define QSE_SIO_ENOERR QSE_TIO_ENOERR
#define QSE_SIO_ENOMEM QSE_TIO_ENOMEM
#define QSE_SIO_ENOSPC QSE_TIO_ENOSPC
#define QSE_SIO_EILSEQ QSE_TIO_EILSEQ
#define QSE_SIO_EICSEQ QSE_TIO_EICSEQ
#define QSE_SIO_EILCHR QSE_TIO_EILCHR
#define QSE_SIO_ERRNUM(sio) QSE_TIO_ERRNUM(&((sio)->tio))
enum qse_sio_errnum_t
{
QSE_SIO_ENOERR = 0, /**< no error */
QSE_SIO_ENOMEM, /**< out of memory */
QSE_SIO_EINVAL, /**< invalid parameter */
QSE_SIO_EACCES, /**< access denied */
QSE_SIO_ENOENT, /**< no such file */
QSE_SIO_EEXIST, /**< already exist */
QSE_SIO_EINTR, /**< already exist */
QSE_SIO_EILSEQ, /**< illegal sequence */
QSE_SIO_EICSEQ, /**< incomplete sequence */
QSE_SIO_EILCHR, /**< illegal character */
QSE_SIO_ESUBSYS, /**< subsystem(system call) error */
QSE_SIO_EOTHER /**< other error */
};
typedef enum qse_sio_errnum_t qse_sio_errnum_t;
typedef qse_fio_off_t qse_sio_pos_t;
typedef qse_fio_hnd_t qse_sio_hnd_t;
@ -82,18 +95,60 @@ typedef struct qse_sio_t qse_sio_t;
struct qse_sio_t
{
QSE_DEFINE_COMMON_FIELDS (tio)
qse_fio_t fio;
qse_tio_t tio;
QSE_DEFINE_COMMON_FIELDS (sio)
qse_sio_errnum_t errnum;
qse_mchar_t inbuf[2048];
qse_mchar_t outbuf[2048];
/*
depending on the stream type... FILE, FIFO, TCP, UDP
qse_sio_type_t type;
*/
union
{
qse_fio_t file;
int sck;
} u;
struct
{
qse_tio_t io;
qse_sio_t* xtn; /* static extension for tio */
} tio;
qse_mchar_t inbuf[2048];
qse_mchar_t outbuf[2048];
#if defined(_WIN32)
int status;
int status;
#endif
};
/** access the @a errnum field of the #qse_sio_t structure */
#define QSE_SIO_ERRNUM(sio) ((sio)->errnum)
#if 0
typedef struct qse_sio_uri_t qse_sio_uri_t;
struct qse_sio_uri_t
{
enum
{
QSE_SIO_FILE,
QSE_SIO_FIFO,
QSE_SIO_PIPE,
QSE_SIO_TCP,
QSE_SIO_UDP
};
union
{
const qse_char_t* file;
const qse_char_t* fifo;
/* nothing needed for pipe */
/* qse_ipap_t tcp;
qse_ipap_t udp; */
} u;
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -157,6 +212,10 @@ qse_sio_hnd_t qse_sio_gethandle (
qse_sio_t* sio
);
qse_ubi_t qse_sio_gethandleasubi (
qse_sio_t* sio
);
qse_ssize_t qse_sio_flush (
qse_sio_t* sio
);

View File

@ -33,15 +33,19 @@
enum qse_tio_errnum_t
{
QSE_TIO_ENOERR = 0,
QSE_TIO_ENOMEM, /* out of memory */
QSE_TIO_EINVAL, /* invalid parameter */
QSE_TIO_EACCES, /**< access denied */
QSE_TIO_ENOENT, /**< no such file */
QSE_TIO_ENOSPC, /* no more space */
QSE_TIO_EILSEQ, /* illegal sequence */
QSE_TIO_EICSEQ, /* incomplete sequence */
QSE_TIO_EILCHR, /* illegal character */
QSE_TIO_ENINPF, /* no input function attached */
QSE_TIO_ENOUTF, /* no output function attached */
QSE_TIO_EIOERR /* I/O error */
QSE_TIO_EOTHER /* other error */
};
typedef enum qse_tio_errnum_t qse_tio_errnum_t;
@ -82,8 +86,8 @@ typedef struct qse_tio_t qse_tio_t;
* The qse_tio_io_fun_t types define a text I/O handler.
*/
typedef qse_ssize_t (*qse_tio_io_fun_t) (
qse_tio_t* tio,
qse_tio_cmd_t cmd,
void* arg,
void* data,
qse_size_t size
);
@ -91,7 +95,6 @@ typedef qse_ssize_t (*qse_tio_io_fun_t) (
struct qse_tio_io_t
{
qse_tio_io_fun_t fun;
void* arg;
struct
{
qse_size_t capa;
@ -169,14 +172,6 @@ qse_tio_errnum_t qse_tio_geterrnum (
qse_tio_t* tio
);
/**
* The qse_tio_geterrmsg() function translates an error code to a string.
* @return pointer to a constant string describing the last error occurred.
*/
const qse_char_t* qse_tio_geterrmsg (
qse_tio_t* tio
);
/**
* The qse_tio_getcmgr() function returns the character manager.
*/
@ -199,7 +194,6 @@ void qse_tio_setcmgr (
int qse_tio_attachin (
qse_tio_t* tio,
qse_tio_io_fun_t input,
void* arg,
qse_mchar_t* bufptr,
qse_size_t bufcapa
);
@ -219,7 +213,6 @@ int qse_tio_detachin (
int qse_tio_attachout (
qse_tio_t* tio,
qse_tio_io_fun_t output,
void* arg,
qse_mchar_t* bufptr,
qse_size_t bufcapa
);

View File

@ -70,6 +70,9 @@
/* Define to 1 if you have the `expl' function. */
#undef HAVE_EXPL
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the `fdopendir' function. */
#undef HAVE_FDOPENDIR
@ -279,6 +282,9 @@
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/wait.h> header file. */
#undef HAVE_SYS_WAIT_H
/* Define to 1 if you have the `tan' function. */
#undef HAVE_TAN

View File

@ -53,14 +53,52 @@ typedef struct qse_http_version_t qse_http_version_t;
*/
enum qse_http_method_t
{
QSE_HTTP_GET,
QSE_HTTP_OTHER,
/* rfc 2616 */
QSE_HTTP_HEAD,
QSE_HTTP_GET,
QSE_HTTP_POST,
QSE_HTTP_PUT,
QSE_HTTP_DELETE,
QSE_HTTP_TRACE,
QSE_HTTP_OPTIONS,
QSE_HTTP_TRACE,
QSE_HTTP_CONNECT
#if 0
/* rfc 2518 */
QSE_HTTP_PROPFIND,
QSE_HTTP_PROPPATCH,
QSE_HTTP_MKCOL,
QSE_HTTP_COPY,
QSE_HTTP_MOVE,
QSE_HTTP_LOCK,
QSE_HTTP_UNLOCK,
/* rfc 3253 */
QSE_HTTP_VERSION_CONTROL,
QSE_HTTP_REPORT,
QSE_HTTP_CHECKOUT,
QSE_HTTP_CHECKIN,
QSE_HTTP_UNCHECKOUT,
QSE_HTTP_MKWORKSPACE,
QSE_HTTP_UPDATE,
QSE_HTTP_LABEL,
QSE_HTTP_MERGE,
QSE_HTTP_BASELINE_CONTROL,
QSE_HTTP_MKACTIVITY,
/* microsoft */
QSE_HTTP_BPROPFIND,
QSE_HTTP_BPROPPATCH,
QSE_HTTP_BCOPY,
QSE_HTTP_BDELETE,
QSE_HTTP_BMOVE,
QSE_HTTP_NOTIFY,
QSE_HTTP_POLL,
QSE_HTTP_SUBSCRIBE,
QSE_HTTP_UNSUBSCRIBE,
#endif
};
typedef enum qse_http_method_t qse_http_method_t;
@ -125,18 +163,16 @@ int qse_comparehttpversions (
const qse_http_version_t* v2
);
const qse_mchar_t* qse_gethttpmethodname (
const qse_mchar_t* qse_httpmethodtombs (
qse_http_method_t type
);
int qse_gethttpmethodtype (
const qse_mchar_t* name,
qse_http_method_t* method
qse_http_method_t qse_mbstohttpmethod (
const qse_mchar_t* name
);
int qse_gethttpmethodtypefromstr (
const qse_mcstr_t* name,
qse_http_method_t* type
qse_http_method_t qse_mcstrtohttpmethod (
const qse_mcstr_t* name
);
int qse_parsehttprange (