Debian Codegraph @

src/hardware/serialport/misc_util.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /* $Id: misc_util.h,v 1.5 2009-09-25 23:40:47 h-a-l-9000 Exp $ */
20
21 #ifndef SDLNETWRAPPER_H
22 #define SDLNETWRAPPER_H
23
24 #ifndef DOSBOX_DOSBOX_H
25 #include "dosbox.h"
26 #endif
27
28 #if C_MODEM
29
30 # ifndef DOSBOX_SUPPORT_H
31 #include "support.h"
32 #endif
33
34 // Netwrapper Capabilities
35 #define NETWRAPPER_TCP 1
36 #define NETWRAPPER_TCP_NATIVESOCKET 2
37
38 #if defined WIN32
39 #define NATIVESOCKETS
40 #include <winsock2.h>
41 #include <ws2tcpip.h> //for socklen_t
42 //typedef int socklen_t;
43
44 //Tests for BSD/OS2/LINUX
45 #elif defined HAVE_STDLIB_H && defined HAVE_SYS_TYPES_H && defined HAVE_SYS_SOCKET_H && defined HAVE_NETINET_IN_H
46 #define NATIVESOCKETS
47 #define SOCKET int
48 #include <stdio.h> //darwin
49 #include <stdlib.h> //darwin
50 #include <sys/types.h>
51 #include <sys/socket.h>
52 #include <netinet/in.h>
53 //socklen_t should be handled by configure
54 #endif
55
56 #ifdef NATIVESOCKETS
57 #define CAPWORD (NETWRAPPER_TCP|NETWRAPPER_TCP_NATIVESOCKET)
58 #else
59 #define CAPWORD NETWRAPPER_TCP
60 #endif
61
62 #include "SDL_net.h"
63
64
65
66 Bit32u Netwrapper_GetCapabilities();
67
68
69 class TCPClientSocket {
70 public:
71 TCPClientSocket(TCPsocket source);
72 TCPClientSocket(const char* destination, Bit16u port);
73 #ifdef NATIVESOCKETS
74 Bit8u* nativetcpstruct;
75 TCPClientSocket(int platformsocket);
76 #endif
77 ~TCPClientSocket();
78
79 // return:
80 // -1: no data
81 // -2: socket closed
82 // >0: data char
83 Bits GetcharNonBlock();
84
85
86 bool Putchar(Bit8u data);
87 bool SendArray(Bit8u* data, Bitu bufsize);
88 bool ReceiveArray(Bit8u* data, Bitu* size);
89 bool isopen;
90
91 bool GetRemoteAddressString(Bit8u* buffer);
92
93 void FlushBuffer();
94 void SetSendBufferSize(Bitu bufsize);
95
96 // buffered send functions
97 bool SendByteBuffered(Bit8u data);
98 bool SendArrayBuffered(Bit8u* data, Bitu bufsize);
99
100 private:
101 TCPsocket mysock;
102 SDLNet_SocketSet listensocketset;
103
104 // Items for send buffering
105 Bitu sendbuffersize;
106 Bitu sendbufferindex;
107
108 Bit8u* sendbuffer;
109 };
110
111 class TCPServerSocket {
112 public:
113 bool isopen;
114 TCPsocket mysock;
115 TCPServerSocket(Bit16u port);
116 ~TCPServerSocket();
117 TCPClientSocket* Accept();
118 };
119
120
121 #endif //C_MODEM
122
123 #endif //# SDLNETWRAPPER_H