Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 3c84316 | 2019-07-07 15:06:44 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 20 | #ifndef REPO_HANDLES_TCP_BULK_INSERT_HANDLE_HPP |
| 21 | #define REPO_HANDLES_TCP_BULK_INSERT_HANDLE_HPP |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 23 | #include "common.hpp" |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 24 | #include "storage/repo-storage.hpp" |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | 3c84316 | 2019-07-07 15:06:44 -0400 | [diff] [blame] | 26 | #include <boost/asio/ip/tcp.hpp> |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 27 | |
| 28 | namespace repo { |
| 29 | |
| 30 | class TcpBulkInsertHandle : noncopyable |
| 31 | { |
| 32 | public: |
| 33 | class Error : public std::runtime_error |
| 34 | { |
| 35 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 36 | using std::runtime_error::runtime_error; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | public: |
| 40 | TcpBulkInsertHandle(boost::asio::io_service& ioService, |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 41 | RepoStorage& storageHandle); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 42 | |
| 43 | void |
| 44 | listen(const std::string& host, const std::string& port); |
| 45 | |
| 46 | void |
| 47 | stop(); |
| 48 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 49 | RepoStorage& |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 50 | getStorageHandle() |
| 51 | { |
| 52 | return m_storageHandle; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | void |
Davide Pesavento | 3c84316 | 2019-07-07 15:06:44 -0400 | [diff] [blame] | 57 | asyncAccept(); |
| 58 | |
| 59 | void |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 60 | handleAccept(const boost::system::error_code& error, |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 61 | const std::shared_ptr<boost::asio::ip::tcp::socket>& socket); |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | boost::asio::ip::tcp::acceptor m_acceptor; |
| 65 | boost::asio::ip::tcp::endpoint m_localEndpoint; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 66 | RepoStorage& m_storageHandle; |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace repo |
| 70 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 71 | #endif // REPO_HANDLES_TCP_BULK_INSERT_HANDLE_HPP |