added nwio timeout handler for win32

added PROCINFO handler for win32
This commit is contained in:
2012-08-01 04:00:39 +00:00
parent c7cea1d985
commit a448d6c399
41 changed files with 667 additions and 729 deletions

View File

@ -1,9 +1,9 @@
# Makefile.in generated by automake 1.11.3 from Makefile.am.
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
# Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@ -72,12 +72,6 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
@ -455,9 +449,9 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libqsecmn.la: $(libqsecmn_la_OBJECTS) $(libqsecmn_la_DEPENDENCIES) $(EXTRA_libqsecmn_la_DEPENDENCIES)
libqsecmn.la: $(libqsecmn_la_OBJECTS) $(libqsecmn_la_DEPENDENCIES)
$(libqsecmn_la_LINK) -rpath $(libdir) $(libqsecmn_la_OBJECTS) $(libqsecmn_la_LIBADD) $(LIBS)
libqsecmnxx.la: $(libqsecmnxx_la_OBJECTS) $(libqsecmnxx_la_DEPENDENCIES) $(EXTRA_libqsecmnxx_la_DEPENDENCIES)
libqsecmnxx.la: $(libqsecmnxx_la_OBJECTS) $(libqsecmnxx_la_DEPENDENCIES)
$(libqsecmnxx_la_LINK) $(am_libqsecmnxx_la_rpath) $(libqsecmnxx_la_OBJECTS) $(libqsecmnxx_la_LIBADD) $(LIBS)
mostlyclean-compile:
@ -694,15 +688,10 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:

View File

