| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #include "MailServer/Server.h"
- #include <Logging.h>
- #include <asio.hpp>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <iostream>
- int main(int argc, char* argv[])
- {
- try
- {
- Logging::OpenLog();
- Logging::SetLogMask(Logging::Severity::Debug);
- /* error checking elided for brevity */
- int fd = ::open("/dev/null", O_WRONLY);
- ::dup2(fd, 2);
- ::close(fd);
- unsigned int port;
- std::string path;
- std::string url;
- if (argc == 3)
- {
- port = std::atoi(argv[1]);
- path = std::string(argv[2]);
- }
- else if (argc == 4)
- {
- port = std::atoi(argv[1]);
- path = std::string(argv[2]);
- url = std::string(argv[3]);
- }
- else
- {
- std::cout << "Usage: AlarmServer <port> <path> [url]\n";
- return 1;
- }
- Logging::Log(Logging::Severity::Info, "Starting AlarmServer");
- asio::io_service io_service;
- MailServer::Server s(io_service, port, path, url);
- io_service.run();
- Logging::Log(Logging::Severity::Info, "Stopping AlarmServer...");
- Logging::CloseLog();
- }
- catch (std::exception& e)
- {
- std::stringstream ss;
- ss << "ERROR: " << e.what() << std::endl;
- std::cerr << ss.str() << std::endl;
- Logging::Log(Logging::Severity::Error, ss.str());
- Logging::CloseLog();
- return -1;
- }
- return 0;
- }
|