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