blob: 4582e26233338875cb2b6cb4938f60b4e851f91a [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
Patrick Venture9b37b092020-05-28 20:58:57 -07007#include <stdplus/handle/managed.hpp>
8
Benjamin Fair545f5652019-10-09 14:18:54 -07009#include <cstdint>
10#include <optional>
Benjamin Fair545f5652019-10-09 14:18:54 -070011#include <vector>
12
13namespace ipmi_flash
14{
15
16/**
17 * Data Handler for receiving the image over a network port
18 */
19class NetDataHandler : public DataInterface
20{
21 public:
Patrick Williams10388362023-05-10 07:51:09 -050022 NetDataHandler() : listenFd(std::nullopt), connFd(std::nullopt) {}
Benjamin Fair545f5652019-10-09 14:18:54 -070023
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:
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