blob: 5e3c1750ec784063cdd527c94cea34848cb63485 [file] [log] [blame]
Adrien Béraud612b55b2023-05-29 10:42:04 -04001/*
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
Adrien Béraud612b55b2023-05-29 10:42:04 -040022#include <memory>
23#include <functional>
Adrien Béraud67ff0772023-07-12 11:22:29 -040024#include <chrono>
Adrien Béraud612b55b2023-05-29 10:42:04 -040025
26#if defined(_MSC_VER)
27#include <BaseTsd.h>
28using ssize_t = SSIZE_T;
29#endif
30
Adrien Béraud1ae60aa2023-07-07 09:55:09 -040031namespace dhtnet {
Adrien Béraud612b55b2023-05-29 10:42:04 -040032
33class IceTransport;
34using IceRecvCb = std::function<ssize_t(unsigned char* buf, size_t len)>;
35
36class IceSocket
37{
38private:
39 std::shared_ptr<IceTransport> ice_transport_ {};
40 int compId_ = -1;
41
42public:
43 IceSocket(std::shared_ptr<IceTransport> iceTransport, int compId)
44 : ice_transport_(std::move(iceTransport))
45 , compId_(compId)
46 {}
47
48 void close();
49 ssize_t send(const unsigned char* buf, size_t len);
50 ssize_t waitForData(std::chrono::milliseconds timeout);
51 void setOnRecv(IceRecvCb cb);
52 uint16_t getTransportOverhead();
53 void setDefaultRemoteAddress(const IpAddr& addr);
54 int getCompId() const { return compId_; };
55};
56
57}; // namespace jami