summaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-02 00:50:04 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-02 00:50:04 +0000
commit3999c2eccf43c998e70d49023d8f35e3fa1632c8 (patch)
treedffe949ab5a9679f26b870ce71691c6dd60866f9 /src/socket.cpp
parent86775e2e98f55b3b88befe2daff0ca23f02f3155 (diff)
Rewrite BindPorts to index ports by their human-readable description
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11635 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socket.cpp')
-rw-r--r--src/socket.cpp55
1 files changed, 24 insertions, 31 deletions
diff --git a/src/socket.cpp b/src/socket.cpp
index 277f61bcd..ccae48a6d 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -111,12 +111,7 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
{
char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF], Desc[MAXBUF];
int bound = 0;
- bool started_with_nothing = (ports.size() == 0);
- std::vector<std::pair<std::string, int> > old_ports;
-
- /* XXX: Make a copy of the old ip/port pairs here */
- for (std::vector<ListenSocketBase *>::iterator o = ports.begin(); o != ports.end(); ++o)
- old_ports.push_back(make_pair((*o)->GetIP(), (*o)->GetPort()));
+ std::vector<ListenSocketBase*> old_ports(ports.begin(), ports.end());
for (int count = 0; count < Config->ConfValueEnum("bind"); count++)
{
@@ -137,21 +132,18 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
if (*Addr == '*')
*Addr = 0;
+ irc::sockets::sockaddrs bindspec;
+ irc::sockets::aptosa(Addr, portno, &bindspec);
+ std::string bind_readable = irc::sockets::satouser(&bindspec);
+
bool skip = false;
- for (std::vector<ListenSocketBase *>::iterator n = ports.begin(); n != ports.end(); ++n)
+ for (std::vector<ListenSocketBase *>::iterator n = old_ports.begin(); n != old_ports.end(); ++n)
{
- if (((*n)->GetIP() == Addr) && ((*n)->GetPort() == portno))
+ if ((*n)->GetBindDesc() == bind_readable)
{
skip = true;
- /* XXX: Here, erase from our copy of the list */
- for (std::vector<std::pair<std::string, int> >::iterator k = old_ports.begin(); k != old_ports.end(); ++k)
- {
- if ((k->first == Addr) && (k->second == portno))
- {
- old_ports.erase(k);
- break;
- }
- }
+ old_ports.erase(n);
+ break;
}
}
if (!skip)
@@ -165,29 +157,30 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
}
else
{
- failed_ports.push_back(std::make_pair((*Addr ? Addr : "*") + std::string(":") + ConvToStr(portno), strerror(errno)));
+ failed_ports.push_back(std::make_pair(bind_readable, strerror(errno)));
}
}
}
}
}
- /* XXX: Here, anything left in our copy list, close as removed */
- if (!started_with_nothing)
+ std::vector<ListenSocketBase *>::iterator n = ports.begin();
+ for (std::vector<ListenSocketBase *>::iterator o = old_ports.begin(); o != old_ports.end(); ++o)
{
- for (size_t k = 0; k < old_ports.size(); ++k)
+ while (n != ports.end() && *n != *o)
+ n++;
+ if (n == ports.end())
{
- for (std::vector<ListenSocketBase *>::iterator n = ports.begin(); n != ports.end(); ++n)
- {
- if (((*n)->GetIP() == old_ports[k].first) && ((*n)->GetPort() == old_ports[k].second))
- {
- this->Logs->Log("SOCKET",DEFAULT,"Port binding %s:%d was removed from the config file, closing.", old_ports[k].first.c_str(), old_ports[k].second);
- delete *n;
- ports.erase(n);
- break;
- }
- }
+ this->Logs->Log("SOCKET",ERROR,"Port bindings slipped out of vector, aborting close!");
+ break;
}
+
+ this->Logs->Log("SOCKET",DEFAULT, "Port binding %s was removed from the config file, closing.",
+ (*n)->GetBindDesc().c_str());
+ delete *n;
+
+ // this keeps the iterator valid, pointing to the next element
+ n = ports.erase(n);
}
return bound;