enhanced TcpServer::setup_listeners() to ignore some whitespaces int the addresses.
added a new parameter to App::guardProcess() to let it not guard optionally
This commit is contained in:
parent
47a8cdeb11
commit
b9a8722d3b
@ -438,6 +438,17 @@ public:
|
||||
return this->_item->buffer[index];
|
||||
}
|
||||
|
||||
const CHAR_TYPE& getLastChar () const
|
||||
{
|
||||
QSE_ASSERT (this->_item->size > 0);
|
||||
return this->getCharAt(this->_item->size - 1);
|
||||
}
|
||||
|
||||
const CHAR_TYPE& getFirstChar () const
|
||||
{
|
||||
return this->getCharAt(0);
|
||||
}
|
||||
|
||||
void setCharAt (qse_size_t index, CHAR_TYPE c)
|
||||
{
|
||||
QSE_ASSERT (index < this->_item->size);
|
||||
|
@ -159,7 +159,7 @@ public:
|
||||
return this->_guarded_child_pid >= 0;
|
||||
}
|
||||
|
||||
int guardProcess (const SignalSet& signals, qse_mtime_t guard_pause_ms = 0, const qse_mchar_t* proc_name = QSE_NULL);
|
||||
int guardProcess (const SignalSet& signals, bool _guard = true, qse_mtime_t guard_pause_ms = 0, const qse_mchar_t* proc_name = QSE_NULL);
|
||||
|
||||
|
||||
// =============================================================
|
||||
|
@ -23,6 +23,7 @@
|
||||
(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 <stdio.h>
|
||||
|
||||
#include <qse/si/App.hpp>
|
||||
#include <qse/si/Mutex.hpp>
|
||||
@ -502,7 +503,7 @@ int App::neglectSignals (const SignalSet& signals, bool ignore_if_unhandled)
|
||||
return n;
|
||||
}
|
||||
|
||||
int App::guardProcess (const SignalSet& signals, qse_mtime_t guard_pause_ms, const qse_mchar_t* proc_name)
|
||||
int App::guardProcess (const SignalSet& signals, bool _guard, qse_mtime_t guard_pause_ms, const qse_mchar_t* proc_name)
|
||||
{
|
||||
SignalState old_ss[QSE_NSIGS];
|
||||
int seq = 0;
|
||||
@ -558,6 +559,7 @@ int App::guardProcess (const SignalSet& signals, qse_mtime_t guard_pause_ms, con
|
||||
{
|
||||
if (WEXITSTATUS(status) == 0)
|
||||
{
|
||||
exit_ok:
|
||||
// the child has terminated normally and successfully.
|
||||
for (int i = 0; i < QSE_NSIGS; i++)
|
||||
{
|
||||
@ -576,6 +578,8 @@ int App::guardProcess (const SignalSet& signals, qse_mtime_t guard_pause_ms, con
|
||||
::kill (-pid, SIGKILL);
|
||||
}
|
||||
|
||||
if (!_guard) goto exit_ok; // no guard;
|
||||
|
||||
if (guard_pause_ms > 0) qse_msleep (guard_pause_ms);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <qse/si/TcpServer.hpp>
|
||||
#include <qse/si/os.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/chr.h>
|
||||
#include "../cmn/mem-prv.h"
|
||||
|
||||
#include <errno.h>
|
||||
@ -259,6 +260,24 @@ void TcpServer::dispatch_mux_event (qse_mux_t* mux, const qse_mux_evt_t* evt) QS
|
||||
}
|
||||
}
|
||||
|
||||
static const qse_char_t* strip_enclosing_spaces (const qse_char_t* ptr, qse_size_t* len)
|
||||
{
|
||||
const qse_char_t* end = ptr + *len;
|
||||
while (ptr < end)
|
||||
{
|
||||
if (!QSE_ISSPACE(*ptr)) break;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
while (end > ptr)
|
||||
{
|
||||
if (!QSE_ISSPACE(end[-1])) break;
|
||||
end--;
|
||||
}
|
||||
*len = end - ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int TcpServer::setup_listeners (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
const qse_char_t* addr_ptr, * comma;
|
||||
@ -321,8 +340,8 @@ int TcpServer::setup_listeners (const qse_char_t* addrs) QSE_CPP_NOEXCEPT
|
||||
|
||||
comma = qse_strchr(addr_ptr, QSE_T(','));
|
||||
addr_len = comma? comma - addr_ptr: qse_strlen(addr_ptr);
|
||||
/* [NOTE] no whitespaces are allowed before and after a comma */
|
||||
|
||||
addr_ptr = strip_enclosing_spaces(addr_ptr, &addr_len);
|
||||
if (sockaddr.set(addr_ptr, addr_len) <= -1)
|
||||
{
|
||||
this->logfmt (QSE_LOG_ERROR, QSE_T("unrecognized listener address - %.*js\n"), (int)addr_len, addr_ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user