static void stratcon_ingest_sweep_journals_int(char *first, char *second, char *third, int (*test)(const char *), int (*ingest)(const char *fullpath, const char *remote_str, const char *remote_cn, const char *id_str)) { char path[PATH_MAX]; DIR *root; struct dirent *de, *entry; int i = 0, cnt = 0; char **entries; int size = 0; snprintf(path, sizeof(path), "%s%s%s%s%s%s%s", basejpath, first ? "/" : "", first ? first : "", second ? "/" : "", second ? second : "", third ? "/" : "", third ? third : ""); #ifdef _PC_NAME_MAX size = pathconf(path, _PC_NAME_MAX); #endif size = MAX(size, PATH_MAX + 128); de = alloca(size); root = opendir(path); if(!root) return; while(portable_readdir_r(root, de, &entry) == 0 && entry != NULL) cnt++; closedir(root); root = opendir(path); if(!root) return; entries = malloc(sizeof(*entries) * cnt); while(portable_readdir_r(root, de, &entry) == 0 && entry != NULL) { if(i < cnt) { entries[i++] = strdup(entry->d_name); } } closedir(root); cnt = i; /* could have changed, directories are fickle */ qsort(entries, i, sizeof(*entries), (int (*)(const void *, const void *))strcasecmp); for(i=0; i<cnt; i++) { if(!strcmp(entries[i], ".") || !strcmp(entries[i], "..")) continue; noitL(ds_deb, "Processing L%d entry '%s'\n", third ? 4 : second ? 3 : first ? 2 : 1, entries[i]); if(!first) stratcon_ingest_sweep_journals_int(entries[i], NULL, NULL, test, ingest); else if(!second) stratcon_ingest_sweep_journals_int(first, entries[i], NULL, test, ingest); else if(!third) stratcon_ingest_sweep_journals_int(first, second, entries[i], test, ingest); else if(test(entries[i])) { char fullpath[PATH_MAX]; snprintf(fullpath, sizeof(fullpath), "%s/%s/%s/%s/%s", basejpath, first,second,third,entries[i]); ingest(fullpath,first,second,third); } } for(i=0; i<cnt; i++) free(entries[i]); free(entries); }
int SrsEdgeIngester::cycle() { int ret = ERROR_SUCCESS; if ((ret = connect_server()) != ERROR_SUCCESS) { return ret; } srs_assert(client); client->set_recv_timeout(SRS_CONSTS_RTMP_RECV_TIMEOUT_US); client->set_send_timeout(SRS_CONSTS_RTMP_SEND_TIMEOUT_US); SrsRequest* req = _req; if ((ret = client->handshake()) != ERROR_SUCCESS) { srs_error("handshake with server failed. ret=%d", ret); return ret; } if ((ret = client->connect_app(req->app, req->tcUrl, req)) != ERROR_SUCCESS) { srs_error("connect with server failed, tcUrl=%s. ret=%d", req->tcUrl.c_str(), ret); return ret; } if ((ret = client->create_stream(stream_id)) != ERROR_SUCCESS) { srs_error("connect with server failed, stream_id=%d. ret=%d", stream_id, ret); return ret; } if ((ret = client->play(req->stream, stream_id)) != ERROR_SUCCESS) { srs_error("connect with server failed, stream=%s, stream_id=%d. ret=%d", req->stream.c_str(), stream_id, ret); return ret; } if ((ret = _source->on_publish()) != ERROR_SUCCESS) { srs_error("edge pull stream then publish to edge failed. ret=%d", ret); return ret; } if ((ret = _edge->on_ingest_play()) != ERROR_SUCCESS) { return ret; } ret = ingest(); if (srs_is_client_gracefully_close(ret)) { srs_warn("origin disconnected, retry. ret=%d", ret); ret = ERROR_SUCCESS; } return ret; }