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:
22     NetDataHandler() : listenFd(std::nullopt), connFd(std::nullopt)
23     {}
24 
25     bool open() override;
26     bool close() override;
27     std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
28     bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
29     std::vector<std::uint8_t> readMeta() override;
30 
31     static constexpr std::uint16_t listenPort = 623;
32     static constexpr int timeoutS = 5;
33 
34   private:
35     static void closefd(int&& fd)
36     {
37         ::close(fd);
38     }
39     using Fd = stdplus::Managed<int>::Handle<closefd>;
40 
41     Fd listenFd;
42     Fd connFd;
43 };
44 
45 } // namespace ipmi_flash
46