comparison dwcompat.h @ 1960:22e3e829be13

Win: Switch to using winsock 2.x, this will remove support for ancient versions of Windows like 95 and NT 3.5 and older... This allows us to use unix domain sockets with Windows 10 for the sockpipe() macro... (used in my HandyFTP application) When compiled with Visual Studio 2017 5.5 and newer will use unix domain sockets, however this may fail on older Windows 10 versions and older versions of Windows. I am not sure it is worth the effort to dual mode it, when it can just be compiled with an older compiler and function on older versions of Windows if necessary.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 26 Jul 2019 06:58:41 +0000
parents cb5f9aa9aebb
children 824fdbc2f761
comparison
equal deleted inserted replaced
1959:9ac432c8620c 1960:22e3e829be13
127 127
128 #ifndef BKS_TABBEDDIALOG 128 #ifndef BKS_TABBEDDIALOG
129 #define BKS_TABBEDDIALOG 0x0800 129 #define BKS_TABBEDDIALOG 0x0800
130 #endif 130 #endif
131 131
132 #define PIPENAME "\\socket\\" __TARGET__ "%d" 132 #define PIPEROOT "\\socket\\"
133 #define TPIPENAME "\\socket\\" __TARGET__ "%d"
134 #else
135 #define PIPENAME "/tmp/" __TARGET__ "%d"
136 #define TPIPENAME "/tmp/" __TARGET__ "%d"
137 #endif /* __EMX__ || __IBMC__ */ 133 #endif /* __EMX__ || __IBMC__ */
138 134
139 #if defined(__OS2__) && (defined(__IBMC__) || defined(__WATCOMC__)) 135 #if defined(__OS2__) && (defined(__IBMC__) || defined(__WATCOMC__))
140 #define BSD_SELECT 136 #define BSD_SELECT
141 137
161 # else 157 # else
162 # define API _cdecl 158 # define API _cdecl
163 # endif 159 # endif
164 #endif 160 #endif
165 161
162 #include <winsock2.h>
166 #include <windows.h> 163 #include <windows.h>
167 #include <winsock.h>
168 #include <time.h> 164 #include <time.h>
169 #include <process.h> 165 #include <process.h>
170 #include <sys/stat.h> 166 #include <sys/stat.h>
171 167
172 #ifdef MSVC 168 #ifdef MSVC
183 #include <dirent.h> 179 #include <dirent.h>
184 #endif 180 #endif
185 181
186 #include <stdarg.h> 182 #include <stdarg.h>
187 183
188 #if defined(__CYGWIN32__) /*|| defined(__MINGW32__)*/ 184 /* Cygwin and Visual Studio 15.4 (SDK 10.0.16299.15) support domain sockets */
185 #if defined(__CYGWIN32__)
189 #include <sys/un.h> 186 #include <sys/un.h>
190 #endif /* __CYGWIN32__ || __MINGW32__ */ 187 #elif defined(_MSC_VER) && _MSC_VER >= 1912
191 188 #include <afunix.h>
192 #ifndef __CYGWIN32__ 189 #define PIPEROOT "C:\\Windows\\Temp\\"
190 #else
193 #define NO_DOMAIN_SOCKETS 191 #define NO_DOMAIN_SOCKETS
194 #endif /* __CYGWIN32__ */ 192 #endif
193
194 #ifndef PIPEROOT
195 #define PIPEROOT "/tmp/"
196 #endif
197
198 #define PIPENAME "%s" __TARGET__ "%d"
195 199
196 #if defined(_P_NOWAIT) && !defined(P_NOWAIT) 200 #if defined(_P_NOWAIT) && !defined(P_NOWAIT)
197 #define P_NOWAIT _P_NOWAIT 201 #define P_NOWAIT _P_NOWAIT
198 #endif 202 #endif
199 203
316 #endif 320 #endif
317 321
318 #ifdef __IBMC__ 322 #ifdef __IBMC__
319 #define sockinit() sock_init(); 323 #define sockinit() sock_init();
320 #elif defined(__WIN32__) || defined(WINNT) 324 #elif defined(__WIN32__) || defined(WINNT)
321 #define sockinit() { static WSADATA wsa; WSAStartup(MAKEWORD (1, 1), &wsa); } 325 #define sockinit() { static WSADATA wsa; WSAStartup(MAKEWORD (2, 0), &wsa); }
322 #else /* !WIN32 */ 326 #else /* !WIN32 */
323 #define sockinit() 327 #define sockinit()
324 #endif 328 #endif
325 329
326 #if defined(__WIN32__) || defined(WINNT) 330 #if defined(__WIN32__) || defined(WINNT)
336 struct sockaddr_un un; \ 340 struct sockaddr_un un; \
337 int tmpsock = socket(AF_UNIX, SOCK_STREAM, 0); \ 341 int tmpsock = socket(AF_UNIX, SOCK_STREAM, 0); \
338 pipes[1] = socket(AF_UNIX, SOCK_STREAM, 0); \ 342 pipes[1] = socket(AF_UNIX, SOCK_STREAM, 0); \
339 memset(&un, 0, sizeof(un)); \ 343 memset(&un, 0, sizeof(un)); \
340 un.sun_family=AF_UNIX; \ 344 un.sun_family=AF_UNIX; \
341 sprintf(un.sun_path, PIPENAME, pipes[1]); \ 345 sprintf(un.sun_path, PIPENAME, PIPEROOT, pipes[1]); \
342 bind(tmpsock, (struct sockaddr *)&un, sizeof(un)); \ 346 bind(tmpsock, (struct sockaddr *)&un, sizeof(un)); \
343 listen(tmpsock, 0); \ 347 listen(tmpsock, 0); \
344 connect(pipes[1], (struct sockaddr *)&un, sizeof(un)); \ 348 connect(pipes[1], (struct sockaddr *)&un, sizeof(un)); \
345 pipes[0] = accept(tmpsock, 0, 0); \ 349 pipes[0] = accept(tmpsock, 0, 0); \
346 sockclose(tmpsock); \ 350 sockclose(tmpsock); \