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