Skip to content

Commit

Permalink
libxipc: More exception removal and breakage cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
greearb committed Sep 8, 2017
1 parent 5c32e35 commit 94a17b5
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 76 deletions.
8 changes: 2 additions & 6 deletions xorp/cli/tests/test_cli.cc
Expand Up @@ -134,12 +134,8 @@ cli_main(const string& finder_hostname, uint16_t finder_port,
//
FinderServer *finder = NULL;
if (start_finder) {
try {
finder = new FinderServer(eventloop, IPv4(finder_hostname.c_str()),
finder_port);
} catch (const InvalidPort&) {
XLOG_FATAL("Could not start in-process Finder");
}
finder = new FinderServer(eventloop, IPv4(finder_hostname.c_str()),
finder_port);
}

//
Expand Down
13 changes: 6 additions & 7 deletions xorp/libfeaclient/tests/test_remote_copy.cc
Expand Up @@ -296,13 +296,12 @@ test_main()
EventLoop e;
ref_ptr<FinderServer> fs = 0;
for (uint16_t port = 32000; port < 32500; port++) {
try {
fs = new FinderServer(e, FinderConstants::FINDER_DEFAULT_HOST(),
port);
goto ___got_finder;
} catch (const InvalidPort&) {
continue;
}
/* This will proabbly break sometimes due to asserts when port is used,
* due to the exception-removal logic. Can fix later if we care.
* --Ben */
fs = new FinderServer(e, FinderConstants::FINDER_DEFAULT_HOST(),
port);
goto ___got_finder;
}
verbose_log("Could not instantiate FinderServer");
return -1;
Expand Down
4 changes: 0 additions & 4 deletions xorp/libxipc/finder_main.cc
Expand Up @@ -191,10 +191,6 @@ finder_main(int argc, char* const argv[])
while (xorp_do_run) {
e.run();
}
} catch (const InvalidPort& i) {
XLOG_ERROR("%s: a finder may already be running.\n",
i.why().c_str());
exit(-1);
} catch (...) {
xorp_catch_standard_exceptions();
}
Expand Down
2 changes: 0 additions & 2 deletions xorp/libxipc/finder_server.cc
Expand Up @@ -27,7 +27,6 @@
FinderServer::FinderServer(EventLoop& e,
IPv4 default_interface,
uint16_t default_port)
throw (InvalidPort)
: _e(e), _f(e), _fxt(_f)
{
char* value;
Expand Down Expand Up @@ -90,7 +89,6 @@ FinderServer::~FinderServer()

bool
FinderServer::add_binding(IPv4 addr, uint16_t port)
throw (InvalidPort)
{
Listeners::const_iterator i = _listeners.begin();
while (i != _listeners.end()) {
Expand Down
6 changes: 2 additions & 4 deletions xorp/libxipc/finder_server.hh
Expand Up @@ -49,8 +49,7 @@ public:
/**
* Constructor
*/
FinderServer(EventLoop& e, IPv4 default_interface, uint16_t default_port)
throw (InvalidPort);
FinderServer(EventLoop& e, IPv4 default_interface, uint16_t default_port);

/**
* Destructor
Expand All @@ -63,8 +62,7 @@ public:
* @return true on success, false if binding already exists or cannot be
* instantiated.
*/
bool add_binding(IPv4 addr, uint16_t port)
throw (InvalidPort);
bool add_binding(IPv4 addr, uint16_t port);

/**
* Remove an interface binding that was added by calling add_binding.
Expand Down
5 changes: 2 additions & 3 deletions xorp/libxipc/finder_tcp.cc
Expand Up @@ -288,7 +288,6 @@ FinderTcpListenerBase::FinderTcpListenerBase(EventLoop& e,
IPv4 interface,
uint16_t port,
bool en)
throw (InvalidPort)
: _e(e), _en(false), _addr(interface), _port(port)
{
comm_init();
Expand All @@ -302,10 +301,10 @@ FinderTcpListenerBase::FinderTcpListenerBase(EventLoop& e,

_lsock = comm_bind_tcp4(&if_ia, htons(port), COMM_SOCK_NONBLOCKING);
if (!_lsock.is_valid()) {
xorp_throw(InvalidPort, comm_get_last_error_str());
XLOG_FATAL(comm_get_last_error_str());
}
if (comm_listen(_lsock.getSocket(), COMM_LISTEN_DEFAULT_BACKLOG) != XORP_OK) {
xorp_throw(InvalidPort, comm_get_last_error_str());
XLOG_FATAL(comm_get_last_error_str());
}

if (en)
Expand Down
3 changes: 1 addition & 2 deletions xorp/libxipc/finder_tcp.hh
Expand Up @@ -137,8 +137,7 @@ public:
FinderTcpListenerBase(EventLoop& e,
IPv4 iface,
uint16_t port,
bool en = true)
throw (InvalidPort);
bool en = true);

virtual ~FinderTcpListenerBase();

Expand Down
1 change: 0 additions & 1 deletion xorp/libxipc/finder_tcp_messenger.cc
Expand Up @@ -222,7 +222,6 @@ FinderTcpListener::FinderTcpListener(EventLoop& e,
IPv4 interface,
uint16_t port,
bool en)
throw (InvalidPort)
: FinderTcpListenerBase(e, interface, port, en), _mm(mm), _cmds(cmds)
{
}
Expand Down
3 changes: 1 addition & 2 deletions xorp/libxipc/finder_tcp_messenger.hh
Expand Up @@ -92,8 +92,7 @@ public:
XrlCmdMap& cmds,
IPv4 iface,
uint16_t port,
bool enabled = true)
throw (InvalidPort);
bool enabled = true);

virtual ~FinderTcpListener();

Expand Down
1 change: 0 additions & 1 deletion xorp/libxipc/tests/test_finder_tcp.cc
Expand Up @@ -121,7 +121,6 @@ class DummyFinder : public FinderTcpListenerBase {
DummyFinder(EventLoop& e,
IPv4 interface,
uint16_t port = FinderConstants::FINDER_DEFAULT_PORT())
throw (InvalidPort)
: FinderTcpListenerBase(e, interface, port), _connection(0)
{
add_permitted_host(interface);
Expand Down
6 changes: 3 additions & 3 deletions xorp/libxipc/xrl_args.cc
Expand Up @@ -256,7 +256,7 @@ XrlArgs::add_ipvx(const char* name, const IPvX& val)
}

const IPvX
XrlArgs::get_ipvx(const char* name) const;
XrlArgs::get_ipvx(const char* name) const
{
XrlAtom a(name, xrlatom_ipv4);
if (a.invalid()) {
Expand All @@ -265,7 +265,7 @@ XrlArgs::get_ipvx(const char* name) const;
return get(b).ipv6();
}
else {
return get(a).ipv4;
return get(a).ipv4();
}
}

Expand Down Expand Up @@ -297,7 +297,7 @@ XrlArgs::get_ipvxnet(const char* name) const
return get(b).ipv6net();
}
else {
return get(a).ipv4net;
return get(a).ipv4net();
}
}

Expand Down
7 changes: 3 additions & 4 deletions xorp/libxipc/xrl_atom.cc
Expand Up @@ -162,7 +162,7 @@ XrlAtom::data_from_c_str(const char* c_str)
ssize_t bad_pos = xrlatom_decode_value(c_str, strlen(c_str), decoded);
if (bad_pos >= 0) {
_invalid = true;
return -1;
return;
}
c_str = decoded.c_str();
_have_data = true;
Expand Down Expand Up @@ -232,7 +232,6 @@ XrlAtom::data_from_c_str(const char* c_str)

// ... Your types instantiator here ...
}
return -1;
}

XrlAtom::~XrlAtom()
Expand All @@ -253,7 +252,7 @@ XrlAtom::type_and_data_okay(const XrlAtomType& t) const {
}

const bool&
XrlAtom::boolean() const;
XrlAtom::boolean() const
{
XLOG_ASSERT(type_and_data_okay(xrlatom_boolean));
return _boolean;
Expand Down Expand Up @@ -511,7 +510,7 @@ XrlAtom::XrlAtom(const char* serialized)
: _type(xrlatom_no_type),
_have_data(false),
_own(true),
_has_fake_args(false),
_has_fake_args(false)
{

const char *start, *sep;
Expand Down
7 changes: 3 additions & 4 deletions xorp/libxipc/xrl_atom_list.cc
Expand Up @@ -49,7 +49,7 @@ XrlAtomList::append(const XrlAtom& xa)
do_append(xa);
}

int
bool
XrlAtomList::check_type(const XrlAtom& xa)
{
if (_list.empty() == false && _list.front().type() != xa.type()) {
Expand Down Expand Up @@ -85,9 +85,8 @@ XrlAtomList::get(size_t itemno) const
return *ci;

error:
XtrlAtom bad;
bad.set_invalid(true);
return bad;
XrlAtom.set_invalid(true);
return XrlAtom::bad_atom;
}

void
Expand Down
7 changes: 0 additions & 7 deletions xorp/libxorp/exceptions.cc
Expand Up @@ -72,13 +72,6 @@ XorpReasonedException::why() const
return ( _why.size() != 0 ) ? _why : string("Not specified");
}

InvalidPort::InvalidPort(const char* file,
size_t line,
const string& init_why)
: XorpReasonedException("InvalidPort", file, line, init_why)
{
}

InvalidBufferOffset::InvalidBufferOffset(const char* file,
size_t line,
const string& init_why)
Expand Down
8 changes: 0 additions & 8 deletions xorp/libxorp/exceptions.hh
Expand Up @@ -134,14 +134,6 @@ protected:
// ----------------------------------------------------------------------------
// Standard XORP exceptions

/**
* @short A standard XORP exception that is thrown if a port is invalid.
*/
class InvalidPort : public XorpReasonedException {
public:
InvalidPort(const char* file, size_t line, const string& init_why = "");
};

/**
* @short A standard XORP exception that is thrown if a buffer ofset is
* invalid.
Expand Down
27 changes: 9 additions & 18 deletions xorp/rtrmgr/main_rtrmgr.cc
Expand Up @@ -283,25 +283,16 @@ Rtrmgr::run()
// deletion order.
//
FinderServer* fs = NULL;
try {
fs = new FinderServer(eventloop,
FinderConstants::FINDER_DEFAULT_HOST(),
_bind_port);
while (_bind_addrs.empty() == false) {
if (fs->add_binding(_bind_addrs.front(), _bind_port) == false) {
XLOG_WARNING("Finder failed to bind interface %s port %d",
_bind_addrs.front().str().c_str(), _bind_port);
}
_bind_addrs.pop_front();

fs = new FinderServer(eventloop,
FinderConstants::FINDER_DEFAULT_HOST(),
_bind_port);
while (_bind_addrs.empty() == false) {
if (fs->add_binding(_bind_addrs.front(), _bind_port) == false) {
XLOG_WARNING("Finder failed to bind interface %s port %d",
_bind_addrs.front().str().c_str(), _bind_port);
}
} catch (const InvalidPort& i) {
XLOG_ERROR("%s: a finder may already be running.", i.why().c_str());
delete tt;
return (1);
} catch (...) {
xorp_catch_standard_exceptions();
delete tt;
return (1);
_bind_addrs.pop_front();
}

//
Expand Down

0 comments on commit 94a17b5

Please sign in to comment.