]> git.vomp.tv Git - vompserver.git/blob - tcp.h
15 years that line of code has been waiting to crash
[vompserver.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 <unistd.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <errno.h>
30
31 // For TCP_KEEPIDLE and co
32 #include <netinet/tcp.h>
33
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
37 #include <fcntl.h>
38 #include <ctype.h>
39 #include <pthread.h>
40
41 #include "log.h"
42
43
44 typedef unsigned char UCHAR;
45 typedef unsigned short USHORT;
46
47 class TCP
48 {
49   public:
50     // Creation
51     TCP(int tsocket);
52     ~TCP();
53     void assignSocket(int tsocket);
54
55     // Setup
56     void disableReadTimeout();
57     void setNonBlocking();
58     int setSoKeepTime(int timeOut);
59
60     int connectTo(char *host, unsigned short port);
61     int sendPacket(UCHAR*, size_t size);
62 //    UCHAR* receivePacket();
63     int readData(UCHAR* buffer, int totalBytes);
64     
65     // Get methods
66     int isConnected();
67     int getDataLength();
68
69     static void dump(unsigned char* data, USHORT size);
70     static UCHAR dcc(UCHAR c);
71
72   private:
73     Log* log;
74     int sock;
75     int connected;
76     int readTimeoutEnabled;
77     int dataLength;
78     pthread_mutex_t sendLock;
79     
80     void cleanup();
81 };
82
83 #endif