blob: 795185de0ae8fc70634a7f1d5dc5b2bc2e16802d [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
22#include "generic_io.h"
23
24#include <memory>
25#include <functional>
26
27#if defined(_MSC_VER)
28#include <BaseTsd.h>
29using ssize_t = SSIZE_T;
30#endif
31
32namespace jami {
33
34class IceTransport;
35using IceRecvCb = std::function<ssize_t(unsigned char* buf, size_t len)>;
36
37class IceSocket
38{
39private:
40 std::shared_ptr<IceTransport> ice_transport_ {};
41 int compId_ = -1;
42
43public:
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