Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
DobbyLogRelay.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2022 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19
20#pragma once
21
22#include "IPollLoop.h"
23
24#include <sys/socket.h>
25#include <sys/un.h>
26#include <mutex>
27#include <string>
28
29// Need a large buffer to store the entire datagram
30#define BUFFER_SIZE (32 * 1024)
31
33 public std::enable_shared_from_this<DobbyLogRelay>
34{
35public:
36 DobbyLogRelay(const std::string &sourceSocketPath,
37 const std::string &destinationSocketPath);
39
40public:
41 void process(const std::shared_ptr<AICommon::IPollLoop> &pollLoop, epoll_event event) override;
42 void addToPollLoop(const std::shared_ptr<AICommon::IPollLoop> &pollLoop);
43 void removeFromPollLoop(const std::shared_ptr<AICommon::IPollLoop> &pollLoop);
44
45private:
46 int createDgramSocket(const std::string& path);
47
48private:
49 const std::string mSourceSocketPath;
50 const std::string mDestinationSocketPath;
51
52 int mSourceSocketFd;
53 int mDestinationSocketFd;
54
55 sockaddr_un mDestinationSocketAddress;
56
57 char mBuf[BUFFER_SIZE];
58 std::mutex mLock;
59};
Definition IPollLoop.h:40
Definition DobbyLogRelay.h:34
void addToPollLoop(const std::shared_ptr< AICommon::IPollLoop > &pollLoop)
Adds the log relay to a given poll loop so that the process() method is called when the source socket...
Definition DobbyLogRelay.cpp:105
void removeFromPollLoop(const std::shared_ptr< AICommon::IPollLoop > &pollLoop)
Removes the log relay to a given poll loop.
Definition DobbyLogRelay.cpp:116
void process(const std::shared_ptr< AICommon::IPollLoop > &pollLoop, epoll_event event) override
Called on the poll loop. Forwards the data from the source to the destination socket.
Definition DobbyLogRelay.cpp:128
int createDgramSocket(const std::string &path)
Create a SOCK_DGRAM AF_UNIX socket at the given path. Removes the socket at the given path if it exis...
Definition DobbyLogRelay.cpp:182