5
* --------------------------------------------------------------------------
7
* Pthreads-win32 - POSIX Threads Library for Win32
8
* Copyright(C) 1998 John E. Bossom
9
* Copyright(C) 1999,2005 Pthreads-win32 contributors
11
* Contact Email: rpj@callisto.canberra.edu.au
13
* The current list of contributors is contained
14
* in the file CONTRIBUTORS included with the source
15
* code distribution. The list can also be seen at the
16
* following World Wide Web location:
17
* http://sources.redhat.com/pthreads-win32/contributors.html
19
* This library is free software; you can redistribute it and/or
20
* modify it under the terms of the GNU Lesser General Public
21
* License as published by the Free Software Foundation; either
22
* version 2 of the License, or (at your option) any later version.
24
* This library is distributed in the hope that it will be useful,
25
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
* Lesser General Public License for more details.
29
* You should have received a copy of the GNU Lesser General Public
30
* License along with this library in the file COPYING.LIB;
31
* if not, write to the Free Software Foundation, Inc.,
32
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
34
* --------------------------------------------------------------------------
36
* Test Synopsis: Test true asynchronous cancelation with Alert driver.
38
* Test Method (Validation or Falsification):
41
* Requirements Tested:
42
* - Cancel threads, including those blocked on system recources
43
* such as network I/O.
61
* - File name, Line number, and failed expression on failure.
62
* - No output on success.
65
* - have working pthread_create, pthread_self, pthread_mutex_lock/unlock
66
* pthread_testcancel, pthread_cancel, pthread_join
69
* - Process returns zero exit status.
72
* - Process returns non-zero exit status.
82
struct sockaddr_in serverAddress;
83
struct sockaddr_in clientAddress;
88
WORD wsaVersion = MAKEWORD (2, 2);
91
pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
92
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
94
if (WSAStartup (wsaVersion, &wsaData) != 0)
99
UDPSocket = socket (AF_INET, SOCK_DGRAM, 0);
100
if ((int)UDPSocket == -1)
102
printf ("Server: socket ERROR \n");
106
serverAddress.sin_family = AF_INET;
107
serverAddress.sin_addr.s_addr = INADDR_ANY;
108
serverAddress.sin_port = htons (9003);
111
(UDPSocket, (struct sockaddr *) &serverAddress,
112
sizeof (struct sockaddr_in)))
114
printf ("Server: ERROR can't bind UDPSocket");
118
addr_len = sizeof (struct sockaddr);
123
recvfrom (UDPSocket, (char *) buffer, nbyte, 0,
124
(struct sockaddr *) &clientAddress, &addr_len);
126
closesocket (UDPSocket);
134
test_sleep (void *arg)
136
pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
137
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
145
test_wait (void *arg)
150
pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
151
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
153
hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
155
dwEvent = WaitForSingleObject (hEvent, 1000); /* WAIT_IO_COMPLETION */
167
if (pthread_win32_test_features_np (PTW32_ALERTABLE_ASYNC_CANCEL))
169
printf ("Cancel sleeping thread.\n");
170
assert (pthread_create (&t, NULL, test_sleep, NULL) == 0);
171
/* Sleep for a while; then cancel */
173
assert (pthread_cancel (t) == 0);
174
assert (pthread_join (t, &result) == 0);
175
assert (result == PTHREAD_CANCELED && "test_sleep" != NULL);
177
printf ("Cancel waiting thread.\n");
178
assert (pthread_create (&t, NULL, test_wait, NULL) == 0);
179
/* Sleep for a while; then cancel. */
181
assert (pthread_cancel (t) == 0);
182
assert (pthread_join (t, &result) == 0);
183
assert (result == PTHREAD_CANCELED && "test_wait");
185
printf ("Cancel blocked thread (blocked on network I/O).\n");
186
assert (pthread_create (&t, NULL, test_udp, NULL) == 0);
187
/* Sleep for a while; then cancel. */
189
assert (pthread_cancel (t) == 0);
190
assert (pthread_join (t, &result) == 0);
191
assert (result == PTHREAD_CANCELED && "test_udp" != NULL);
195
printf ("Alertable async cancel not available.\n");