blob: 4a6b457f188738402bd21882ee6beee0c9cecc5b [file] [log] [blame]
Adrien Béraud612b55b2023-05-29 10:42:04 -04001/*
2 * Copyright (C) 2004-2023 Savoir-faire Linux Inc.
3 *
Adrien Béraudcb753622023-07-17 22:32:49 -04004 * This program is free software: you can redistribute it and/or modify
Adrien Béraud612b55b2023-05-29 10:42:04 -04005 * it under the terms of the GNU General Public License as published by
Adrien Béraudcb753622023-07-17 22:32:49 -04006 * the Free Software Foundation, either version 3 of the License, or
Adrien Béraud612b55b2023-05-29 10:42:04 -04007 * (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éraudcb753622023-07-17 22:32:49 -040011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Adrien Béraud612b55b2023-05-29 10:42:04 -040012 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
Adrien Béraudcb753622023-07-17 22:32:49 -040015 * along with this program. If not, see <https://www.gnu.org/licenses/>.
Adrien Béraud612b55b2023-05-29 10:42:04 -040016 */
17#pragma once
18
Adrien Béraud612b55b2023-05-29 10:42:04 -040019#include <memory>
20#include <functional>
Adrien Béraud67ff0772023-07-12 11:22:29 -040021#include <chrono>
Adrien Béraud612b55b2023-05-29 10:42:04 -040022
23#if defined(_MSC_VER)
24#include <BaseTsd.h>
25using ssize_t = SSIZE_T;
26#endif
27
Adrien Béraud1ae60aa2023-07-07 09:55:09 -040028namespace dhtnet {
Adrien Béraud612b55b2023-05-29 10:42:04 -040029
30class IceTransport;
31using IceRecvCb = std::function<ssize_t(unsigned char* buf, size_t len)>;
32
33class IceSocket
34{
35private:
36 std::shared_ptr<IceTransport> ice_transport_ {};
37 int compId_ = -1;
38
39public:
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