Skip to content

files stop being send after a while #14

@saper150

Description

@saper150

HI, i have an issue where after sending some file (usually 10-70) FluteTransmitter stops sending files.

My setup:
I have a ffmpg process running the is creating an hls stream and saving the files to ~/hls folder

My code:
main.cpp

#include "Watcher.h"
#include <chrono>
#include <thread>

int main() {
    Watcher f;
    f.register_file_watchers();
    f.io_service.run();

}

Watcher.h

#pragma once

#include <string>
#include "Poco/DirectoryWatcher.h"
#include <boost/asio.hpp>
#include "Transmitter.h"

class Watcher {
    public:
    boost::asio::io_service io_service;
    void register_file_watchers();
    Watcher();

    private:
    const std::string m_watch_folder = "/home/tx/hls";
    std::unique_ptr<LibFlute::Transmitter> m_transmitter;
    void handle_file(const Poco::DirectoryWatcher::DirectoryEvent &changeEvent);

};

Watcher.cpp

#include "Watcher.h"
#include "spdlog/spdlog.h"
#include "Poco/Delegate.h"

#include <vector>
#include <fstream>

#include <filesystem>

bool hasEnding (std::string const &fullString, std::string const &ending) {
    if (fullString.length() >= ending.length()) {
        return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
    } else {
        return false;
    }
}


Watcher::Watcher()
{
    m_transmitter = std::make_unique<LibFlute::Transmitter>("239.11.4.50", 9988, 0,
                                                         1500, 800000, io_service);

    m_transmitter->register_completion_callback([](uint32_t tui) {
        spdlog::info("file transmitted {}", tui);
    });
}


void Watcher::register_file_watchers()
{
    spdlog::info("Setting up file watcher at {}", m_watch_folder);

    try
    {
        auto *watcher = new Poco::DirectoryWatcher(m_watch_folder);

        watcher->itemMovedTo += Poco::delegate(this, &Watcher::handle_file);
        watcher->itemAdded += Poco::delegate(this, &Watcher::handle_file);
    }
    catch (const Poco::FileNotFoundException &error)
    {
        spdlog::error("watch folder does not exists {}", m_watch_folder);
        exit(1);
    }
}


void Watcher::handle_file(const Poco::DirectoryWatcher::DirectoryEvent &changeEvent)
{

    if (hasEnding(changeEvent.item.absolutePath(), ".tmp")) {
        return;
    }

    spdlog::info("handle file {}", changeEvent.item.absolutePath());

    std::ifstream file(changeEvent.item.absolutePath(), std::ios_base::binary);

    std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
    
    std::filesystem::path path(changeEvent.item.absolutePath());

    std::string toSend = "watchfolder/hls/" + path.filename().string();

    m_transmitter->send(
        toSend,
        "application/octet-stream",
        m_transmitter->seconds_since_epoch() + 60 * 10,
        (char *)content.c_str(),
        content.length()
    );

}

After sending some files completion callback stops being invoked

part of my logs:

[2025-04-15 14:00:02.270] [info] file transmitted 55
[2025-04-15 14:00:02.270] [info] file transmitted 56
[2025-04-15 14:00:04.251] [info] handle file /home/tx/hls/stream2286.ts
[2025-04-15 14:00:04.259] [info] handle file /home/tx/hls/stream.m3u8
[2025-04-15 14:00:04.270] [info] file transmitted 57
[2025-04-15 14:00:04.270] [info] file transmitted 58
[2025-04-15 14:00:06.263] [info] handle file /home/tx/hls/stream2287.ts
[2025-04-15 14:00:06.267] [info] handle file /home/tx/hls/stream.m3u8
[2025-04-15 14:00:06.280] [info] file transmitted 59
[2025-04-15 14:00:06.280] [info] file transmitted 60
[2025-04-15 14:00:08.265] [info] handle file /home/tx/hls/stream2288.ts
[2025-04-15 14:00:08.270] [info] handle file /home/tx/hls/stream.m3u8
[2025-04-15 14:00:08.278] [info] file transmitted 61
[2025-04-15 14:00:08.278] [info] file transmitted 62
[2025-04-15 14:00:10.247] [info] handle file /home/tx/hls/stream2289.ts
[2025-04-15 14:00:10.247] [info] handle file /home/tx/hls/stream.m3u8
[2025-04-15 14:00:12.256] [info] handle file /home/tx/hls/stream2290.ts
[2025-04-15 14:00:12.262] [info] handle file /home/tx/hls/stream.m3u8
[2025-04-15 14:00:14.256] [info] handle file /home/tx/hls/stream2291.ts
[2025-04-15 14:00:14.261] [info] handle file /home/tx/hls/stream.m3u8
[2025-04-15 14:00:16.261] [info] handle file /home/tx/hls/stream2292.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions