1
0

AlarmServer.cc 854 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "MailServer/Server.h"
  2. #include <asio.hpp>
  3. #include <sys/types.h>
  4. #include <fcntl.h>
  5. #include <unistd.h>
  6. #include <iostream>
  7. int main(int argc, char* argv[])
  8. {
  9. try
  10. {
  11. /* error checking elided for brevity */
  12. int fd = ::open("/dev/null", O_WRONLY);
  13. ::dup2(fd, 2);
  14. ::close(fd);
  15. unsigned int port;
  16. std::string path;
  17. std::string url;
  18. if (argc == 3)
  19. {
  20. port = std::atoi(argv[1]);
  21. path = std::string(argv[2]);
  22. }
  23. else if (argc == 4)
  24. {
  25. port = std::atoi(argv[1]);
  26. path = std::string(argv[2]);
  27. url = std::string(argv[3]);
  28. }
  29. else
  30. {
  31. std::cout << "Usage: AlarmServer <port> <path> [url]\n";
  32. return 1;
  33. }
  34. asio::io_service io_service;
  35. MailServer::Server s(io_service, port, path, url);
  36. io_service.run();
  37. }
  38. catch (std::exception& e)
  39. {
  40. std::cerr << "Exception: " << e.what() << std::endl;
  41. }
  42. }