]> git.vomp.tv Git - vompclient.git/blob - tcp.h
Fix black background for 16:9 live TV on 4:3 screen
[vompclient.git] / tcp.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3     Copyright 2003-2004 University Of Bradford
4
5     This file is part of VOMP.
6
7     VOMP is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     VOMP is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with VOMP; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21
22 #ifndef TCP_H
23 #define TCP_H
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <ctype.h>
31 #include <mutex>
32
33 #ifndef WIN32
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <unistd.h>
37 #include <arpa/inet.h>
38 #include <sys/ioctl.h>
39 #include <net/if.h>
40 #include <pthread.h>
41 #else
42 #include <winsock2.h>
43 #include <errno.h>
44 #include <Ws2tcpip.h>
45 #endif
46
47 #include "defines.h"
48
49 class TCP
50 {
51   public:
52     TCP();
53     ~TCP();
54
55     int connectTo(char *host, unsigned short port);
56     void assignSocket(int tsocket);
57
58     int isConnected();
59     void disableTimeout();
60
61     int readData(void* buffer, int totalBytes);
62     int sendData(void*, size_t size);
63
64     static void dump(unsigned char* data, ULONG size);
65
66     void getMAC(char* dest); // copies 6 MAC bytes to dest
67     void setReceiveWindow(size_t rxBufferSize);
68
69   private:
70     int sock;
71     int connected;
72     int timeoutEnabled;
73     int dataLength;
74     std::mutex mutex;
75
76     static UCHAR dcc(UCHAR c);
77 };
78
79 #endif