Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2023 Savoir-faire Linux Inc. |
| 3 | * |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 4 | * This program is free software: you can redistribute it and/or modify |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 5 | * it under the terms of the GNU General Public License as published by |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 6 | * the Free Software Foundation, either version 3 of the License, or |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 16 | */ |
| 17 | #pragma once |
| 18 | |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 19 | #include <memory> |
| 20 | #include <functional> |
Adrien Béraud | 67ff077 | 2023-07-12 11:22:29 -0400 | [diff] [blame] | 21 | #include <chrono> |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 22 | |
| 23 | #if defined(_MSC_VER) |
| 24 | #include <BaseTsd.h> |
| 25 | using ssize_t = SSIZE_T; |
| 26 | #endif |
| 27 | |
Adrien Béraud | 1ae60aa | 2023-07-07 09:55:09 -0400 | [diff] [blame] | 28 | namespace dhtnet { |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 29 | |
| 30 | class IceTransport; |
| 31 | using IceRecvCb = std::function<ssize_t(unsigned char* buf, size_t len)>; |
| 32 | |
| 33 | class IceSocket |
| 34 | { |
| 35 | private: |
| 36 | std::shared_ptr<IceTransport> ice_transport_ {}; |
| 37 | int compId_ = -1; |
| 38 | |
| 39 | public: |
| 40 | IceSocket(std::shared_ptr<IceTransport> iceTransport, int compId) |
| 41 | : ice_transport_(std::move(iceTransport)) |
| 42 | , compId_(compId) |
| 43 | {} |
| 44 | |
| 45 | void close(); |
| 46 | ssize_t send(const unsigned char* buf, size_t len); |
| 47 | ssize_t waitForData(std::chrono::milliseconds timeout); |
| 48 | void setOnRecv(IceRecvCb cb); |
| 49 | uint16_t getTransportOverhead(); |
| 50 | void setDefaultRemoteAddress(const IpAddr& addr); |
| 51 | int getCompId() const { return compId_; }; |
| 52 | }; |
| 53 | |
| 54 | }; // namespace jami |