1 #pragma once
2 
3 #include "data_handler.hpp"
4 
5 #include <unistd.h>
6 
7 #include <stdplus/handle/managed.hpp>
8 
9 #include <cstdint>
10 #include <optional>
11 #include <vector>
12 
13 namespace ipmi_flash
14 {
15 
16 /**
17  * Data Handler for receiving the image over a network port
18  */
19 class NetDataHandler : public DataInterface
20 {
21   public:
NetDataHandler()22     NetDataHandler() : listenFd(std::nullopt), connFd(std::nullopt) {}
23 
24     bool open() override;
25     bool close() override;
26     std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
27     bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
28     std::vector<std::uint8_t> readMeta() override;
29 
30     static constexpr std::uint16_t listenPort = 623;
31     static constexpr int timeoutS = 5;
32 
33   private:
closefd(int && fd)34     static void closefd(int&& fd)
35     {
36         ::close(fd);
37     }
38     using Fd = stdplus::Managed<int>::Handle<closefd>;
39 
40     Fd listenFd;
41     Fd connFd;
42 };
43 
44 } // namespace ipmi_flash
45