DOSBox-X
|
00001 /* 00002 * Copyright (C) 2002-2020 The DOSBox Team 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License along 00015 * with this program; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 00020 #ifndef SDLNETWRAPPER_H 00021 #define SDLNETWRAPPER_H 00022 00023 #ifndef DOSBOX_DOSBOX_H 00024 #include "dosbox.h" 00025 #endif 00026 00027 #if C_MODEM 00028 00029 # ifndef DOSBOX_SUPPORT_H 00030 #include "support.h" 00031 #endif 00032 00033 // Netwrapper Capabilities 00034 #define NETWRAPPER_TCP 1 00035 #define NETWRAPPER_TCP_NATIVESOCKET 2 00036 00037 #if defined WIN32 00038 #define NATIVESOCKETS 00039 #include <winsock2.h> 00040 #include <ws2tcpip.h> //for socklen_t 00041 //typedef int socklen_t; 00042 00043 //Tests for BSD/OS2/LINUX 00044 #elif defined HAVE_STDLIB_H && defined HAVE_SYS_TYPES_H && defined HAVE_SYS_SOCKET_H && defined HAVE_NETINET_IN_H 00045 #define NATIVESOCKETS 00046 #define SOCKET int 00047 #include <stdio.h> //darwin 00048 #include <stdlib.h> //darwin 00049 #include <sys/types.h> 00050 #include <sys/socket.h> 00051 #include <netinet/in.h> 00052 //socklen_t should be handled by configure 00053 #endif 00054 00055 #ifdef NATIVESOCKETS 00056 #define CAPWORD (NETWRAPPER_TCP|NETWRAPPER_TCP_NATIVESOCKET) 00057 #else 00058 #define CAPWORD NETWRAPPER_TCP 00059 #endif 00060 00061 #include "SDL_net.h" 00062 00063 00064 00065 Bit32u Netwrapper_GetCapabilities(); 00066 00067 00068 class TCPClientSocket { 00069 public: 00070 TCPClientSocket(TCPsocket source); 00071 TCPClientSocket(const char* destination, Bit16u port); 00072 #ifdef NATIVESOCKETS 00073 Bit8u* nativetcpstruct; 00074 TCPClientSocket(int platformsocket); 00075 #endif 00076 ~TCPClientSocket(); 00077 00078 // return: 00079 // -1: no data 00080 // -2: socket closed 00081 // >0: data char 00082 Bits GetcharNonBlock(); 00083 00084 00085 bool Putchar(Bit8u data); 00086 bool SendArray(Bit8u* data, Bitu bufsize); 00087 bool ReceiveArray(Bit8u* data, Bitu* size); 00088 bool isopen; 00089 00090 bool GetRemoteAddressString(Bit8u* buffer); 00091 00092 void FlushBuffer(); 00093 void SetSendBufferSize(Bitu bufsize); 00094 00095 // buffered send functions 00096 bool SendByteBuffered(Bit8u data); 00097 bool SendArrayBuffered(Bit8u* data, Bitu bufsize); 00098 00099 private: 00100 TCPsocket mysock = NULL; 00101 SDLNet_SocketSet listensocketset = NULL; 00102 00103 // Items for send buffering 00104 Bitu sendbuffersize = 0; 00105 Bitu sendbufferindex = 0; 00106 00107 Bit8u* sendbuffer; 00108 }; 00109 00110 class TCPServerSocket { 00111 public: 00112 bool isopen; 00113 TCPsocket mysock; 00114 TCPServerSocket(Bit16u port); 00115 ~TCPServerSocket(); 00116 TCPClientSocket* Accept(); 00117 }; 00118 00119 00120 #endif //C_MODEM 00121 00122 #endif //# SDLNETWRAPPER_H