Repository: ossrs/srs
File: trunk/src/main/srs_main_server.cpp (C++)

Code before:
extern const char* _srs_version;

// @global main SRS server, for debugging
SrsServer* _srs_server = NULL;

// Whether setup config by environment variables, see https://github.com/ossrs/srs/issues/2277
bool _srs_config_by_env = false;

// The binary name of SRS.
const char* _srs_binary = NULL;

// Free global data, for address sanitizer.
extern void srs_free_global_system_ips();

#ifdef SRS_SANITIZER_LOG
void asan_report_callback(const char* str)
{
    char buf[256];

    std::vector<std::string> asan_logs = srs_string_split(string(str), "\n");
    size_t log_count = asan_logs.size();
    for (size_t i = 0; i < log_count; i++) {
        std::string l = srs_string_trim_start(asan_logs[i], " ");

        if (srs_string_starts_with(l, "#")) {
            if ((srs_parse_asan_backtrace_symbols((char*)l.c_str(), buf)) == ERROR_SUCCESS) {
                asan_logs[i] += ", " + std::string(buf);

            }
        }
        srs_trace("%s", asan_logs[i].c_str());
    }
}
#endif

/**
 * main entrance.
 */
srs_error_t do_main(int argc, char** argv, char** envp)
{
    srs_error_t err = srs_success;

    // TODO: Might fail if change working directory.
    _srs_binary = argv[0];

    // Initialize global and thread-local variables.
    if ((err = srs_global_initialize()) != srs_success) {
        return srs_error_wrap(err, "global init");
    }

    if ((err = SrsThreadPool::setup_thread_locals()) != srs_success) {

Review comment (suggestion):
Since we have already used an int return value, we might as well make use of it.

```cpp
for (size_t i = 0; i < log_count; i++) {
  std::string log = srs_string_trim_start(asan_logs[i], " ");
  if (!srs_string_starts_with(log, "#")) {
    srs_trace("%s", log.c_str());
    continue;
  }

  int r0 = srs_parse_asan_backtrace_symbols((char*)log.c_str(), buf);
  if (r0 != ERROR_SUCCESS) {
    srs_trace("%s, r0=%d", log.c_str(), r0);
  } else {
    srs_trace("%s, %s", log.c_str(), buf);
  }
```

`TRANS_BY_GPT3`

Code after:
extern const char* _srs_version;

// @global main SRS server, for debugging
SrsServer* _srs_server = NULL;

// Whether setup config by environment variables, see https://github.com/ossrs/srs/issues/2277
bool _srs_config_by_env = false;

// The binary name of SRS.
const char* _srs_binary = NULL;

// Free global data, for address sanitizer.
extern void srs_free_global_system_ips();

#ifdef SRS_SANITIZER_LOG
extern void asan_report_callback(const char* str);
#endif

/**
 * main entrance.
 */
srs_error_t do_main(int argc, char** argv, char** envp)
{
    srs_error_t err = srs_success;

    // TODO: Might fail if change working directory.
    _srs_binary = argv[0];

    // Initialize global and thread-local variables.
    if ((err = srs_global_initialize()) != srs_success) {
        return srs_error_wrap(err, "global init");
    }

    if ((err = SrsThreadPool::setup_thread_locals()) != srs_success) {
        return srs_error_wrap(err, "thread init");
    }

    // For background context id.
    _srs_context->set_id(_srs_context->generate_id());

    // TODO: support both little and big endian.
    srs_assert(srs_is_little_endian());
    
    // for gperf gmp or gcp,
    // should never enable it when not enabled for performance issue.
#ifdef SRS_GPERF_MP
    HeapProfilerStart("gperf.srs.gmp");
#endif
#ifdef SRS_GPERF_CP
    ProfilerStart("gperf.srs.gcp");
#endif