Mercurial > irccd
view lib/irccd/connection.cpp @ 95:1125d90b3b44
Misc: switch to .hpp, #477
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 20 Apr 2016 19:45:00 +0200 |
parents | f8160d515a76 |
children | 9a636d4ab8a2 |
line wrap: on
line source
/* * connection.cpp -- value wrapper for connecting to irccd * * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <irccd/logger.hpp> #include "connection.hpp" namespace irccd { json::Value Connection::next(const std::string &name, int timeout) { m_timer.reset(); while (isConnected()) { json::Value object = next(clamp(timeout)); if (object.isObject() && object["response"].toString() == name) return object; } throw std::runtime_error("connection lost"); } void Connection::verify(const std::string &name, int timeout) { auto object = next(name, timeout); auto value = object.at("status").toString(); if (!value.empty() && value != "ok") throw std::runtime_error(object.at("error").toString()); } } // !irccd