@ -55,15 +55,15 @@ static QSE_INLINE unsigned int wcsn_to_ifindex (const qse_wchar_t* ptr, qse_size
return if_nametoindex (tmp);
}
#else
staitc QSE_INLINE unsigned int mbsn_to_ifindex (const qse_mchar_t* ptr, qse_size_t len)
static QSE_INLINE unsigned int mbsn_to_ifindex (const qse_mchar_t* ptr, qse_size_t len)
{
return 0U;
}
staitc QSE_INLINE unsigned int wcsn_to_ifindex (const qse_wchar_t* ptr, qse_size_t len)
static QSE_INLINE unsigned int wcsn_to_ifindex (const qse_wchar_t* ptr, qse_size_t len)
{
return 0U;
}
#endif
#endif /* HAVE_IF_NAMETOINDEX */
#if defined(HAVE_IF_INDEXTONAME)
static QSE_INLINE int ifindex_to_mbsn (unsigned int index, qse_mchar_t* buf, qse_size_t len)
@ -96,10 +96,28 @@ static QSE_INLINE int ifindex_to_wcsn (unsigned int index, qse_wchar_t* buf, qse
{
return 0;
}
#endif
#endif /* HAVE_IF_INDEXTONAME */
#endif
#else /* HAVE_NET_IF_H */
static QSE_INLINE unsigned int mbsn_to_ifindex (const qse_mchar_t* ptr, qse_size_t len)
{
return 0U;
}
static QSE_INLINE unsigned int wcsn_to_ifindex (const qse_wchar_t* ptr, qse_size_t len)
{
return 0U;
}
static QSE_INLINE int ifindex_to_mbsn (unsigned int index, qse_mchar_t* buf, qse_size_t len)
{
return 0;
}
static QSE_INLINE int ifindex_to_wcsn (unsigned int index, qse_wchar_t* buf, qse_size_t len)
{
return 0;
}
#endif /* HAVE_NET_IF_H */
int qse_mbstonwad (const qse_mchar_t* str, qse_nwad_t* nwad)
{

View File

@ -265,12 +265,26 @@ static int wait_for_data (qse_nwio_t* nwio, int tmout, int what)
tv.tv_usec = (tmout % QSE_MSECS_PER_SEC) *
QSE_USECS_PER_MSEC;
#if defined(_WIN32)
xret = select (nwio->handle + 1, &fds[0], &fds[1], QSE_NULL, &tv);
if (xret == SOCKET_ERROR)
{
nwio->errnum = syserr_to_errnum (WSAGetLastError());
return -1;
}
#elif defined(__OS2__)
/* TODO: */
#elif defined(__DOS__)
nwio->errnum = QSE_NWIO_NOIMPL;
return -1;
#else
xret = select (nwio->handle + 1, &fds[0], &fds[1], QSE_NULL, &tv);
if (xret <= -1)
{
nwio->errnum = syserr_to_errnum (errno);
return -1;
}
#endif
else if (xret == 0)
{
nwio->errnum = QSE_NWIO_ETMOUT;
@ -388,6 +402,9 @@ int qse_nwio_init (
goto oops;
}
if (nwio->tmout.a >= 0 &&
wait_for_data (nwio, nwio->tmout.a, 0) <= -1) goto oops;
handle = accept (nwio->handle, (struct sockaddr*)&addr, &addrlen);
if (handle == INVALID_SOCKET)
{
@ -405,10 +422,60 @@ int qse_nwio_init (
}
else
{
if (connect (nwio->handle, (struct sockaddr*)&addr, addrlen) == SOCKET_ERROR)
int xret;
if (nwio->tmout.c >= 0 && (flags & QSE_NWIO_TCP))
{
nwio->errnum = syserr_to_errnum (WSAGetLastError());
goto oops;
unsigned long cmd = 1;
if (ioctlsocket(nwio->handle, FIONBIO, &cmd) == SOCKET_ERROR)
{
nwio->errnum = syserr_to_errnum (WSAGetLastError());
goto oops;
}
}
xret = connect (nwio->handle, (struct sockaddr*)&addr, addrlen);
if (nwio->tmout.c >= 0 && (flags & QSE_NWIO_TCP))
{
unsigned long cmd = 0;
int wsaerr;
wsaerr = WSAGetLastError ();
if (ioctlsocket (nwio->handle, FIONBIO, &cmd) == SOCKET_ERROR ||
(xret == SOCKET_ERROR && wsaerr != WSAEWOULDBLOCK))
{
nwio->errnum = syserr_to_errnum (wsaerr);
goto oops;
}
if (wait_for_data (nwio, nwio->tmout.c, 1) <= -1) goto oops;
else
{
int xlen;
DWORD xerr;
xlen = QSE_SIZEOF(xret);
if (getsockopt (nwio->handle, SOL_SOCKET, SO_ERROR, (char*)&xerr, &xlen) == SOCKET_ERROR)
{
nwio->errnum = syserr_to_errnum (WSAGetLastError());
goto oops;
}
else if (xerr != 0)
{
nwio->errnum = syserr_to_errnum (xerr);
goto oops;
}
}
}
else
{
if (xret == SOCKET_ERROR)
{
nwio->errnum = syserr_to_errnum (WSAGetLastError());
goto oops;
}
}
}
@ -757,6 +824,10 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
int addrlen;
addrlen = QSE_SIZEOF(addr);
if (nwio->tmout.a >= 0 &&
wait_for_data (nwio, nwio->tmout.a, 0) <= -1) return -1;
count = recvfrom (
nwio->handle, buf, size, 0,
(struct sockaddr*)&addr, &addrlen);
@ -778,6 +849,9 @@ static qse_ssize_t nwio_read (qse_nwio_t* nwio, void* buf, qse_size_t size)
}
else
{
if (nwio->tmout.r >= 0 &&
wait_for_data (nwio, nwio->tmout.r, 0) <= -1) return -1;
count = recv (nwio->handle, buf, size, 0);
if (count == SOCKET_ERROR) nwio->errnum = syserr_to_errnum (WSAGetLastError());
}
@ -938,6 +1012,9 @@ static qse_ssize_t nwio_write (qse_nwio_t* nwio, const void* data, qse_size_t si
if (size > (QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(int)))
size = QSE_TYPE_MAX(qse_ssize_t) & QSE_TYPE_MAX(int);
if (nwio->tmout.w >= 0 &&
wait_for_data (nwio, nwio->tmout.w, 1) <= -1) return -1;
count = send (nwio->handle, data, size, 0);
if (count == SOCKET_ERROR) nwio->errnum = syserr_to_errnum (WSAGetLastError());
return count;