Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
TcpInputFilter.h 1.22 KiB
#ifndef TCP_INPUT_H
#define TCP_INPUT_H

#include <arpa/inet.h>
#include <netinet/in.h>

#include <memory>
#include <string>

#include "InputFilter.h"
#include "config.h"
#include "tbb/pipeline.h"
#include "tbb/tick_count.h"

class TcpInputFilter : public InputFilter {
 public:
  TcpInputFilter(int port, size_t packetBufferSize, size_t nbPacketBuffers,
                 uint32_t nOrbitsPerPacket, ctrl &control, config &conf);
  ~TcpInputFilter();

 protected:
  ssize_t readInput(char **buffer, size_t bufferSize);  // Override
  void print(std::ostream &out) const;                  // Override

 private:
  void openConnection();
  void closeConnection();
  ssize_t readPacketFromTcp(char **buffer, size_t bufferSize);

  struct Statistics {
    uint64_t nbOversizedPackets = 0;
    uint64_t nbHeaderDesync = 0;
  } stats;

  struct packet_header {
    uint64_t feedbeef;
    uint64_t frames_in_packet;
    uint64_t orbit_dropped_counter;
    uint64_t orbit_seen_counter;
  };

  const uint32_t nOrbitsPerPacket_;

  sockaddr_in server_addr_;
  sockaddr_in client_addr_;
  int destPort_;
  int sock_;
  unsigned int sin_size_;
  int connected_;
  bool connection_open_ = false;
};

typedef std::shared_ptr<TcpInputFilter> TcpInputFilterPtr;

#endif