Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tried to create SocketManager and P2PSocket to be used in API.
- Loading branch information
Showing
8 changed files
with
144 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* You may redistribute this program and/or modify it under the terms of | ||
* the GNU General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#include "P2PSocket.h" | ||
#include "SocketManager.h" | ||
|
||
namespace p2pnet { | ||
|
||
P2PSocket::P2PSocket() { | ||
m_parent_manager = Singleton<SocketManager>::getInstance(); | ||
} | ||
P2PSocket::P2PSocket(SocketManager& parent_manager) : m_parent_manager(&parent_manager) {} | ||
|
||
P2PSocket::~P2PSocket() {} | ||
|
||
} /* namespace p2pnet */ |
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,31 @@ | ||
/* | ||
* You may redistribute this program and/or modify it under the terms of | ||
* the GNU General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef P2PSOCKET_H_ | ||
#define P2PSOCKET_H_ | ||
|
||
namespace p2pnet { | ||
|
||
class SocketManager; | ||
|
||
class P2PSocket { | ||
SocketManager* m_parent_manager; | ||
public: | ||
P2PSocket(); | ||
P2PSocket(SocketManager& parent_manager); | ||
virtual ~P2PSocket(); | ||
}; | ||
|
||
} /* namespace p2pnet */ | ||
|
||
#endif /* P2PSOCKET_H_ */ |
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,36 @@ | ||
/* | ||
* You may redistribute this program and/or modify it under the terms of | ||
* the GNU General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#include "SocketManager.h" | ||
|
||
namespace p2pnet { | ||
|
||
SocketManager::SocketManager() : m_external_io_service(false) { | ||
socket_thread = std::thread([&](){m_io_service->run();}); | ||
} | ||
|
||
SocketManager::SocketManager(boost::asio::io_service& io_service) : | ||
m_io_service(&io_service), | ||
m_external_io_service(true) { | ||
} | ||
|
||
SocketManager::~SocketManager() { | ||
if(!m_external_io_service){ | ||
m_io_service->stop(); | ||
if(socket_thread.joinable()) | ||
socket_thread.join(); | ||
delete m_io_service; | ||
} | ||
} | ||
|
||
} /* namespace p2pnet */ |
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,42 @@ | ||
/* | ||
* You may redistribute this program and/or modify it under the terms of | ||
* the GNU General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef SOCKETMANAGER_H_ | ||
#define SOCKETMANAGER_H_ | ||
|
||
#include <boost/asio.hpp> | ||
#include <thread> | ||
#include "daemon_comm/APIClient.h" | ||
|
||
namespace p2pnet { | ||
|
||
/** | ||
* This class is used for connection to p2pnetd. | ||
*/ | ||
class SocketManager { | ||
std::thread socket_thread; | ||
boost::asio::io_service* m_io_service; | ||
bool m_external_io_service; | ||
|
||
api::APIClient* m_primary_api_client; | ||
public: | ||
SocketManager(); | ||
SocketManager(boost::asio::io_service& io_service); | ||
virtual ~SocketManager(); | ||
|
||
|
||
}; | ||
|
||
} /* namespace p2pnet */ | ||
|
||
#endif /* SOCKETMANAGER_H_ */ |
File renamed without changes.
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
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