]> git.vomp.tv Git - vompclient.git/blob - tcp.h
Replace TCP. Use new IP API only, getMAC works with if!=eth0
[vompclient.git] / tcp.h
1 /*
2     Copyright 2020 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP 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 2 of the License, or
9     (at your option) any later version.
10
11     VOMP 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 VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef TCP_H
21 #define TCP_H
22
23 #include <mutex>
24
25 #include "defines.h"
26
27 struct MACAddress
28 {
29   UCHAR mac[6];
30 };
31
32 class Log;
33
34 class TCP
35 {
36   public:
37     ~TCP();
38     bool init(); // Must call this first, once on any new TCP object
39     void shutdown(); // Optional. Closes connection. Can call connect() next
40     
41     bool connect(const std::string& ip, USHORT port);
42     bool read(void* dest, ULONG numBytes);
43     bool write(void* src, ULONG numBytes);
44     bool status();
45
46     MACAddress getMAC();
47
48   private:
49     Log* logger;
50     int sockfd{-1};
51     int abortPipe[2]{-1, -1};
52     bool connected{};
53     std::mutex writeMutex;
54 };
55
56 #endif