main.cpp 819 B

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