You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
930 B
C++
44 lines
930 B
C++
![]()
6 years ago
|
// A general HTTP server serving static files.
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <string>
|
||
|
|
||
|
#include "webcc/logger.h"
|
||
|
#include "webcc/server.h"
|
||
|
|
||
![]()
6 years ago
|
void Help() {
|
||
|
std::cout << "Usage:" << std::endl;
|
||
|
std::cout << " file_server <port> <doc_root> [chunk_size]" << std::endl;
|
||
|
std::cout << "E.g.," << std::endl;
|
||
|
std::cout << " file_server 8080 D:/www" << std::endl;
|
||
|
std::cout << " file_server 8080 D:/www 10000" << std::endl;
|
||
![]()
6 years ago
|
}
|
||
|
|
||
|
int main(int argc, char* argv[]) {
|
||
|
if (argc < 3) {
|
||
![]()
6 years ago
|
Help();
|
||
![]()
6 years ago
|
return 1;
|
||
|
}
|
||
|
|
||
|
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||
|
|
||
|
std::uint16_t port = static_cast<std::uint16_t>(std::atoi(argv[1]));
|
||
|
std::string doc_root = argv[2];
|
||
|
|
||
|
try {
|
||
![]()
6 years ago
|
webcc::Server server(port, doc_root);
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
if (argc == 4) {
|
||
|
server.set_file_chunk_size(std::atoi(argv[3]));
|
||
|
}
|
||
|
|
||
![]()
6 years ago
|
server.Run();
|
||
![]()
6 years ago
|
|
||
|
} catch (const std::exception& e) {
|
||
|
std::cerr << e.what() << std::endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|