renamed ErrorCode to ErrorNumber wherever possible
substituted this->getMmgr()->reallocate() and this->getMmgr()->dispose() for QSE_MMGR_REALLOC() and QSE_MMGR_FREE() in TcpServer.cpp
This commit is contained in:
parent
b12e3f4016
commit
3f8838afd3
@ -223,9 +223,9 @@ public:
|
||||
|
||||
|
||||
/** defines common error codes */
|
||||
enum ErrorCode
|
||||
enum ErrorNumber
|
||||
{
|
||||
/* [NOTE] if you change items here, you must change the stock error description in ErrorGrab */
|
||||
/* [NOTE] if you change items here, you must change the stock error description in TypesErrorNumberToStr::operator() */
|
||||
|
||||
E_ENOERR, /**< no error */
|
||||
E_EOTHER, /**< other error */
|
||||
|
@ -33,17 +33,17 @@
|
||||
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
|
||||
template <typename ERRCODE, typename ERRCODETOSTR, int MSGSZ>
|
||||
template <typename ERRNUM, typename ERRNUMTOSTR, int MSGSZ>
|
||||
class QSE_EXPORT ErrorGrab
|
||||
{
|
||||
public:
|
||||
ErrorGrab(): _errcode((ERRCODE)0)
|
||||
ErrorGrab(): _errnum((ERRNUM)0)
|
||||
{
|
||||
this->_errmsg[0] = QSE_T('\0');
|
||||
this->_errmsg_backup[0] = QSE_T('\0');
|
||||
}
|
||||
|
||||
ERRCODE getErrorCode () const QSE_CPP_NOEXCEPT { return this->_errcode; }
|
||||
ERRNUM getErrorNumber () const QSE_CPP_NOEXCEPT { return this->_errnum; }
|
||||
|
||||
const qse_char_t* getErrorMsg () const QSE_CPP_NOEXCEPT { return this->_errmsg; }
|
||||
const qse_char_t* backupErrorMsg () QSE_CPP_NOEXCEPT
|
||||
@ -52,41 +52,41 @@ public:
|
||||
return this->_errmsg_backup;
|
||||
}
|
||||
|
||||
void setErrorFmtv (ERRCODE errcode, const qse_char_t* fmt, va_list ap) QSE_CPP_NOEXCEPT
|
||||
void setErrorFmtv (ERRNUM errnum, const qse_char_t* fmt, va_list ap) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
this->_errcode = errcode;
|
||||
this->_errnum = errnum;
|
||||
qse_strxvfmt (this->_errmsg, QSE_COUNTOF(this->_errmsg), fmt, ap);
|
||||
}
|
||||
|
||||
void setErrorFmt (ERRCODE errcode, const qse_char_t* fmt, ...) QSE_CPP_NOEXCEPT
|
||||
void setErrorFmt (ERRNUM errnum, const qse_char_t* fmt, ...) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
this->setErrorFmtv (errcode, fmt, ap);
|
||||
this->setErrorFmtv (errnum, fmt, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
void setErrorCode (ERRCODE errcode)
|
||||
void setErrorNumber (ERRNUM errnum)
|
||||
{
|
||||
this->_errcode = errcode;
|
||||
qse_strxcpy (this->_errmsg, QSE_COUNTOF(this->_errmsg), this->_errtostr(errcode));
|
||||
this->_errnum = errnum;
|
||||
qse_strxcpy (this->_errmsg, QSE_COUNTOF(this->_errmsg), this->_errtostr(errnum));
|
||||
}
|
||||
|
||||
private:
|
||||
ERRCODE _errcode;
|
||||
ERRCODETOSTR _errtostr;
|
||||
ERRNUM _errnum;
|
||||
ERRNUMTOSTR _errtostr;
|
||||
qse_char_t _errmsg_backup[MSGSZ];
|
||||
qse_char_t _errmsg[MSGSZ];
|
||||
};
|
||||
|
||||
// the stock functor class to convert the Types::ErrorCode to a string
|
||||
struct TypesErrorCodeToStr
|
||||
// the stock functor class to convert the Types::ErrorNumber to a string
|
||||
struct TypesErrorNumberToStr
|
||||
{
|
||||
const qse_char_t* operator() (Types::ErrorCode errcode);
|
||||
const qse_char_t* operator() (Types::ErrorNumber errnum);
|
||||
};
|
||||
|
||||
typedef ErrorGrab<Types::ErrorCode, TypesErrorCodeToStr, 128> ErrorGrab128;
|
||||
typedef ErrorGrab<Types::ErrorCode, TypesErrorCodeToStr, 256> ErrorGrab256;
|
||||
typedef ErrorGrab<Types::ErrorNumber, TypesErrorNumberToStr, 128> ErrorGrab128;
|
||||
typedef ErrorGrab<Types::ErrorNumber, TypesErrorNumberToStr, 256> ErrorGrab256;
|
||||
|
||||
QSE_END_NAMESPACE(QSE)
|
||||
|
||||
|
@ -50,8 +50,8 @@ public:
|
||||
Socket () QSE_CPP_NOEXCEPT;
|
||||
virtual ~Socket () QSE_CPP_NOEXCEPT;
|
||||
|
||||
ErrorCode getErrorCode () const QSE_CPP_NOEXCEPT { return this->errcode; }
|
||||
void setErrorCode (ErrorCode errcode) QSE_CPP_NOEXCEPT { this->errcode = errcode; }
|
||||
ErrorNumber getErrorNumber () const QSE_CPP_NOEXCEPT { return this->errcode; }
|
||||
void setErrorNumber (ErrorNumber errcode) QSE_CPP_NOEXCEPT { this->errcode = errcode; }
|
||||
|
||||
int open (int domain, int type, int protocol, int traits = 0) QSE_CPP_NOEXCEPT;
|
||||
void close () QSE_CPP_NOEXCEPT;
|
||||
@ -161,7 +161,7 @@ public:
|
||||
protected:
|
||||
qse_sck_hnd_t handle;
|
||||
int domain;
|
||||
ErrorCode errcode;
|
||||
ErrorNumber errcode;
|
||||
|
||||
void set_errcode_with_syserr (int syserr);
|
||||
int get_ifce_index (const void* name, qse_size_t len, bool wchar);
|
||||
|
@ -355,7 +355,7 @@ public:
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
this->setErrorCode (E_ENOMEM);
|
||||
this->setErrorNumber (E_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -390,7 +390,7 @@ private:
|
||||
{
|
||||
if (!this->__lfunc)
|
||||
{
|
||||
//this->setErrorCode (TcpServer::E_ENOMEM or E_EINVAL??);
|
||||
//this->setErrorNumber (TcpServer::E_ENOMEM or E_EINVAL??);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ QSE_BEGIN_NAMESPACE(QSE)
|
||||
class Sttp: public Mmged, public Uncopyable
|
||||
{
|
||||
public:
|
||||
enum ErrorCode
|
||||
enum ErrorNumber
|
||||
{
|
||||
E_NOERR = 0,
|
||||
E_MEMORY,
|
||||
@ -53,8 +53,7 @@ public:
|
||||
E_SEMICOLON,
|
||||
E_TOOMANYARGS,
|
||||
E_WRONGARG,
|
||||
E_WRONGCHAR,
|
||||
__NERRCODES__
|
||||
E_WRONGCHAR
|
||||
};
|
||||
|
||||
Sttp (Transmittable* s = QSE_NULL, Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT;
|
||||
@ -89,7 +88,7 @@ public:
|
||||
this->opt_send_newline = opt;
|
||||
}
|
||||
|
||||
int getErrorCode() const QSE_CPP_NOEXCEPT
|
||||
int getErrorNumber() const QSE_CPP_NOEXCEPT
|
||||
{
|
||||
return this->p_errcode;
|
||||
}
|
||||
@ -105,8 +104,8 @@ public:
|
||||
// Socket sck;
|
||||
// Sttp sttp(sck);
|
||||
// if (sttp->receiveCmd(&cmd) <= -1 &&
|
||||
// sttp->getErrorCode() == Sttp::E_RECEIVE &&
|
||||
// sck->getErrorCode() == Socket::E_EAGAIN) { ... }
|
||||
// sttp->getErrorNumber() == Sttp::E_RECEIVE &&
|
||||
// sck->getErrorNumber() == Socket::E_EAGAIN) { ... }
|
||||
// \endcode
|
||||
//
|
||||
// \return 1 if a command is received. 0 if end of input is detected
|
||||
@ -120,7 +119,7 @@ public:
|
||||
|
||||
const qse_char_t* getErrorStr () const QSE_CPP_NOEXCEPT;
|
||||
|
||||
void setErrorCode (int code) QSE_CPP_NOEXCEPT
|
||||
void setErrorNumber (int code) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
this->p_errcode = code;
|
||||
}
|
||||
@ -145,7 +144,7 @@ protected:
|
||||
};
|
||||
|
||||
Transmittable* p_medium;
|
||||
int p_errcode; /* ErrorCode */
|
||||
int p_errcode; /* ErrorNumber */
|
||||
|
||||
qse_mchar_t inbuf [MAX_INBUF_LEN];
|
||||
qse_mchar_t outbuf[MAX_OUTBUF_LEN];
|
||||
|
61
qse/lib/cmn/ErrorGrab.cpp
Normal file
61
qse/lib/cmn/ErrorGrab.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <qse/cmn/ErrorGrab.hpp>
|
||||
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
|
||||
static const qse_char_t* _errstr[] =
|
||||
{
|
||||
QSE_T("no error"),
|
||||
QSE_T("other error"),
|
||||
QSE_T("not implemented"),
|
||||
QSE_T("subsystem error"),
|
||||
QSE_T("internal error"),
|
||||
|
||||
QSE_T("insufficient memory"),
|
||||
QSE_T("wrong number of arguments"),
|
||||
QSE_T("invalid parameter or data"),
|
||||
QSE_T("access denied"),
|
||||
QSE_T("operation not allowed"),
|
||||
|
||||
QSE_T("data not found"),
|
||||
QSE_T("existing data"),
|
||||
QSE_T("not directory"),
|
||||
QSE_T("interrupted"),
|
||||
QSE_T("pipe error"),
|
||||
|
||||
QSE_T("in progress"),
|
||||
QSE_T("resource unavailable"),
|
||||
QSE_T("exception")
|
||||
};
|
||||
|
||||
const qse_char_t* TypesErrorNumberToStr::operator() (Types::ErrorNumber errnum)
|
||||
{
|
||||
return errnum >= QSE_COUNTOF(_errstr)? QSE_T("unknown error"): _errstr[errnum];
|
||||
}
|
||||
|
||||
QSE_END_NAMESPACE(QSE)
|
@ -54,7 +54,7 @@ QSE_BEGIN_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
#include "../cmn/syserr.h"
|
||||
IMPLEMENT_SYSERR_TO_ERRNUM (Socket::ErrorCode, Socket::)
|
||||
IMPLEMENT_SYSERR_TO_ERRNUM (Socket::ErrorNumber, Socket::)
|
||||
|
||||
Socket::Socket () QSE_CPP_NOEXCEPT: handle(QSE_INVALID_SCKHND), domain(-1), errcode(E_ENOERR)
|
||||
{
|
||||
@ -92,7 +92,7 @@ open_socket:
|
||||
goto open_socket;
|
||||
}
|
||||
#endif
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
@ -108,7 +108,7 @@ open_socket:
|
||||
if (fcntl_v == -1)
|
||||
{
|
||||
fcntl_failure:
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
::close (x);
|
||||
return -1;
|
||||
}
|
||||
@ -157,7 +157,7 @@ int Socket::getSockName (SocketAddress& addr) QSE_CPP_NOEXCEPT
|
||||
QSE_ASSERT (qse_is_sck_valid(this->handle));
|
||||
qse_sck_len_t len = addr.getAddrCapa();
|
||||
int n = ::getsockname(this->handle, (struct sockaddr*)addr.getAddrPtr(), &len);
|
||||
if (n == -1) this->setErrorCode (syserr_to_errnum(errno));
|
||||
if (n == -1) this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ int Socket::getPeerName (SocketAddress& addr) QSE_CPP_NOEXCEPT
|
||||
QSE_ASSERT (qse_is_sck_valid(this->handle));
|
||||
qse_sck_len_t len = addr.getAddrCapa();
|
||||
int n = ::getpeername(this->handle, (struct sockaddr*)addr.getAddrPtr(), &len);
|
||||
if (n == -1) this->setErrorCode (syserr_to_errnum(errno));
|
||||
if (n == -1) this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ int Socket::getOption (int level, int optname, void* optval, qse_sck_len_t* optl
|
||||
{
|
||||
QSE_ASSERT (qse_is_sck_valid(this->handle));
|
||||
int n = ::getsockopt(this->handle, level, optname, (char*)optval, optlen);
|
||||
if (n == -1) this->setErrorCode (syserr_to_errnum(errno));
|
||||
if (n == -1) this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ int Socket::setOption (int level, int optname, const void* optval, qse_sck_len_t
|
||||
{
|
||||
QSE_ASSERT (qse_is_sck_valid(this->handle));
|
||||
int n = ::setsockopt(this->handle, level, optname, (const char*)optval, optlen);
|
||||
if (n == -1) this->setErrorCode (syserr_to_errnum(errno));
|
||||
if (n == -1) this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ int Socket::setReusePort (int n) QSE_CPP_NOEXCEPT
|
||||
#if defined(SO_REUSEPORT)
|
||||
return this->setOption (SOL_SOCKET, SO_REUSEPORT, (char*)&n, QSE_SIZEOF(n));
|
||||
#else
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -260,7 +260,7 @@ int Socket::setTcpNodelay (int n) QSE_CPP_NOEXCEPT
|
||||
#if defined(TCP_NODELAY)
|
||||
return this->setOption (IPPROTO_TCP, TCP_NODELAY, (char*)&n, QSE_SIZEOF(n));
|
||||
#else
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -270,7 +270,7 @@ int Socket::setOobInline (int n) QSE_CPP_NOEXCEPT
|
||||
#if defined(SO_OOBINLINE)
|
||||
return this->setOption (SOL_SOCKET, SO_OOBINLINE, (char*)&n, QSE_SIZEOF(n));
|
||||
#else
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -280,7 +280,7 @@ int Socket::setIpv6Only (int n) QSE_CPP_NOEXCEPT
|
||||
#if defined(IPV6_V6ONLY)
|
||||
return this->setOption (IPPROTO_IPV6, IPV6_V6ONLY, (char*)&n, QSE_SIZEOF(n));
|
||||
#else
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -292,7 +292,7 @@ int Socket::shutdown (int how) QSE_CPP_NOEXCEPT
|
||||
// i put this guard to allow multiple calls to shutdown().
|
||||
if (::shutdown(this->handle, how) == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -306,7 +306,7 @@ int Socket::connect (const SocketAddress& target) QSE_CPP_NOEXCEPT
|
||||
|
||||
if (::connect(this->handle, (struct sockaddr*)target.getAddrPtr(), target.getAddrSize()) == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -319,7 +319,7 @@ int Socket::bind (const SocketAddress& target) QSE_CPP_NOEXCEPT
|
||||
|
||||
if (::bind(this->handle, (struct sockaddr*)target.getAddrPtr(), target.getAddrSize()) == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -354,13 +354,13 @@ int Socket::bindToIfce (const qse_mchar_t* ifce) QSE_CPP_NOEXCEPT
|
||||
qse_size_t mlen = qse_mbsxcpy (ifr.ifr_name, QSE_COUNTOF(ifr.ifr_name), ifce);
|
||||
if (ifce[mlen] != QSE_MT('\0'))
|
||||
{
|
||||
this->setErrorCode (E_EINVAL);
|
||||
this->setErrorNumber (E_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
return this->setOption (SOL_SOCKET, SO_BINDTODEVICE, (char*)&ifr, QSE_SIZEOF(ifr));
|
||||
}
|
||||
#else
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -380,13 +380,13 @@ int Socket::bindToIfce (const qse_wchar_t* ifce) QSE_CPP_NOEXCEPT
|
||||
qse_size_t wlen, mlen = QSE_COUNTOF(ifr.ifr_name);
|
||||
if (qse_wcstombs(ifce, &wlen, ifr.ifr_name, &mlen) <= -1 || ifce[wlen] != QSE_WT('\0'))
|
||||
{
|
||||
this->setErrorCode (E_EINVAL);
|
||||
this->setErrorNumber (E_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
return this->setOption (SOL_SOCKET, SO_BINDTODEVICE, (char*)&ifr, QSE_SIZEOF(ifr));
|
||||
}
|
||||
#else
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -397,7 +397,7 @@ int Socket::listen (int backlog) QSE_CPP_NOEXCEPT
|
||||
|
||||
if (::listen(this->handle, backlog) == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -423,7 +423,7 @@ int Socket::accept (Socket* newsck, SocketAddress* newaddr, int traits) QSE_CPP_
|
||||
{
|
||||
if (errno != ENOSYS)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -439,7 +439,7 @@ int Socket::accept (Socket* newsck, SocketAddress* newaddr, int traits) QSE_CPP_
|
||||
newfd = ::accept(this->handle, (struct sockaddr*)newaddr->getAddrPtr(), &addrlen);
|
||||
if (newfd == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -449,7 +449,7 @@ int Socket::accept (Socket* newsck, SocketAddress* newaddr, int traits) QSE_CPP_
|
||||
if (flag_v == -1)
|
||||
{
|
||||
fcntl_failure:
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
::close (newfd);
|
||||
return -1;
|
||||
}
|
||||
@ -479,7 +479,7 @@ qse_ssize_t Socket::send (const void* buf, qse_size_t len) QSE_CPP_NOEXCEPT
|
||||
qse_ssize_t n = ::send(this->handle, buf, len, 0);
|
||||
if (n == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -493,7 +493,7 @@ qse_ssize_t Socket::send (const void* buf, qse_size_t len, const SocketAddress&
|
||||
qse_ssize_t n = ::sendto(this->handle, buf, len, 0, (struct sockaddr*)dstaddr.getAddrPtr(), dstaddr.getAddrSize());
|
||||
if (n == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -529,14 +529,14 @@ qse_ssize_t Socket::send (const qse_ioptl_t* iov, int count) QSE_CPP_NOEXCEPT
|
||||
#endif
|
||||
if (nwritten <= -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return nwritten;
|
||||
#else
|
||||
// TODO: combine to a single buffer .... use sendto....
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -557,14 +557,14 @@ qse_ssize_t Socket::send (const qse_ioptl_t* iov, int count, const SocketAddress
|
||||
nwritten = ::sendmsg(this->handle, &msg, 0);
|
||||
if (nwritten <= -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return nwritten;
|
||||
#else
|
||||
// TODO: combine to a single buffer .... use sendto....
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -617,7 +617,7 @@ qse_ssize_t Socket::send (const qse_ioptl_t* iov, int count, const SocketAddress
|
||||
struct in_addr* pi = (struct in_addr*)CMSG_DATA(cmsg);
|
||||
*pi = *(struct in_addr*)srcaddr.getIp6addr();
|
||||
#else
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -647,14 +647,14 @@ qse_ssize_t Socket::send (const qse_ioptl_t* iov, int count, const SocketAddress
|
||||
nwritten = ::sendmsg(this->handle, &msg, 0);
|
||||
if (nwritten <= -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return nwritten;
|
||||
#else
|
||||
// TODO: combine to a single buffer .... use sendto....
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
@ -671,7 +671,7 @@ int Socket::sendx (const void* buf, qse_size_t len, qse_size_t* total_sent) QSE_
|
||||
qse_ssize_t n = ::send(this->handle, (char*)buf + pos, len - pos, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
if (total_sent) *total_sent = pos;
|
||||
return -1;
|
||||
}
|
||||
@ -694,7 +694,7 @@ int Socket::sendx (const void* buf, qse_size_t len, const SocketAddress& dstaddr
|
||||
qse_ssize_t n = ::sendto(this->handle, (char*)buf + pos, len - pos, 0, (struct sockaddr*)dstaddr.getAddrPtr(), dstaddr.getAddrSize());
|
||||
if (n == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
if (total_sent) *total_sent = pos;
|
||||
return -1;
|
||||
}
|
||||
@ -734,7 +734,7 @@ int Socket::sendx (qse_ioptl_t* iov, int count, qse_size_t* total_sent) QSE_CPP_
|
||||
#endif
|
||||
if (nwritten <= -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
if (backup_index >= 0) iov[backup_index] = backup;
|
||||
if (total_sent) *total_sent = total;
|
||||
return -1;
|
||||
@ -784,7 +784,7 @@ int Socket::sendx (qse_ioptl_t* iov, int count, qse_size_t* total_sent) QSE_CPP_
|
||||
nwritten = ::send(this->handle, (qse_uint8_t*)v->ptr + pos, rem, 0);
|
||||
if (nwritten <= -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
if (total_sent) *total_sent = total;
|
||||
return -1;
|
||||
}
|
||||
@ -829,7 +829,7 @@ int Socket::sendx (qse_ioptl_t* iov, int count, const SocketAddress& dstaddr, qs
|
||||
nwritten = ::sendmsg(this->handle, &msg, 0);
|
||||
if (nwritten <= -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
if (backup_index >= 0) iov[backup_index] = backup;
|
||||
if (total_sent) *total_sent = total;
|
||||
return -1;
|
||||
@ -879,7 +879,7 @@ int Socket::sendx (qse_ioptl_t* iov, int count, const SocketAddress& dstaddr, qs
|
||||
nwritten = ::sendto(this->handle, (qse_uint8_t*)v->ptr + pos, rem, 0);
|
||||
if (nwritten <= -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
if (total_sent) *total_sent = total;
|
||||
return -1;
|
||||
}
|
||||
@ -907,7 +907,7 @@ qse_ssize_t Socket::receive (void* buf, qse_size_t len) QSE_CPP_NOEXCEPT
|
||||
qse_ssize_t n = ::recv(this->handle, buf, len, 0);
|
||||
if (n == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -922,7 +922,7 @@ qse_ssize_t Socket::receive (void* buf, qse_size_t len, SocketAddress& srcaddr)
|
||||
qse_ssize_t n = ::recvfrom(this->handle, buf, len, 0, (struct sockaddr*)srcaddr.getAddrPtr(), &addrlen);
|
||||
if (n == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -935,7 +935,7 @@ int Socket::joinMulticastGroup (const SocketAddress& mcaddr, const SocketAddress
|
||||
|
||||
if (family != ifaddr.getFamily())
|
||||
{
|
||||
this->setErrorCode (E_EINVAL);
|
||||
this->setErrorNumber (E_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -967,7 +967,7 @@ int Socket::joinMulticastGroup (const SocketAddress& mcaddr, const SocketAddress
|
||||
#endif
|
||||
}
|
||||
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -977,7 +977,7 @@ int Socket::leaveMulticastGroup (const SocketAddress& mcaddr, const SocketAddres
|
||||
|
||||
if (family != ifaddr.getFamily())
|
||||
{
|
||||
this->setErrorCode (E_EINVAL);
|
||||
this->setErrorNumber (E_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1008,7 +1008,7 @@ int Socket::leaveMulticastGroup (const SocketAddress& mcaddr, const SocketAddres
|
||||
#endif
|
||||
}
|
||||
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1044,7 +1044,7 @@ int Socket::get_ifce_index (const void* name, qse_size_t len, bool wchar)
|
||||
qse_size_t wlen = len, mlen = QSE_COUNTOF(ifr.ifr_name) - 1;
|
||||
if (qse_wcsntombsn((const qse_wchar_t*)name, &wlen, ifr.ifr_name, &mlen) <= -1 || wlen != len)
|
||||
{
|
||||
this->setErrorCode (E_EINVAL);
|
||||
this->setErrorNumber (E_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
ifr.ifr_name[mlen] = QSE_MT('\0');
|
||||
@ -1054,14 +1054,14 @@ int Socket::get_ifce_index (const void* name, qse_size_t len, bool wchar)
|
||||
qse_size_t mlen = qse_mbsxncpy(ifr.ifr_name, QSE_COUNTOF(ifr.ifr_name), (const qse_mchar_t*)name, len);
|
||||
if (mlen != len)
|
||||
{
|
||||
this->setErrorCode (E_EINVAL);
|
||||
this->setErrorNumber (E_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (::ioctl(this->handle, SIOCGIFINDEX, &ifr) == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1071,7 +1071,7 @@ int Socket::get_ifce_index (const void* name, qse_size_t len, bool wchar)
|
||||
return ifr.ifr_index;
|
||||
#endif
|
||||
#else
|
||||
this->setErrorCode (E_ENOIMPL);
|
||||
this->setErrorNumber (E_ENOIMPL);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@ -1146,7 +1146,7 @@ int Socket::get_ifce_address (int cmd, const void* name, qse_size_t len, bool wc
|
||||
qse_size_t wlen = len, mlen = QSE_COUNTOF(ifr.ifr_name) - 1;
|
||||
if (qse_wcsntombsn((const qse_wchar_t*)name, &wlen, ifr.ifr_name, &mlen) <= -1 || wlen != len)
|
||||
{
|
||||
this->setErrorCode (E_EINVAL);
|
||||
this->setErrorNumber (E_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
ifr.ifr_name[mlen] = QSE_MT('\0');
|
||||
@ -1156,7 +1156,7 @@ int Socket::get_ifce_address (int cmd, const void* name, qse_size_t len, bool wc
|
||||
qse_size_t mlen = qse_mbsxncpy(ifr.ifr_name, QSE_COUNTOF(ifr.ifr_name), (const qse_mchar_t*)name, len);
|
||||
if (mlen != len)
|
||||
{
|
||||
this->setErrorCode (E_EINVAL);
|
||||
this->setErrorNumber (E_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1203,14 +1203,14 @@ int Socket::get_ifce_address (int cmd, const void* name, qse_size_t len, bool wc
|
||||
|
||||
if (::ioctl(this->handle, cmd, &ifr) == -1)
|
||||
{
|
||||
this->setErrorCode (syserr_to_errnum(errno));
|
||||
this->setErrorNumber (syserr_to_errnum(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct sockaddr* sa = (struct sockaddr*)&ifr.ifr_addr;
|
||||
if (sa->sa_family != this->domain)
|
||||
{
|
||||
this->setErrorCode (E_ENOENT);
|
||||
this->setErrorNumber (E_ENOENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
|
||||
#include "../cmn/syserr.h"
|
||||
IMPLEMENT_SYSERR_TO_ERRNUM (TcpServer::ErrorCode, TcpServer::)
|
||||
IMPLEMENT_SYSERR_TO_ERRNUM (TcpServer::ErrorNumber, TcpServer::)
|
||||
|
||||
int TcpServer::Worker::main ()
|
||||
{
|
||||
@ -205,10 +205,10 @@ void TcpServer::dispatch_mux_event (qse_mux_t* mux, const qse_mux_evt_t* evt) QS
|
||||
|
||||
if (server->isStopRequested()) return; /* normal termination requested */
|
||||
|
||||
Socket::ErrorCode lerr = lsck->getErrorCode();
|
||||
Socket::ErrorNumber lerr = lsck->getErrorNumber();
|
||||
if (lerr == Socket::E_EINTR || lerr == Socket::E_EAGAIN) return;
|
||||
|
||||
server->setErrorCode (lerr);
|
||||
server->setErrorNumber (lerr);
|
||||
server->stop ();
|
||||
return;
|
||||
}
|
||||
@ -262,7 +262,7 @@ int TcpServer::setup_listeners (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
if (errno != 0)
|
||||
this->setErrorFmt (syserr_to_errnum(errno), QSE_T("%hs"), strerror(errno));
|
||||
else
|
||||
this->setErrorCode (E_ENOMEM);
|
||||
this->setErrorNumber (E_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
mux_xtn_t* mux_xtn = (mux_xtn_t*)qse_mux_getxtn(mux);
|
||||
@ -294,11 +294,11 @@ int TcpServer::setup_listeners (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
ev.data = QSE_NULL;
|
||||
if (qse_mux_insert(mux, &ev) <= -1)
|
||||
{
|
||||
this->setErrorCode (E_ESYSERR);
|
||||
this->setErrorNumber (E_ESYSERR);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
this->setErrorCode (E_ENOERR);
|
||||
this->setErrorNumber (E_ENOERR);
|
||||
|
||||
addr_ptr = addrs;
|
||||
while (1)
|
||||
@ -373,7 +373,7 @@ int TcpServer::setup_listeners (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
|
||||
if (!this->listener_list.head)
|
||||
{
|
||||
if (this->getErrorCode() == E_ENOERR)
|
||||
if (this->getErrorNumber() == E_ENOERR)
|
||||
{
|
||||
this->setErrorFmt (E_EINVAL, QSE_T("unable to create liteners with %js"), addrs);
|
||||
}
|
||||
@ -429,7 +429,7 @@ int TcpServer::start (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
qse_mux_errnum_t merr = qse_mux_geterrnum(this->listener_list.mux);
|
||||
if (merr != QSE_MUX_EINTR)
|
||||
{
|
||||
this->setErrorCode (E_ESYSERR); // TODO: proper error code conversion
|
||||
this->setErrorNumber (E_ESYSERR); // TODO: proper error code conversion
|
||||
xret = -1;
|
||||
break;
|
||||
}
|
||||
@ -444,7 +444,7 @@ int TcpServer::start (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
this->delete_all_workers (Worker::LIVE);
|
||||
this->delete_all_workers (Worker::DEAD);
|
||||
|
||||
this->setErrorCode (E_EEXCEPT);
|
||||
this->setErrorNumber (E_EEXCEPT);
|
||||
this->server_serving = false;
|
||||
this->setStopRequested (false);
|
||||
this->free_all_listeners ();
|
||||
@ -521,17 +521,17 @@ int TcpServer::prepare_to_acquire_wid () QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (this->wid_map.capa >= WID_MAX)
|
||||
{
|
||||
this->setErrorCode (E_ENOMEM); // TODO: proper error code
|
||||
this->setErrorNumber (E_ENOMEM); // TODO: proper error code
|
||||
return -1;
|
||||
}
|
||||
|
||||
new_capa = WID_MAX;
|
||||
}
|
||||
|
||||
tmp = (wid_map_data_t*)QSE_MMGR_REALLOC(this->getMmgr(), this->wid_map.ptr, QSE_SIZEOF(*tmp) * new_capa);
|
||||
tmp = (wid_map_data_t*)this->getMmgr()->reallocate(this->wid_map.ptr, QSE_SIZEOF(*tmp) * new_capa, false);
|
||||
if (!tmp)
|
||||
{
|
||||
this->setErrorCode (E_ENOMEM);
|
||||
this->setErrorNumber (E_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -591,7 +591,7 @@ void TcpServer::free_wid_map () QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (this->wid_map.ptr)
|
||||
{
|
||||
QSE_MMGR_FREE (this->getMmgr(), this->wid_map.ptr);
|
||||
this->getMmgr()->dispose (this->wid_map.ptr);
|
||||
this->wid_map.capa = 0;
|
||||
this->wid_map.free_first = wid_map_t::WID_INVALID;
|
||||
this->wid_map.free_last = wid_map_t::WID_INVALID;
|
||||
|
Loading…
Reference in New Issue
Block a user