touched up code for warp 4
This commit is contained in:
@ -112,7 +112,7 @@ if ENABLE_BUNDLED_UNICODE
|
||||
libqsecmn_la_SOURCES += uni.c
|
||||
endif
|
||||
|
||||
if INCLUDE_MORE_CMGRS
|
||||
if ENABLE_XCMGRS
|
||||
libqsecmn_la_SOURCES += cp949.c cp950.c
|
||||
endif
|
||||
|
||||
|
@ -36,7 +36,7 @@ POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
@ENABLE_BUNDLED_UNICODE_TRUE@am__append_1 = uni.c
|
||||
@INCLUDE_MORE_CMGRS_TRUE@am__append_2 = cp949.c cp950.c
|
||||
@ENABLE_XCMGRS_TRUE@am__append_2 = cp949.c cp950.c
|
||||
@ENABLE_CXX_TRUE@am__append_3 = libqsecmnxx.la
|
||||
subdir = lib/cmn
|
||||
DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
|
||||
@ -100,7 +100,7 @@ am__libqsecmn_la_SOURCES_DIST = alg-base64.c alg-rand.c alg-search.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
|
||||
@INCLUDE_MORE_CMGRS_TRUE@am__objects_2 = cp949.lo cp950.lo
|
||||
@ENABLE_XCMGRS_TRUE@am__objects_2 = cp949.lo cp950.lo
|
||||
am_libqsecmn_la_OBJECTS = alg-base64.lo alg-rand.lo alg-search.lo \
|
||||
alg-sort.lo assert.lo chr.lo dir.lo dll.lo env.lo gdl.lo \
|
||||
htb.lo fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo glob.lo \
|
||||
|
@ -32,6 +32,8 @@
|
||||
# include <tchar.h>
|
||||
#elif defined(__OS2__)
|
||||
# define INCL_DOSFILEMGR
|
||||
# define INCL_DOSMODULEMGR
|
||||
# define INCL_DOSPROCESS
|
||||
# define INCL_DOSERRORS
|
||||
# include <os2.h>
|
||||
#elif defined(__DOS__)
|
||||
@ -178,6 +180,34 @@ static qse_fio_errnum_t syserr_to_errnum (int e)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__OS2__)
|
||||
|
||||
typedef APIRET (*DosOpenLType) (
|
||||
PSZ pszFileName, PHFILE pHf, PULONG pulAction,
|
||||
LONGLONG cbFile, ULONG ulAttribute,
|
||||
ULONG fsOpenFlags, ULONG fsOpenMode,
|
||||
PEAOP2 peaop2
|
||||
);
|
||||
|
||||
typedef APIRET (*DosSetFilePtrLType) (
|
||||
HFILE hFile,
|
||||
LONGLONG ib,
|
||||
ULONG method,
|
||||
PLONGLONG ibActual
|
||||
);
|
||||
|
||||
typedef APIRET (*DosSetFileSizeLType) (
|
||||
HFILE hFile,
|
||||
LONGLONG cbSize
|
||||
);
|
||||
|
||||
static int dos_set = 0;
|
||||
static DosOpenLType dos_open_l = QSE_NULL;
|
||||
static DosSetFilePtrLType dos_set_file_ptr_l = QSE_NULL;
|
||||
static DosSetFileSizeLType dos_set_file_size_l = QSE_NULL;
|
||||
|
||||
#endif
|
||||
|
||||
qse_fio_t* qse_fio_open (
|
||||
qse_mmgr_t* mmgr, qse_size_t ext,
|
||||
const qse_char_t* path, int flags, int mode)
|
||||
@ -216,6 +246,27 @@ int qse_fio_init (
|
||||
int fellback = 0;
|
||||
#endif
|
||||
|
||||
#if defined(__OS2__)
|
||||
if (!dos_set)
|
||||
{
|
||||
DosEnterCritSec ();
|
||||
if (!dos_set)
|
||||
{
|
||||
HMODULE mod;
|
||||
if (DosLoadModule(NULL, 0, "DOSCALL1", &mod) == NO_ERROR)
|
||||
{
|
||||
/* look up routines by ordinal */
|
||||
DosQueryProcAddr (mod, 981, NULL, (PFN*)&dos_open_l);
|
||||
DosQueryProcAddr (mod, 988, NULL, (PFN*)&dos_set_file_ptr_l);
|
||||
DosQueryProcAddr (mod, 989, NULL, (PFN*)&dos_set_file_size_l);
|
||||
}
|
||||
|
||||
dos_set = 1;
|
||||
}
|
||||
DosExitCritSec ();
|
||||
}
|
||||
#endif
|
||||
|
||||
QSE_MEMSET (fio, 0, QSE_SIZEOF(*fio));
|
||||
fio->mmgr = mmgr;
|
||||
|
||||
@ -456,11 +507,6 @@ int qse_fio_init (
|
||||
APIRET ret;
|
||||
ULONG action_taken = 0;
|
||||
ULONG open_action, open_mode, open_attr;
|
||||
#if defined(FIL_STANDARDL)
|
||||
LONGLONG zero;
|
||||
#else
|
||||
ULONG zero;
|
||||
#endif
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
const qse_mchar_t* path_mb = path;
|
||||
@ -498,13 +544,6 @@ int qse_fio_init (
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(FIL_STANDARDL)
|
||||
zero.ulLo = 0;
|
||||
zero.ulHi = 0;
|
||||
#else
|
||||
zero = 0;
|
||||
#endif
|
||||
|
||||
if (flags & QSE_FIO_APPEND)
|
||||
fio->status |= STATUS_APPEND;
|
||||
|
||||
@ -559,19 +598,39 @@ int qse_fio_init (
|
||||
open_attr = (mode & QSE_FIO_WUSR)? FILE_NORMAL: FILE_READONLY;
|
||||
|
||||
#if defined(FIL_STANDARDL)
|
||||
ret = DosOpenL (
|
||||
#else
|
||||
ret = DosOpen (
|
||||
if (dos_open_l)
|
||||
{
|
||||
LONGLONG zero;
|
||||
|
||||
zero.ulLo = 0;
|
||||
zero.ulHi = 0;
|
||||
ret = dos_open_l (
|
||||
path_mb, /* file name */
|
||||
&handle, /* file handle */
|
||||
&action_taken, /* store action taken */
|
||||
zero, /* size */
|
||||
open_attr, /* attribute */
|
||||
open_action, /* action if it exists */
|
||||
open_mode, /* open mode */
|
||||
0L
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
ret = DosOpen (
|
||||
path_mb, /* file name */
|
||||
&handle, /* file handle */
|
||||
&action_taken, /* store action taken */
|
||||
0, /* size */
|
||||
open_attr, /* attribute */
|
||||
open_action, /* action if it exists */
|
||||
open_mode, /* open mode */
|
||||
0L
|
||||
);
|
||||
#if defined(FIL_STANDARDL)
|
||||
}
|
||||
#endif
|
||||
path_mb, /* file name */
|
||||
&handle, /* file handle */
|
||||
&action_taken, /* store action taken */
|
||||
zero, /* size */
|
||||
open_attr, /* attribute */
|
||||
open_action, /* action if it exists */
|
||||
open_mode, /* open mode */
|
||||
0L
|
||||
);
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
/* nothing to do */
|
||||
@ -1033,36 +1092,41 @@ qse_fio_off_t qse_fio_seek (
|
||||
};
|
||||
|
||||
#if defined(FIL_STANDARDL)
|
||||
|
||||
LONGLONG pos, newpos;
|
||||
APIRET ret;
|
||||
|
||||
QSE_ASSERT (QSE_SIZEOF(offset) >= QSE_SIZEOF(pos));
|
||||
|
||||
pos.ulLo = (ULONG)(offset&0xFFFFFFFFlu);
|
||||
pos.ulHi = (ULONG)(offset>>32);
|
||||
|
||||
ret = DosSetFilePtrL (fio->handle, pos, seek_map[origin], &newpos);
|
||||
if (ret != NO_ERROR)
|
||||
if (dos_set_file_ptr_l)
|
||||
{
|
||||
fio->errnum = syserr_to_errnum (ret);
|
||||
return (qse_fio_off_t)-1;
|
||||
LONGLONG pos, newpos;
|
||||
APIRET ret;
|
||||
|
||||
QSE_ASSERT (QSE_SIZEOF(offset) >= QSE_SIZEOF(pos));
|
||||
|
||||
pos.ulLo = (ULONG)(offset&0xFFFFFFFFlu);
|
||||
pos.ulHi = (ULONG)(offset>>32);
|
||||
|
||||
ret = dos_set_file_ptr_l (fio->handle, pos, seek_map[origin], &newpos);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
fio->errnum = syserr_to_errnum (ret);
|
||||
return (qse_fio_off_t)-1;
|
||||
}
|
||||
|
||||
return ((qse_fio_off_t)newpos.ulHi << 32) | newpos.ulLo;
|
||||
}
|
||||
|
||||
return ((qse_fio_off_t)newpos.ulHi << 32) | newpos.ulLo;
|
||||
|
||||
#else
|
||||
ULONG newpos;
|
||||
APIRET ret;
|
||||
|
||||
ret = DosSetFilePtr (fio->handle, offset, seek_map[origin], &newpos);
|
||||
if (ret != NO_ERROR)
|
||||
else
|
||||
{
|
||||
fio->errnum = syserr_to_errnum (ret);
|
||||
return (qse_fio_off_t)-1;
|
||||
}
|
||||
#endif
|
||||
ULONG newpos;
|
||||
APIRET ret;
|
||||
|
||||
return newpos;
|
||||
ret = DosSetFilePtr (fio->handle, offset, seek_map[origin], &newpos);
|
||||
if (ret != NO_ERROR)
|
||||
{
|
||||
fio->errnum = syserr_to_errnum (ret);
|
||||
return (qse_fio_off_t)-1;
|
||||
}
|
||||
|
||||
return newpos;
|
||||
#if defined(FIL_STANDARDL)
|
||||
}
|
||||
#endif
|
||||
|
||||
#elif defined(__DOS__)
|
||||
@ -1123,15 +1187,22 @@ int qse_fio_truncate (qse_fio_t* fio, qse_fio_off_t size)
|
||||
APIRET ret;
|
||||
|
||||
#if defined(FIL_STANDARDL)
|
||||
LONGLONG sz;
|
||||
/* the file must have the write access for it to succeed */
|
||||
if (dos_set_file_size_l)
|
||||
{
|
||||
LONGLONG sz;
|
||||
/* the file must have the write access for it to succeed */
|
||||
|
||||
sz.ulLo = (ULONG)(size&0xFFFFFFFFlu);
|
||||
sz.ulHi = (ULONG)(size>>32);
|
||||
sz.ulLo = (ULONG)(size&0xFFFFFFFFlu);
|
||||
sz.ulHi = (ULONG)(size>>32);
|
||||
|
||||
ret = DosSetFileSizeL (fio->handle, sz);
|
||||
#else
|
||||
ret = DosSetFileSize (fio->handle, size);
|
||||
ret = DosSetFileSizeL (fio->handle, sz);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
ret = DosSetFileSize (fio->handle, size);
|
||||
#if defined(FIL_STANDARDL)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ret != NO_ERROR)
|
||||
@ -1274,13 +1345,20 @@ qse_ssize_t qse_fio_write (qse_fio_t* fio, const void* data, qse_size_t size)
|
||||
{
|
||||
/* i do this on a best-effort basis */
|
||||
#if defined(FIL_STANDARDL)
|
||||
LONGLONG pos, newpos;
|
||||
pos.ulLo = (ULONG)0;
|
||||
pos.ulHi = (ULONG)0;
|
||||
DosSetFilePtrL (fio->handle, pos, FILE_END, &newpos);
|
||||
#else
|
||||
ULONG newpos;
|
||||
DosSetFilePtr (fio->handle, 0, FILE_END, &newpos);
|
||||
if (dos_set_file_ptr_l)
|
||||
{
|
||||
LONGLONG pos, newpos;
|
||||
pos.ulLo = (ULONG)0;
|
||||
pos.ulHi = (ULONG)0;
|
||||
dos_set_file_ptr_l (fio->handle, pos, FILE_END, &newpos);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
ULONG newpos;
|
||||
DosSetFilePtr (fio->handle, 0, FILE_END, &newpos);
|
||||
#if defined(FIL_STANDARDL)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ static qse_cmgr_t builtin_cmgr[] =
|
||||
qse_slwctoslmb
|
||||
},
|
||||
|
||||
#if defined(QSE_INCLUDE_MORE_CMGRS)
|
||||
#if defined(QSE_ENABLE_XCMGRS)
|
||||
{
|
||||
qse_cp949touc,
|
||||
qse_uctocp949
|
||||
@ -91,7 +91,7 @@ qse_cmgr_t* qse_findcmgr (const qse_char_t* name)
|
||||
} tab[] =
|
||||
{
|
||||
{ QSE_T("utf8"), QSE_CMGR_UTF8 },
|
||||
#if defined(QSE_INCLUDE_MORE_CMGRS)
|
||||
#if defined(QSE_ENABLE_XCMGRS)
|
||||
{ QSE_T("cp949"), QSE_CMGR_CP949 },
|
||||
{ QSE_T("cp950"), QSE_CMGR_CP950 },
|
||||
#endif
|
||||
|
@ -30,12 +30,17 @@
|
||||
# include <types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <tcpustd.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <nerrno.h>
|
||||
# if defined(TCPV40HDRS)
|
||||
# define USE_SELECT
|
||||
# define BSD_SELECT
|
||||
# include <sys/select.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# define INCL_DOSERRORS
|
||||
# include <os2.h>
|
||||
# pragma library("tcpip32.lib")
|
||||
|
||||
#elif defined(__DOS__)
|
||||
# include <errno.h>
|
||||
@ -64,15 +69,7 @@ struct qse_mux_t
|
||||
qse_mux_errnum_t errnum;
|
||||
qse_mux_evtfun_t evtfun;
|
||||
|
||||
#if defined(__OS2__)
|
||||
int* fdarr;
|
||||
int size;
|
||||
struct
|
||||
{
|
||||
qse_mux_evt_t** ptr;
|
||||
int ubound;
|
||||
} me;
|
||||
#elif defined(USE_SELECT)
|
||||
#if defined(USE_SELECT)
|
||||
fd_set rset;
|
||||
fd_set wset;
|
||||
fd_set tmprset;
|
||||
@ -98,6 +95,14 @@ struct qse_mux_t
|
||||
qse_mux_evt_t** ptr;
|
||||
int ubound;
|
||||
} me;
|
||||
#elif defined(__OS2__)
|
||||
int* fdarr;
|
||||
int size;
|
||||
struct
|
||||
{
|
||||
qse_mux_evt_t** ptr;
|
||||
int ubound;
|
||||
} me;
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -140,8 +145,10 @@ static qse_mux_errnum_t syserr_to_errnum (int e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
#if defined(SOCENOMEM)
|
||||
case SOCENOMEM:
|
||||
return QSE_MUX_ENOMEM;
|
||||
#endif
|
||||
|
||||
case SOCEINVAL:
|
||||
return QSE_MUX_EINVAL;
|
||||
@ -149,11 +156,15 @@ static qse_mux_errnum_t syserr_to_errnum (int e)
|
||||
case SOCEACCES:
|
||||
return QSE_MUX_EACCES;
|
||||
|
||||
#if defined(SOCENOENT)
|
||||
case SOCENOENT:
|
||||
return QSE_MUX_ENOENT;
|
||||
#endif
|
||||
|
||||
#if defined(SOCEEXIST)
|
||||
case SOCEEXIST:
|
||||
return QSE_MUX_EEXIST;
|
||||
#endif
|
||||
|
||||
case SOCEINTR:
|
||||
return QSE_MUX_EINTR;
|
||||
@ -252,10 +263,7 @@ int qse_mux_init (qse_mux_t* mux, qse_mmgr_t* mmgr, qse_mux_evtfun_t evtfun, qse
|
||||
* event buffers */
|
||||
if (capahint <= 0) capahint = 1;
|
||||
|
||||
#if defined(__OS2__)
|
||||
/* nothing special to do */
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
#if defined(USE_SELECT)
|
||||
FD_ZERO (&mux->rset);
|
||||
FD_ZERO (&mux->wset);
|
||||
mux->maxhnd = -1;
|
||||
@ -281,6 +289,9 @@ int qse_mux_init (qse_mux_t* mux, qse_mmgr_t* mmgr, qse_mux_evtfun_t evtfun, qse
|
||||
}
|
||||
#endif
|
||||
|
||||
#elif defined(__OS2__)
|
||||
/* nothing special to do */
|
||||
|
||||
#else
|
||||
/* TODO: */
|
||||
mux->errnum = QSE_MUX_ENOIMPL;
|
||||
@ -292,24 +303,8 @@ int qse_mux_init (qse_mux_t* mux, qse_mmgr_t* mmgr, qse_mux_evtfun_t evtfun, qse
|
||||
|
||||
void qse_mux_fini (qse_mux_t* mux)
|
||||
{
|
||||
#if defined(__OS2__)
|
||||
if (mux->me.ptr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < mux->me.ubound; i++)
|
||||
{
|
||||
if (mux->me.ptr[i])
|
||||
QSE_MMGR_FREE (mux->mmgr, mux->me.ptr[i]);
|
||||
}
|
||||
|
||||
QSE_MMGR_FREE (mux->mmgr, mux->me.ptr);
|
||||
mux->me.ubound = 0;
|
||||
}
|
||||
|
||||
if (mux->fdarr) QSE_MMGR_FREE (mux->mmgr, mux->fdarr);
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
#if defined(USE_SELECT)
|
||||
FD_ZERO (&mux->rset);
|
||||
FD_ZERO (&mux->wset);
|
||||
|
||||
@ -351,6 +346,23 @@ void qse_mux_fini (qse_mux_t* mux)
|
||||
QSE_MMGR_FREE (mux->mmgr, mux->me.ptr);
|
||||
mux->me.ubound = 0;
|
||||
}
|
||||
|
||||
#elif defined(__OS2__)
|
||||
if (mux->me.ptr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < mux->me.ubound; i++)
|
||||
{
|
||||
if (mux->me.ptr[i])
|
||||
QSE_MMGR_FREE (mux->mmgr, mux->me.ptr[i]);
|
||||
}
|
||||
|
||||
QSE_MMGR_FREE (mux->mmgr, mux->me.ptr);
|
||||
mux->me.ubound = 0;
|
||||
}
|
||||
|
||||
if (mux->fdarr) QSE_MMGR_FREE (mux->mmgr, mux->fdarr);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -373,54 +385,7 @@ qse_mux_errnum_t qse_mux_geterrnum (qse_mux_t* mux)
|
||||
|
||||
int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
{
|
||||
#if defined(__OS2__)
|
||||
|
||||
if (evt->hnd >= mux->me.ubound)
|
||||
{
|
||||
qse_mux_evt_t** tmp;
|
||||
int* fatmp;
|
||||
int ubound;
|
||||
|
||||
ubound = evt->hnd + 1;
|
||||
ubound = ALIGN_TO (ubound, 128);
|
||||
|
||||
tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
mux->errnum = QSE_MUX_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* maintain this array double the size of the highest handle + 1 */
|
||||
fatmp = QSE_MMGR_REALLOC (mux->mmgr, mux->fdarr, QSE_SIZEOF(*mux->fdarr) * (ubound * 2));
|
||||
if (fatmp == QSE_NULL)
|
||||
{
|
||||
QSE_MMGR_FREE (mux->mmgr, tmp);
|
||||
mux->errnum = QSE_MUX_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
QSE_MEMSET (&tmp[mux->me.ubound], 0, QSE_SIZEOF(*mux->me.ptr) * (ubound - mux->me.ubound));
|
||||
mux->me.ptr = tmp;
|
||||
mux->me.ubound = ubound;
|
||||
mux->fdarr = fatmp;
|
||||
}
|
||||
|
||||
if (!mux->me.ptr[evt->hnd])
|
||||
{
|
||||
mux->me.ptr[evt->hnd] = QSE_MMGR_ALLOC (mux->mmgr, QSE_SIZEOF(*evt));
|
||||
if (!mux->me.ptr[evt->hnd])
|
||||
{
|
||||
mux->errnum = QSE_MUX_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
*mux->me.ptr[evt->hnd] = *evt;
|
||||
mux->size++;
|
||||
return 0;
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
#if defined(USE_SELECT)
|
||||
|
||||
/* TODO: windows seems to return a pretty high file descriptors
|
||||
* using an array to store information may not be so effcient.
|
||||
@ -540,6 +505,54 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
mux->ee.len++;
|
||||
return 0;
|
||||
|
||||
#elif defined(__OS2__)
|
||||
|
||||
if (evt->hnd >= mux->me.ubound)
|
||||
{
|
||||
qse_mux_evt_t** tmp;
|
||||
int* fatmp;
|
||||
int ubound;
|
||||
|
||||
ubound = evt->hnd + 1;
|
||||
ubound = ALIGN_TO (ubound, 128);
|
||||
|
||||
tmp = QSE_MMGR_REALLOC (mux->mmgr, mux->me.ptr, QSE_SIZEOF(*mux->me.ptr) * ubound);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
mux->errnum = QSE_MUX_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* maintain this array double the size of the highest handle + 1 */
|
||||
fatmp = QSE_MMGR_REALLOC (mux->mmgr, mux->fdarr, QSE_SIZEOF(*mux->fdarr) * (ubound * 2));
|
||||
if (fatmp == QSE_NULL)
|
||||
{
|
||||
QSE_MMGR_FREE (mux->mmgr, tmp);
|
||||
mux->errnum = QSE_MUX_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
QSE_MEMSET (&tmp[mux->me.ubound], 0, QSE_SIZEOF(*mux->me.ptr) * (ubound - mux->me.ubound));
|
||||
mux->me.ptr = tmp;
|
||||
mux->me.ubound = ubound;
|
||||
mux->fdarr = fatmp;
|
||||
}
|
||||
|
||||
if (!mux->me.ptr[evt->hnd])
|
||||
{
|
||||
mux->me.ptr[evt->hnd] = QSE_MMGR_ALLOC (mux->mmgr, QSE_SIZEOF(*evt));
|
||||
if (!mux->me.ptr[evt->hnd])
|
||||
{
|
||||
mux->errnum = QSE_MUX_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
*mux->me.ptr[evt->hnd] = *evt;
|
||||
mux->size++;
|
||||
return 0;
|
||||
|
||||
|
||||
#else
|
||||
/* TODO: */
|
||||
mux->errnum = QSE_MUX_ENOIMPL;
|
||||
@ -549,30 +562,7 @@ int qse_mux_insert (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
|
||||
int qse_mux_delete (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
{
|
||||
#if defined(__OS2__)
|
||||
|
||||
qse_mux_evt_t* mevt;
|
||||
|
||||
if (mux->size <= 0 || evt->hnd < 0 || evt->hnd >= mux->me.ubound)
|
||||
{
|
||||
mux->errnum = QSE_MUX_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mevt = mux->me.ptr[evt->hnd];
|
||||
if (mevt->hnd != evt->hnd)
|
||||
{
|
||||
/* already deleted??? */
|
||||
mux->errnum = QSE_MUX_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mevt->hnd = -1;
|
||||
mevt->mask = 0;
|
||||
mux->size--;
|
||||
return 0;
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
#if defined(USE_SELECT)
|
||||
qse_mux_evt_t* mevt;
|
||||
|
||||
if (mux->size <= 0 || evt->hnd < 0 || evt->hnd >= mux->me.ubound)
|
||||
@ -632,6 +622,30 @@ done:
|
||||
|
||||
mux->ee.len--;
|
||||
return 0;
|
||||
|
||||
#elif defined(__OS2__)
|
||||
|
||||
qse_mux_evt_t* mevt;
|
||||
|
||||
if (mux->size <= 0 || evt->hnd < 0 || evt->hnd >= mux->me.ubound)
|
||||
{
|
||||
mux->errnum = QSE_MUX_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mevt = mux->me.ptr[evt->hnd];
|
||||
if (mevt->hnd != evt->hnd)
|
||||
{
|
||||
/* already deleted??? */
|
||||
mux->errnum = QSE_MUX_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mevt->hnd = -1;
|
||||
mevt->mask = 0;
|
||||
mux->size--;
|
||||
return 0;
|
||||
|
||||
|
||||
#else
|
||||
/* TODO */
|
||||
@ -642,63 +656,7 @@ done:
|
||||
|
||||
int qse_mux_poll (qse_mux_t* mux, const qse_ntime_t* tmout)
|
||||
{
|
||||
#if defined(__OS2__)
|
||||
|
||||
qse_mux_evt_t* evt;
|
||||
long tv;
|
||||
int n, i, count, rcount, wcount;
|
||||
|
||||
tv = QSE_SEC_TO_MSEC(tmout->sec) + QSE_NSEC_TO_MSEC (tmout->nsec);
|
||||
|
||||
/*
|
||||
* be aware that reconstructing this array every time is pretty
|
||||
* inefficient.
|
||||
*/
|
||||
count = 0;
|
||||
for (i = 0; i < mux->me.ubound; i++)
|
||||
{
|
||||
evt = mux->me.ptr[i];
|
||||
if (evt && (evt->mask & QSE_MUX_IN)) mux->fdarr[count++] = evt->hnd;
|
||||
}
|
||||
rcount = count;
|
||||
for (i = 0; i < mux->me.ubound; i++)
|
||||
{
|
||||
evt = mux->me.ptr[i];
|
||||
if (evt && (evt->mask & QSE_MUX_OUT)) mux->fdarr[count++] = evt->hnd;
|
||||
}
|
||||
wcount = count - rcount;
|
||||
|
||||
n = os2_select (mux->fdarr, rcount, wcount, 0, tv);
|
||||
if (n <= -1)
|
||||
{
|
||||
mux->errnum = syserr_to_errnum(sock_errno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n >= 1)
|
||||
{
|
||||
qse_mux_evt_t xevt;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (mux->fdarr[i] == -1) continue;
|
||||
|
||||
evt = mux->me.ptr[mux->fdarr[i]];
|
||||
if (!evt || evt->hnd != mux->fdarr[i]) continue;
|
||||
|
||||
xevt = *evt;
|
||||
|
||||
/* due to the way i check 'fdarr' , it can't have
|
||||
* both IN and OUT at the same time. they are
|
||||
* triggered separately */
|
||||
xevt.mask = (i < rcount)? QSE_MUX_IN: QSE_MUX_OUT;
|
||||
mux->evtfun (mux, &xevt);
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
#if defined(USE_SELECT)
|
||||
struct timeval tv;
|
||||
int n;
|
||||
|
||||
@ -782,6 +740,63 @@ int qse_mux_poll (qse_mux_t* mux, const qse_ntime_t* tmout)
|
||||
|
||||
return nfds;
|
||||
|
||||
#elif defined(__OS2__)
|
||||
|
||||
qse_mux_evt_t* evt;
|
||||
long tv;
|
||||
int n, i, count, rcount, wcount;
|
||||
|
||||
tv = QSE_SEC_TO_MSEC(tmout->sec) + QSE_NSEC_TO_MSEC (tmout->nsec);
|
||||
|
||||
/*
|
||||
* be aware that reconstructing this array every time is pretty
|
||||
* inefficient.
|
||||
*/
|
||||
count = 0;
|
||||
for (i = 0; i < mux->me.ubound; i++)
|
||||
{
|
||||
evt = mux->me.ptr[i];
|
||||
if (evt && (evt->mask & QSE_MUX_IN)) mux->fdarr[count++] = evt->hnd;
|
||||
}
|
||||
rcount = count;
|
||||
for (i = 0; i < mux->me.ubound; i++)
|
||||
{
|
||||
evt = mux->me.ptr[i];
|
||||
if (evt && (evt->mask & QSE_MUX_OUT)) mux->fdarr[count++] = evt->hnd;
|
||||
}
|
||||
wcount = count - rcount;
|
||||
|
||||
n = os2_select (mux->fdarr, rcount, wcount, 0, tv);
|
||||
if (n <= -1)
|
||||
{
|
||||
mux->errnum = syserr_to_errnum(sock_errno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n >= 1)
|
||||
{
|
||||
qse_mux_evt_t xevt;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (mux->fdarr[i] == -1) continue;
|
||||
|
||||
evt = mux->me.ptr[mux->fdarr[i]];
|
||||
if (!evt || evt->hnd != mux->fdarr[i]) continue;
|
||||
|
||||
xevt = *evt;
|
||||
|
||||
/* due to the way i check 'fdarr' , it can't have
|
||||
* both IN and OUT at the same time. they are
|
||||
* triggered separately */
|
||||
xevt.mask = (i < rcount)? QSE_MUX_IN: QSE_MUX_OUT;
|
||||
mux->evtfun (mux, &xevt);
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
|
||||
|
||||
#else
|
||||
/* TODO */
|
||||
mux->errnum = QSE_MUX_ENOIMPL;
|
||||
|
@ -31,10 +31,13 @@
|
||||
# include <types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <tcpustd.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <nerrno.h>
|
||||
# pragma library("tcpip32.lib")
|
||||
# if defined(TCPV40HDRS)
|
||||
# include <sys/select.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
#else
|
||||
|
@ -26,16 +26,19 @@
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h> /* sockaddr_in6 */
|
||||
# include <windows.h>
|
||||
# pragma library("ws2_32.lib") /* watcom */
|
||||
# pragma comment(lib,"ws2_32.lib") /* msvc and borland */
|
||||
# define USE_SELECT
|
||||
#elif defined(__OS2__)
|
||||
# include <types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <tcpustd.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <nerrno.h>
|
||||
# pragma library("tcpip32.lib")
|
||||
# if defined(TCPV40HDRS)
|
||||
# define USE_SELECT
|
||||
# include <sys/select.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: consider watt-32 */
|
||||
#else
|
||||
@ -43,6 +46,7 @@
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <sys/time.h>
|
||||
# define USE_SELECT
|
||||
#endif
|
||||
|
||||
enum
|
||||
@ -92,8 +96,10 @@ static qse_nwio_errnum_t syserr_to_errnum (int e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
#if defined(SOCENOMEM)
|
||||
case SOCENOMEM:
|
||||
return QSE_NWIO_ENOMEM;
|
||||
#endif
|
||||
|
||||
case SOCEINVAL:
|
||||
return QSE_NWIO_EINVAL;
|
||||
@ -101,11 +107,15 @@ static qse_nwio_errnum_t syserr_to_errnum (int e)
|
||||
case SOCEACCES:
|
||||
return QSE_NWIO_EACCES;
|
||||
|
||||
#if defined(SOCENOENT)
|
||||
case SOCENOENT:
|
||||
return QSE_NWIO_ENOENT;
|
||||
#endif
|
||||
|
||||
#if defined(SOCEXIST)
|
||||
case SOCEEXIST:
|
||||
return QSE_NWIO_EEXIST;
|
||||
#endif
|
||||
|
||||
case SOCEINTR:
|
||||
return QSE_NWIO_EINTR;
|
||||
@ -205,7 +215,7 @@ static int wait_for_data (qse_nwio_t* nwio, const qse_ntime_t* tmout, int what)
|
||||
{
|
||||
int xret;
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(USE_SELECT)
|
||||
fd_set fds[2];
|
||||
struct timeval tv;
|
||||
|
||||
@ -218,9 +228,19 @@ static int wait_for_data (qse_nwio_t* nwio, const qse_ntime_t* tmout, int what)
|
||||
tv.tv_usec = QSE_NSEC_TO_USEC (tmout->nsec);
|
||||
|
||||
xret = select (nwio->handle + 1, &fds[0], &fds[1], QSE_NULL, &tv);
|
||||
#if defined(_WIN32)
|
||||
if (xret == SOCKET_ERROR)
|
||||
#else
|
||||
if (xret <= -1)
|
||||
#endif
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
nwio->errnum = syserr_to_errnum (WSAGetLastError());
|
||||
#elif defined(__OS2__)
|
||||
nwio->errnum = syserr_to_errnum (sock_errno());
|
||||
#else
|
||||
nwio->errnum = syserr_to_errnum (errno);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
else if (xret == 0)
|
||||
@ -228,6 +248,8 @@ static int wait_for_data (qse_nwio_t* nwio, const qse_ntime_t* tmout, int what)
|
||||
nwio->errnum = QSE_NWIO_ETMOUT;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
#elif defined(__OS2__)
|
||||
int count[2] = { 0, 0 };
|
||||
long tmout_msecs;
|
||||
@ -246,37 +268,13 @@ static int wait_for_data (qse_nwio_t* nwio, const qse_ntime_t* tmout, int what)
|
||||
nwio->errnum = QSE_NWIO_ETMOUT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#elif defined(__DOS__)
|
||||
nwio->errnum = QSE_NWIO_ENOIMPL;
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
fd_set fds[2];
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = tmout->sec;
|
||||
tv.tv_usec = QSE_NSEC_TO_USEC (tmout->nsec);
|
||||
|
||||
FD_ZERO (&fds[0]);
|
||||
FD_ZERO (&fds[1]);
|
||||
FD_SET (nwio->handle, &fds[what]);
|
||||
|
||||
xret = select (nwio->handle + 1, &fds[0], &fds[1], QSE_NULL, &tv);
|
||||
if (xret <= -1)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (errno);
|
||||
return -1;
|
||||
}
|
||||
else if (xret == 0)
|
||||
{
|
||||
nwio->errnum = QSE_NWIO_ETMOUT;
|
||||
return -1;
|
||||
}
|
||||
nwio->errnum = QSE_NWIO_ENOIMPL;
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
qse_nwio_t* qse_nwio_open (
|
||||
@ -591,7 +589,7 @@ int qse_nwio_init (
|
||||
{
|
||||
int noblk = 1;
|
||||
|
||||
if (ioctl (nwio->handle, FIONBIO, &noblk, QSE_SIZEOF(noblk)) <= -1)
|
||||
if (ioctl (nwio->handle, FIONBIO, (void*)&noblk, QSE_SIZEOF(noblk)) <= -1)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (sock_errno());
|
||||
goto oops;
|
||||
@ -605,7 +603,7 @@ int qse_nwio_init (
|
||||
int noblk = 0;
|
||||
|
||||
if ((xret <= -1 && sock_errno() != SOCEINPROGRESS) ||
|
||||
ioctl (nwio->handle, FIONBIO, &noblk, QSE_SIZEOF(noblk)) <= -1)
|
||||
ioctl (nwio->handle, FIONBIO, (void*)&noblk, QSE_SIZEOF(noblk)) <= -1)
|
||||
{
|
||||
nwio->errnum = syserr_to_errnum (sock_errno());
|
||||
goto oops;
|
||||
|
@ -954,6 +954,7 @@ create_process:
|
||||
zero.ulLo = 0;
|
||||
zero.ulHi = 0;
|
||||
|
||||
/* TODO: selective between DosOpenL and DosOpen */
|
||||
rc = DosOpenL (
|
||||
QSE_MT("NUL"),
|
||||
&os2devnul,
|
||||
|
@ -377,7 +377,7 @@ qse_mchar_t* qse_fmthttptime (
|
||||
|
||||
/* TODO: avoid using snprintf () */
|
||||
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
|
||||
_snprintf (buf, bufsz,
|
||||
#else
|
||||
snprintf (buf, bufsz,
|
||||
|
@ -36,24 +36,25 @@
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h> /* sockaddr_in6 */
|
||||
# include <windows.h>
|
||||
# pragma library("ws2_32.lib") /* watcom */
|
||||
# pragma comment(lib,"ws2_32.lib") /* msvc and borland */
|
||||
|
||||
# define EPOCH_DIFF_YEARS (QSE_EPOCH_YEAR-QSE_EPOCH_YEAR_WIN)
|
||||
# define EPOCH_DIFF_DAYS ((qse_long_t)EPOCH_DIFF_YEARS*365+EPOCH_DIFF_YEARS/4-3)
|
||||
# define EPOCH_DIFF_SECS ((qse_long_t)EPOCH_DIFF_DAYS*24*60*60)
|
||||
|
||||
#elif defined(__OS2__)
|
||||
# define INCL_DOSERRORS
|
||||
# define INCL_DOSFILEMGR
|
||||
# include <os2.h>
|
||||
# include <types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <tcpustd.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <nerrno.h>
|
||||
# pragma library("tcpip32.lib")
|
||||
# if defined(TCPV40HDRS)
|
||||
# include <sys/select.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# define INCL_DOSERRORS
|
||||
# define INCL_DOSFILEMGR
|
||||
# include <os2.h>
|
||||
|
||||
#elif defined(__DOS__)
|
||||
/* TODO */
|
||||
@ -1013,7 +1014,7 @@ static int mux_poll (qse_httpd_t* httpd, void* vmux, const qse_ntime_t* tmout)
|
||||
|
||||
static int mux_readable (qse_httpd_t* httpd, qse_ubi_t handle, const qse_ntime_t* tmout)
|
||||
{
|
||||
#if defined(__OS2__)
|
||||
#if defined(__OS2__) && !defined(TCPV40HDRS)
|
||||
long tv;
|
||||
|
||||
tv = tmout? QSE_SECNSEC_TO_MSEC (tmout->sec, tmout->nsec): -1;
|
||||
@ -1039,7 +1040,7 @@ static int mux_readable (qse_httpd_t* httpd, qse_ubi_t handle, const qse_ntime_t
|
||||
|
||||
static int mux_writable (qse_httpd_t* httpd, qse_ubi_t handle, const qse_ntime_t* tmout)
|
||||
{
|
||||
#if defined(__OS2__)
|
||||
#if defined(__OS2__) && !defined(TCPV40HDRS)
|
||||
long tv;
|
||||
tv = tmout? QSE_SECNSEC_TO_MSEC (tmout->sec, tmout->nsec): -1;
|
||||
return os2_select (&handle.i, 0, 1, 0, tv);
|
||||
|
@ -87,7 +87,7 @@ struct qse_httpd_t
|
||||
#define CLIENT_TASK_TRIGGER_IN_MUX(i) (1 << ((i) + 8))
|
||||
|
||||
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user