-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* \file | ||
* \author Jakub Antonín Štigler <[email protected]> | ||
* \brief Mutexed vector of tcp connections (header file) | ||
* \date 2024 | ||
* | ||
* Copyright: (C) 2023 CESNET, z.s.p.o. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <vector> // std::vector | ||
#include <memory> // std::unique_ptr | ||
#include <mutex> // std::mutex, std::lock_guard | ||
|
||
#include <ipfixcol2.h> // ipx_session | ||
|
||
#include "Connection.hpp" // Connection | ||
|
||
namespace tcp_in | ||
{ | ||
|
||
class ConnectionVec { | ||
public: | ||
// TODO: methods for waiting for connection and getting the connections | ||
|
||
/** | ||
* @brief Adds connection to the vector and epoll. | ||
* @param fd file descriptor of the new tcp connection. | ||
*/ | ||
void add_connection(int fd); | ||
|
||
/** | ||
* @brief Removes connection from the vector based on its session. This is safe only for the | ||
* main thread (not the acceptor thread). | ||
* @param session session of the connection to remove. | ||
*/ | ||
void remove_connection(struct ipx_session *session); | ||
private: | ||
/** | ||
* @brief Locks the session for safe adding, removing is safe only for the main thread (not the | ||
* acceptor thread). | ||
* @return Lock guard, vec is unlocked when it goes out of scope. | ||
*/ | ||
inline std::lock_guard<std::mutex> get_lock() { | ||
return std::lock_guard(m_mutex); | ||
} | ||
|
||
int m_epoll_fd; | ||
std::mutex m_mutex; | ||
std::vector<std::unique_ptr<Connection>> m_connections; | ||
}; | ||
|
||
} // namespace tcp_in | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters