Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
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 
28 // Need a large buffer to store the entire datagram
29 #define BUFFER_SIZE (32 * 1024)
30 
32  public std::enable_shared_from_this<DobbyLogRelay>
33 {
34 public:
35  DobbyLogRelay(const std::string &sourceSocketPath,
36  const std::string &destinationSocketPath);
37  ~DobbyLogRelay();
38 
39 public:
40  void process(const std::shared_ptr<AICommon::IPollLoop> &pollLoop, epoll_event event) override;
41  void addToPollLoop(const std::shared_ptr<AICommon::IPollLoop> &pollLoop);
42  void removeFromPollLoop(const std::shared_ptr<AICommon::IPollLoop> &pollLoop);
43 
44 private:
45  int createDgramSocket(const std::string& path);
46 
47 private:
48  const std::string mSourceSocketPath;
49  const std::string mDestinationSocketPath;
50 
51  int mSourceSocketFd;
52  int mDestinationSocketFd;
53 
54  sockaddr_un mDestinationSocketAddress;
55 
56  char mBuf[BUFFER_SIZE];
57  std::mutex mLock;
58 };
Definition: IPollLoop.h:40
Definition: DobbyLogRelay.h:33
DobbyLogRelay(const std::string &sourceSocketPath, const std::string &destinationSocketPath)
Create relay between two UNIX datagram sockets.
Definition: DobbyLogRelay.cpp:40
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