Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmxmlrpc / xmlrpc_transport.c
blob3ae6e69b99fe846306d9d2fc613f60a07f9218c0
1 /* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 ** 1. Redistributions of source code must retain the above copyright
7 ** notice, this list of conditions and the following disclaimer.
8 ** 2. Redistributions in binary form must reproduce the above copyright
9 ** notice, this list of conditions and the following disclaimer in the
10 ** documentation and/or other materials provided with the distribution.
11 ** 3. The name of the author may not be used to endorse or promote products
12 ** derived from this software without specific prior written permission.
13 **
14 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 ** SUCH DAMAGE. */
26 #include "xmlrpc_config.h"
28 #undef PACKAGE
29 #undef VERSION
31 #include <stddef.h>
32 #include <string.h>
33 #include <stdlib.h>
35 #ifdef WIN32
36 #ifdef _DEBUG
37 # include <crtdbg.h>
38 # define new DEBUG_NEW
39 # define malloc(size) _malloc_dbg( size, _NORMAL_BLOCK, __FILE__, __LINE__)
40 # undef THIS_FILE
41 static char THIS_FILE[] = __FILE__;
42 #endif
43 #endif /*WIN32*/
45 #include "xmlrpc.h"
46 #include "xmlrpc_client.h"
48 #if defined (WIN32)
49 #include <process.h>
50 #endif
52 /* For debugging the xmlrpc_transport threading. */
53 /* #define tdbg_printf printf */
54 #define tdbg_printf (void *)
56 /* Lacking from the abyss/thread.c implimentaion. */
57 void wait_for_asynch_thread(pthread_t *thread)
59 #if WIN32
60 unsigned long milliseconds = INFINITE;
61 switch (WaitForSingleObject (
62 *thread /* handle to object to wait for */,
63 milliseconds /* time-out interval in milliseconds*/) )
65 /* One may want to handle these cases */
66 case WAIT_OBJECT_0:
67 case WAIT_TIMEOUT:
68 break;
70 #else
71 void * result;
72 int success;
73 success = pthread_join (*thread, &result);
74 #endif
77 /* MRB-WARNING: Only call when you have successfully
78 ** acquired the Lock/Unlock mutex! */
79 void unregister_asynch_thread (running_thread_list *list, pthread_t *thread)
81 running_thread_info * pCur = NULL;
82 XMLRPC_ASSERT_PTR_OK(thread);
83 XMLRPC_ASSERT_PTR_OK(list);
85 tdbg_printf("unregister_asynch_thread: &pthread_id = %08X *(%08X)\n", thread, *thread);
86 /* Removal */
87 /* Lock (); */
88 for (pCur = list->AsyncThreadHead; pCur != NULL; pCur = (running_thread_info *)pCur->Next)
90 if (pCur->_thread == *thread)
92 if (pCur == list->AsyncThreadHead)
93 list->AsyncThreadHead = pCur->Next;
94 if (pCur == list->AsyncThreadTail)
95 list->AsyncThreadTail = pCur->Last;
96 if (pCur->Last)
97 ((running_thread_info *)(pCur->Last))->Next = pCur->Next;
98 if (pCur->Next)
99 ((running_thread_info *)(pCur->Next))->Last = pCur->Last;
100 /* Free malloc'd running_thread_info */
101 free (pCur);
102 return;
106 /* This is a serious progmatic error, since the thread
107 ** should be in that list! */
108 XMLRPC_ASSERT_PTR_OK(0x0000);
110 /* Unlock (); */
113 /* MRB-WARNING: Only call when you have successfully
114 ** acquired the Lock/Unlock mutex! */
115 void register_asynch_thread (running_thread_list *list, pthread_t *thread)
117 running_thread_info* info = (running_thread_info *) malloc(sizeof(running_thread_info));
119 XMLRPC_ASSERT_PTR_OK(thread);
120 XMLRPC_ASSERT_PTR_OK(list);
122 tdbg_printf("register_asynch_thread: &pthread_id = %08X *(%08X)\n", thread, *thread);
124 info->_thread = *thread;
126 /* Insertion */
127 /* Lock (); */
128 if (list->AsyncThreadHead == NULL)
130 list->AsyncThreadHead = list->AsyncThreadTail = info;
131 list->AsyncThreadTail->Next = list->AsyncThreadHead->Next = NULL;
132 list->AsyncThreadTail->Last = list->AsyncThreadHead->Last = NULL;
134 else
136 info->Last = list->AsyncThreadTail;
137 list->AsyncThreadTail->Next = info;
138 list->AsyncThreadTail = list->AsyncThreadTail->Next;
139 list->AsyncThreadTail->Next = NULL;
141 /* Unlock (); */