From 9954e8cbf9bae21f5a727f9c92e9c33dc6d8eaf1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 15 Jun 2014 11:18:19 +0300 Subject: [PATCH] Add a registered flag to Port --- source/port.cpp | 10 +++++++--- source/port.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/port.cpp b/source/port.cpp index 1c940af..1e4219d 100644 --- a/source/port.cpp +++ b/source/port.cpp @@ -22,6 +22,7 @@ using namespace Msp; Port::Port(NetVis &v, unsigned n): netvis(v), number(n), + registered(false), mesh((GL::COLOR4_UBYTE, GL::VERTEX2)) { char buf[128]; @@ -31,13 +32,16 @@ Port::Port(NetVis &v, unsigned n): addr.sin_addr.s_addr = 0; int err = getnameinfo(reinterpret_cast(&addr), sizeof(sockaddr_in), 0, 0, buf, sizeof(buf), 0); if(err==0) + { name = buf; + registered = !isdigit(name[0]); + } else name = Msp::lexical_cast(number); const map &ports = netvis.get_ports(); unsigned tries = 100; - if(ports.size()>100 && number>=1024) + if(ports.size()>100 && !registered) tries = 10000/ports.size()+1; float best_score = 0; for(unsigned i=0; (i::const_iterator j=ports.begin(); j!=ports.end(); ++j) { - if(number<1024 && j->first>1024) + if(registered && !j->second->is_registered()) break; const GL::Color &other = j->second->get_color(); float dr = c.r-other.r; diff --git a/source/port.h b/source/port.h index d0511e9..4ce9427 100644 --- a/source/port.h +++ b/source/port.h @@ -19,6 +19,7 @@ class Port private: NetVis &netvis; unsigned number; + bool registered; std::string name; Msp::GL::Color color; Msp::GL::Mesh mesh; @@ -27,6 +28,7 @@ public: Port(NetVis &, unsigned); unsigned get_number() const { return number; } + bool is_registered() const { return registered; } const std::string &get_name() const { return name; } const Msp::GL::Color &get_color() const { return color; } -- 2.45.2