Skip to content

Commit

Permalink
Fix: YAML File exception catch
Browse files Browse the repository at this point in the history
1. catch YAML File exception
2. local  IP parse method
  • Loading branch information
MakingL committed Jan 2, 2020
1 parent 63e3540 commit c15ec08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ namespace configure {
int PASV_PORT_HIGH;

void parse_config_file() {
YAML::Node node = YAML::LoadFile(configure::config_file);
YAML::Node node;
try {
node = YAML::LoadFile(configure::config_file);
} catch (const std::exception &e) {
std::cerr << "Cannot parse configure file: " << configure::config_file << ". Exception: " << e.what() << std::endl;
std::cerr << "Please check it for existence." << std::endl;
exit(EXIT_FAILURE);
}


if (!node["server"].IsDefined()) {
std::cerr << "Server config information isn't configured correctly" << std::endl;
Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ int main() {
CLTCPServer tcp_server(configure::SERVER_LISTEN_HOST.c_str(), configure::SERVER_LISTEN_PORT);
int listen_fd = tcp_server.start_listen();

tcp::get_local_ip(nullptr);
if (configure::FORCE_PASSIVE_SERVER_IP.empty()) {
if (tcp::get_local_ip(nullptr) < 0) {
std::cerr << " Get local IP address failed. Please configure force passive IP" << std::endl;
exit(EXIT_FAILURE);
}
}

CLEpoll event_epoll(5);
/* 通过管道统一信号源 */
Expand Down
12 changes: 6 additions & 6 deletions src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "utility.h"

namespace utility {
const char* get_file_perms(struct stat& sbuf) { /* 获得文件的权限 */
const char *get_file_perms(struct stat &sbuf) { /* 获得文件的权限 */
static char perms[] = "----------";
perms[0] = '?';

Expand Down Expand Up @@ -84,16 +84,16 @@ namespace utility {
return perms;
}

const char* get_file_date(struct stat& sbuf) {
static char datebuf[64] = { 0 };
const char* format = "%b %e %H:%M";
const char *get_file_date(struct stat &sbuf) {
static char datebuf[64] = {0};
const char *format = "%b %e %H:%M";
struct timeval tv{0};
gettimeofday(&tv, nullptr);
time_t localTime = tv.tv_sec;
if (sbuf.st_mtime > localTime || (localTime - sbuf.st_mtime) > 60*60*24*182) {
if (sbuf.st_mtime > localTime || (localTime - sbuf.st_mtime) > 60 * 60 * 24 * 182) {
format = "%b %e %Y";
}
struct tm* p = localtime(&sbuf.st_mtime);
struct tm *p = localtime(&sbuf.st_mtime);
strftime(datebuf, sizeof(datebuf), format, p); /* 将格式处理成字符串 */
return datebuf;
}
Expand Down

0 comments on commit c15ec08

Please sign in to comment.