diff options
author | Adam <Adam@anope.org> | 2011-08-21 13:38:42 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-09-10 01:55:09 -0400 |
commit | 2eb708e5ad8b259876d24d828f7472b77864c256 (patch) | |
tree | bed6b70d4bc67eb413453a116e77f8f724cdf3fd /src/main.cpp | |
parent | 4fcb371bc8813cd647b7769a64d586e3a57d684d (diff) |
Cleaned up some of the socket code, cleaned up the pipe engines, added support for binary sockets, and cleaned up the asynch connect/accept code
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 103 |
1 files changed, 49 insertions, 54 deletions
diff --git a/src/main.cpp b/src/main.cpp index 3730c60ea..b00a6ee6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,7 +81,7 @@ class UpdateTimer : public Timer } }; -ConnectionSocket *UplinkSock = NULL; +UplinkSocket *UplinkSock = NULL; int CurrentUplink = 0; static void Connect(); @@ -105,77 +105,72 @@ class ReconnectTimer : public Timer } }; -class UplinkSocket : public ConnectionSocket +UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[CurrentUplink]->ipv6), ConnectionSocket(), BufferedSocket() { - public: - UplinkSocket() : ConnectionSocket(Config->Uplinks[CurrentUplink]->ipv6) - { - UplinkSock = this; - } + UplinkSock = this; +} - ~UplinkSocket() +UplinkSocket::~UplinkSocket() +{ + if (ircdproto && Me && !Me->GetLinks().empty() && Me->GetLinks()[0]->IsSynced()) { - if (ircdproto && Me && !Me->GetLinks().empty() && Me->GetLinks()[0]->IsSynced()) + FOREACH_MOD(I_OnServerDisconnect, OnServerDisconnect()); + + for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { - FOREACH_MOD(I_OnServerDisconnect, OnServerDisconnect()); + User *u = it->second; - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (u->server == Me) { - User *u = it->second; - - if (u->server == Me) - { - /* Don't use quitmsg here, it may contain information you don't want people to see */ - ircdproto->SendQuit(u, "Shutting down"); - BotInfo *bi = findbot(u->nick); - if (bi != NULL) - bi->introduced = false; - } + /* Don't use quitmsg here, it may contain information you don't want people to see */ + ircdproto->SendQuit(u, "Shutting down"); + BotInfo *bi = findbot(u->nick); + if (bi != NULL) + bi->introduced = false; } - - ircdproto->SendSquit(Config->ServerName, quitmsg); - - this->ProcessWrite(); // Write out the last bit } - for (unsigned i = Me->GetLinks().size(); i > 0; --i) - if (!Me->GetLinks()[i - 1]->HasFlag(SERVER_JUPED)) - Me->GetLinks()[i - 1]->Delete(Me->GetName() + " " + Me->GetLinks()[i - 1]->GetName()); + ircdproto->SendSquit(Config->ServerName, quitmsg); - UplinkSock = NULL; + this->ProcessWrite(); // Write out the last bit + } - Me->SetFlag(SERVER_SYNCING); + for (unsigned i = Me->GetLinks().size(); i > 0; --i) + if (!Me->GetLinks()[i - 1]->HasFlag(SERVER_JUPED)) + Me->GetLinks()[i - 1]->Delete(Me->GetName() + " " + Me->GetLinks()[i - 1]->GetName()); - if (!quitting) - { - int Retry = Config->RetryWait; - if (Retry <= 0) - Retry = 60; + UplinkSock = NULL; - Log() << "Retrying in " << Retry << " seconds"; - new ReconnectTimer(Retry); - } - } + Me->SetFlag(SERVER_SYNCING); - bool Read(const Anope::string &buf) + if (!quitting) { - process(buf); - return true; - } + int Retry = Config->RetryWait; + if (Retry <= 0) + Retry = 60; - void OnConnect() - { - Log() << "Successfully connected to " << Config->Uplinks[CurrentUplink]->host << ":" << Config->Uplinks[CurrentUplink]->port; - ircdproto->SendConnect(); - FOREACH_MOD(I_OnServerConnect, OnServerConnect()); + Log() << "Retrying in " << Retry << " seconds"; + new ReconnectTimer(Retry); } +} - void OnError(const Anope::string &error) - { - Log() << "Unable to connect to server " << Config->Uplinks[CurrentUplink]->host << ":" << Config->Uplinks[CurrentUplink]->port << (!error.empty() ? (": " + error) : ""); - this->SetFlag(SF_DEAD); - } -}; +bool UplinkSocket::Read(const Anope::string &buf) +{ + process(buf); + return true; +} + +void UplinkSocket::OnConnect() +{ + Log() << "Successfully connected to " << Config->Uplinks[CurrentUplink]->host << ":" << Config->Uplinks[CurrentUplink]->port; + ircdproto->SendConnect(); + FOREACH_MOD(I_OnServerConnect, OnServerConnect()); +} + +void UplinkSocket::OnError(const Anope::string &error) +{ + Log() << "Unable to connect to server " << Config->Uplinks[CurrentUplink]->host << ":" << Config->Uplinks[CurrentUplink]->port << (!error.empty() ? (": " + error) : ""); +} static void Connect() { |