blob: b107e7296b504a759f56a18b3f2d9b51b8c033c2 [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:
22 NetDataHandler() : listenFd(std::nullopt), connFd(std::nullopt)
Patrick Venture9b37b092020-05-28 20:58:57 -070023 {}
Benjamin Fair545f5652019-10-09 14:18:54 -070024
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