blob: 0a0943ff9188f9b36dc878c6659d5c8bc9e88268 [file] [log] [blame]
Benjamin Fair545f5652019-10-09 14:18:54 -07001#pragma once
2
3#include "data_handler.hpp"
4
5#include <unistd.h>
6
7#include <cstdint>
8#include <optional>
9#include <stdplus/handle/managed.hpp>
10#include <vector>
11
12namespace ipmi_flash
13{
14
15/**
16 * Data Handler for receiving the image over a network port
17 */
18class NetDataHandler : public DataInterface
19{
20 public:
21 NetDataHandler() : listenFd(std::nullopt), connFd(std::nullopt)
22 {
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