Diff
Not logged in

Differences From Artifact [9cd2479cad]:

To Artifact [2cc10c31c2]:


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.36 2003/01/16 19:02:00 mdejong Exp $
 * RCS: @(#) $Id: tclWinSock.c,v 1.37 2003/04/22 23:20:44 andreas_kupries Exp $
 */

#include "tclWinInt.h"

/*
 * Make sure to remove the redirection defines set in tclWinPort.h
 * that is in use in other sections of the core, except for us.
1029
1030
1031
1032
1033
1034
1035

1036
1037
1038
1039
1040
1041
1042

1043
1044
1045
1046
1047
1048
1049
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051







+







+







NewSocketInfo(socket)
    SOCKET socket;
{
    SocketInfo *infoPtr;
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    infoPtr = (SocketInfo *) ckalloc((unsigned) sizeof(SocketInfo));
    infoPtr->channel = 0;
    infoPtr->socket = socket;
    infoPtr->flags = 0;
    infoPtr->watchEvents = 0;
    infoPtr->readyEvents = 0;
    infoPtr->selectEvents = 0;
    infoPtr->acceptEventCount = 0;
    infoPtr->acceptProc = NULL;
    infoPtr->acceptProcData = NULL;
    infoPtr->lastError = 0;

    WaitForSingleObject(tsdPtr->socketListLock, INFINITE);
    infoPtr->nextPtr = tsdPtr->socketList;
    tsdPtr->socketList = infoPtr;
    SetEvent(tsdPtr->socketListLock);
    
2652
2653
2654
2655
2656
2657
2658

































































































































2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
        return (struct servent *) NULL;
    }

    return winSock.getservbyname(name, proto);
}



/*
 *----------------------------------------------------------------------
 *
 * TclpCutSockChannel --
 *
 *	Remove any thread local refs to this channel. See
 *	Tcl_CutChannel for more info.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Changes thread local list of valid channels.
 *
 *----------------------------------------------------------------------
 */

void
TclpCutSockChannel(chan)
    Tcl_Channel chan;			/* The channel being removed. Must
                                         * not be referenced in any
                                         * interpreter. */
{
    ThreadSpecificData *tsdPtr;
    SocketInfo *infoPtr;
    SocketInfo **nextPtrPtr;
    int removed = 0;

    if (Tcl_GetChannelType(chan) != &tcpChannelType)
        return;

    /*
     * The initializtion of tsdPtr _after_ we have determined that we
     * are dealing with socket is necessary. Doing it before causes
     * the module to access th tdsPtr when it is not initialized yet,
     * causing a lockup.
     */

    tsdPtr  = TCL_TSD_INIT(&dataKey);
    infoPtr = (SocketInfo *) Tcl_GetChannelInstanceData (chan);

    for (nextPtrPtr = &(tsdPtr->socketList); (*nextPtrPtr) != NULL;
	 nextPtrPtr = &((*nextPtrPtr)->nextPtr)) {
	if ((*nextPtrPtr) == infoPtr) {
	    (*nextPtrPtr) = infoPtr->nextPtr;
	    removed = 1;
	    break;
	}
    }

    /*
     * This could happen if the channel was created in one thread
     * and then moved to another without updating the thread
     * local data in each thread.
     */

    if (!removed) {
        panic("file info ptr not on thread channel list");
    }

    /*
     * Stop notifications for the socket to occur in this thread.
     */

    SendMessage(tsdPtr->hwnd, SOCKET_SELECT,
		(WPARAM) UNSELECT, (LPARAM) infoPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * TclpSpliceSockChannel --
 *
 *	Insert thread local ref for this channel.
 *	Tcl_SpliceChannel for more info.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Changes thread local list of valid channels.
 *
 *----------------------------------------------------------------------
 */

void
TclpSpliceSockChannel(chan)
    Tcl_Channel chan;			/* The channel being removed. Must
                                         * not be referenced in any
                                         * interpreter. */
{
    ThreadSpecificData *tsdPtr;
    SocketInfo *infoPtr;

    if (Tcl_GetChannelType(chan) != &tcpChannelType)
        return;

    /*
     * Ensure that socket subsystem is initialized in this thread, or
     * else sockets will not work.
     */

    Tcl_MutexLock(&socketMutex);
    InitSockets();
    Tcl_MutexUnlock(&socketMutex);

    /*
     * The initializtion of tsdPtr _after_ we have determined that we
     * are dealing with socket is necessary. Doing it before causes
     * the module to access th tdsPtr when it is not initialized yet,
     * causing a lockup.
     */

    tsdPtr  = TCL_TSD_INIT(&dataKey);
    infoPtr = (SocketInfo *) Tcl_GetChannelInstanceData (chan);

    WaitForSingleObject(tsdPtr->socketListLock, INFINITE);
    infoPtr->nextPtr = tsdPtr->socketList;
    tsdPtr->socketList = infoPtr;
    SetEvent(tsdPtr->socketListLock);

    /*
     * Ensure that notifications for the socket occur in this thread.
     */

    SendMessage(tsdPtr->hwnd, SOCKET_SELECT,
		(WPARAM) SELECT, (LPARAM) infoPtr);
}