Diff
Not logged in

Differences From Artifact [353f2e256f]:

To Artifact [b834fac103]:


1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







/* 
 * tclWinSock.c --
 *
 *	This file contains Windows-specific socket related code.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclWinSock.c,v 1.17 1999/08/01 22:09:29 redman Exp $
 * RCS: @(#) $Id: tclWinSock.c,v 1.18 1999/12/09 14:44:11 hobbs Exp $
 */

#include "tclWinInt.h"

/*
 * The following variable is used to tell whether this module has been
 * initialized.
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288

289
290
291

292
293
294
295
296

297
298
299
300
301
302
303
256
257
258
259
260
261
262

263
264
265
266
267
268

269


















270



271

272
273
274

275
276
277
278
279
280
281
282







-






-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-



-
+







 */

static void
InitSockets()
{
    DWORD id;
    WSADATA wsaData;
    OSVERSIONINFO info;
    ThreadSpecificData *tsdPtr = 
	(ThreadSpecificData *)TclThreadDataKeyGet(&dataKey);

    if (! initialized) {
	initialized = 1;
	Tcl_CreateExitHandler(SocketExitHandler, (ClientData) NULL);
    

	/*
	 * Find out if we're running on Win32s.
	 */
    
	info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&info);
    
	/*
	 * Check to see if Sockets are supported on this system.  Since
	 * win32s panics if we call WSAStartup on a system that doesn't
	 * have winsock.dll, we need to look for it on the system first.
	 * If we find winsock, then load the library and initialize the
	 * stub table.
	 */
    
	if ((info.dwPlatformId != VER_PLATFORM_WIN32s)
		|| (SearchPathA(NULL, "WINSOCK", ".DLL", 0, NULL, NULL) != 0)) {
	    winSock.hInstance = LoadLibraryA("wsock32.dll");
	winSock.hInstance = LoadLibraryA("wsock32.dll");
	} else {
	    winSock.hInstance = NULL;
	}

    
	/*
	 * Initialize the function table.
	 */
    

	if (!SocketsEnabled()) {
	    return;
	}
    
	winSock.accept = (SOCKET (PASCAL FAR *)(SOCKET s,
		struct sockaddr FAR *addr, int FAR *addrlen))
	    GetProcAddress(winSock.hInstance, "accept");
1797
1798
1799
1800
1801
1802
1803
1804

1805
1806
1807
1808
1809
1810
1811
1776
1777
1778
1779
1780
1781
1782

1783
1784
1785
1786
1787
1788
1789
1790







-
+







    /*
     * Check that WinSock is initialized; do not call it if not, to
     * prevent system crashes. This can happen at exit time if the exit
     * handler for WinSock ran before other exit handlers that want to
     * use sockets.
     */

    if (! SocketsEnabled()) {
    if (!SocketsEnabled()) {
        *errorCodePtr = EFAULT;
        return -1;
    }

    /*
     * Check to see if the socket is connected before trying to write.
     */
2157
2158
2159
2160
2161
2162
2163
2164




2165

2166
2167
2168
2169
2170
2171
2172
2136
2137
2138
2139
2140
2141
2142

2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155







-
+
+
+
+

+







    if (tsdPtr->hwnd == NULL) {
	return 1;
    } else {
	/*
	 * store the tsdPtr, it's from a different thread, so it's
	 * not directly accessible, but needed.
	 */
	

#ifdef _WIN64
	SetWindowLongPtr(tsdPtr->hwnd, GWLP_USERDATA, (LONG) tsdPtr);
#else
	SetWindowLong(tsdPtr->hwnd, GWL_USERDATA, (LONG) tsdPtr);
#endif
    }

    while (1) {
	/*
	 * Process all outstanding messages on the socket window.
	 */

2204
2205
2206
2207
2208
2209
2210



2211
2212

2213
2214
2215
2216
2217
2218
2219
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197

2198
2199
2200
2201
2202
2203
2204
2205







+
+
+

-
+







    WPARAM wParam;
    LPARAM lParam;
{
    int event, error;
    SOCKET socket;
    SocketInfo *infoPtr;
    ThreadSpecificData *tsdPtr =
#ifdef _WIN64
	(ThreadSpecificData *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
#else
	(ThreadSpecificData *) GetWindowLong(hwnd, GWL_USERDATA);

#endif

    switch (message) {

	default:
	    return DefWindowProc(hwnd, message, wParam, lParam);
	    break;
	    
2295
2296
2297
2298
2299
2300
2301
2302

2303
2304
2305
2306
2307
2308
2309
2310
2281
2282
2283
2284
2285
2286
2287

2288

2289
2290
2291
2292
2293
2294
2295







-
+
-







		(void) (*winSock.WSAAsyncSelect)(infoPtr->socket, hwnd,
			SOCKET_MESSAGE, infoPtr->selectEvents);
	    } else {
		/*
		 * Clear the selection mask
		 */
		
		(void) (*winSock.WSAAsyncSelect)(infoPtr->socket, hwnd,
		(void) (*winSock.WSAAsyncSelect)(infoPtr->socket, hwnd, 0, 0);
			0, 0);
	    }
	    break;
	case SOCKET_TERMINATE:
	    ExitThread(0);
	    break;
    }