Mercurial > cabal
changeset 5:0faceb076254
code clean up
added PID to the default Core argument
bool => true|false
| author | Vlad Glagolev <enqlave@gmail.com> |
|---|---|
| date | Thu, 24 Jan 2008 21:00:52 +0300 |
| parents | a7051ac7118b |
| children | 9be05a31b7f9 |
| files | sources/connection.cpp sources/core.cpp sources/engine.cpp sources/headers/connection.hpp sources/headers/core.hpp sources/headers/network.hpp sources/network.cpp |
| diffstat | 7 files changed, 39 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/sources/connection.cpp Thu Jan 24 19:38:34 2008 +0300 +++ b/sources/connection.cpp Thu Jan 24 21:00:52 2008 +0300 @@ -45,7 +45,7 @@ void Connection::ircConnect() { if (!current) - shut ("no hosts defined"); + shut("no hosts defined"); if (!connected && !connecting) { cout << "CONNECTION: connecting to server: " << current->host << endl; @@ -117,24 +117,24 @@ sendMsg("AWAY :" + away); } -void Connection::ircJoin(string nchan, string nckey) +void Connection::ircJoin(string chan, string key) { - sendMsg("JOIN " + nchan + (nckey != "" ? " " + nckey : "")); + sendMsg("JOIN " + chan + (key != "" ? " " + key : "")); } -void Connection::ircPart(string nchan) +void Connection::ircPart(string chan) { - sendMsg("PART " + nchan); + sendMsg("PART " + chan); } -void Connection::ircCycle(string nchan) +void Connection::ircCycle(string chan) { - sendMsg("PART " + nchan); - sendMsg("JOIN " + nchan); + sendMsg("PART " + chan); + sendMsg("JOIN " + chan); } -Connection::host_type * - Connection::addHost(host_type *list, pchar host, int port, pchar password) +Connection::host_type *Connection::addHost(host_type *list, pchar host, \ + int port, pchar password) { if (!list) current = list = new host_type(host, port, password);
--- a/sources/core.cpp Thu Jan 24 19:38:34 2008 +0300 +++ b/sources/core.cpp Thu Jan 24 21:00:52 2008 +0300 @@ -23,10 +23,9 @@ Connection *C; Core::Core(): + pid(PID), commander(COMMANDER) { - pid = PID; - cout << "CORE: initializing...\n"; debug = true; @@ -57,7 +56,7 @@ while (1) { if (!strcmp(argv[e], "-c") || !strcmp(argv[e], "--config")) { if (!argv[++e]) - shut ("missing configuration file"); + shut("missing configuration file"); config = argv[e]; break; @@ -67,7 +66,7 @@ debug = false; break; } else - shut ("unknown option detected: " + (string)argv[e]); + shut("unknown option detected: " + (string)argv[e]); } } } @@ -81,7 +80,7 @@ ifstream sysconfig(config, ios::in); if (!sysconfig) - shut ("unable to open configuration file"); + shut("unable to open configuration file"); else { cout << "CORE: parsing configuration file: " << config << endl; @@ -136,7 +135,7 @@ while (1) { now = gettime(); - usleep (100); + usleep(100); for (int e = 0; e < servers; e++) connections[e]->establish();
--- a/sources/engine.cpp Thu Jan 24 19:38:34 2008 +0300 +++ b/sources/engine.cpp Thu Jan 24 21:00:52 2008 +0300 @@ -23,19 +23,19 @@ bool daemonize() { - if (daemon (1, 1) != 0) { + if (daemon(1, 1) != 0) { cout << "Error: unable to daemonize into background\n"; - exit (1); + exit(1); } else { cout << "ENGINE: successfully daemonized into background\n"; - return daemon (1, 1) == 0; + return daemon(1, 1) == 0; } } time_t gettime() { time_t t; - return time (&t); + return time(&t); } string getCountry(string c)
--- a/sources/headers/connection.hpp Thu Jan 24 19:38:34 2008 +0300 +++ b/sources/headers/connection.hpp Thu Jan 24 21:00:52 2008 +0300 @@ -24,8 +24,7 @@ #include "network.hpp" -class Connection - : public Network +class Connection: public Network { public: Connection();
--- a/sources/headers/core.hpp Thu Jan 24 19:38:34 2008 +0300 +++ b/sources/headers/core.hpp Thu Jan 24 21:00:52 2008 +0300 @@ -44,7 +44,7 @@ int servers; Connection *connections[MAX_SERVERS]; - char *pid; + const char *pid; char *config; char commander;
--- a/sources/headers/network.hpp Thu Jan 24 19:38:34 2008 +0300 +++ b/sources/headers/network.hpp Thu Jan 24 21:00:52 2008 +0300 @@ -24,8 +24,8 @@ #include "core.hpp" -class Network { - +class Network +{ public: Network(); ~Network();
--- a/sources/network.cpp Thu Jan 24 19:38:34 2008 +0300 +++ b/sources/network.cpp Thu Jan 24 21:00:52 2008 +0300 @@ -73,14 +73,14 @@ err = recv(cs, &cbuffer, 1, 0); if (!err) - shut ("remote server closed connection"); + shut("remote server closed connection"); else if (err < 0) - shut ("failed to receive data"); + shut("failed to receive data"); else sbuffer += cbuffer; } } else if (!err) - shut ("remote server closed connection"); + shut("remote server closed connection"); return sbuffer; } @@ -91,7 +91,7 @@ bool Network::resolveHost(pchar name, struct address_type *a, int inet) { #ifdef ENABLE_IPV6 - bool e = 0; + bool e = false; struct addrinfo hints, *res, *reso; struct sockaddr_in *in; @@ -114,17 +114,17 @@ in6 = (struct sockaddr_in6 *)res->ai_addr; memcpy (&a->sa6.sin6_addr, &in6->sin6_addr, \ sizeof (struct in6_addr)); - e = 1; + e = true; break; case AF_INET: a->inet = AF_INET; in = (struct sockaddr_in *)res->ai_addr; memcpy (&a->sa.sin_addr, &in->sin_addr, \ sizeof (struct in_addr)); - e = 1; + e = true; break; default: - e = 0; + e = false; } } @@ -176,10 +176,10 @@ #ifdef ENABLE_IPV6 if (a.inet == AF_INET6) - e = bind(cs, (struct sockaddr *)&a.sa6, sizeof (a.sa6)); + e = bind(cs, (struct sockaddr *)&a.sa6, sizeof(a.sa6)); else #endif // ENABLE_IPV6 - e = bind(cs, (struct sockaddr *)&a.sa, sizeof (a.sa)); + e = bind(cs, (struct sockaddr *)&a.sa, sizeof(a.sa)); if (e == -1) { close(cs); @@ -207,7 +207,7 @@ connected = 0; connecting = 1; - cout << "NETWORK: socket opened........... " << cs << endl; + cout << "NETWORK: socket opened..........: " << cs << endl; return 1; } @@ -224,8 +224,8 @@ if (e == -1) { if (errno == EISCONN) { - connected = 1; - connecting = 0; + connected = true; + connecting = false; return 1; } @@ -233,7 +233,7 @@ if (errno != EWOULDBLOCK && errno != EINPROGRESS && errno != EALREADY) { closeSocket(); - connecting = 0; + connecting = false; return 0; } @@ -241,10 +241,10 @@ return 1; } - connected = 1; - connecting = 0; + connected = true; + connecting = false; - cout << "NETWORK: socket connected........ " << cs << endl; + cout << "NETWORK: socket connected.......: " << cs << endl; return 1; }
