- New winsock (part 3 of x)
[reactos.git] / dll / win32 / ws2_32_new / src / bhook.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
4 * FILE: bhook.c
5 * PURPOSE: Blocking Hook support for 1.x clients
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9 /* INCLUDES ******************************************************************/
10 #include "ws2_32.h"
11
12 //#define NDEBUG
13 #include <debug.h>
14
15 /* DATA **********************************************************************/
16
17 /* FUNCTIONS *****************************************************************/
18
19 /*
20 * @implemented
21 */
22 INT
23 WSAAPI
24 WSACancelBlockingCall(VOID)
25 {
26 PWSPROCESS Process;
27 PWSTHREAD Thread;
28 INT ErrorCode;
29 DPRINT("WSACancelBlockingCall\n");
30
31 /* Call the prolog */
32 ErrorCode = WsApiProlog(&Process, &Thread);
33 if (ErrorCode != ERROR_SUCCESS)
34 {
35 /* Fail */
36 SetLastError(ErrorCode);
37 return SOCKET_ERROR;
38 }
39
40 /* Make sure this isn't a 2.2 client */
41 if (LOBYTE(Process->Version) >= 2)
42 {
43 /* Only valid for 1.x */
44 SetLastError(WSAEOPNOTSUPP);
45 return SOCKET_ERROR;
46 }
47
48 /* Cancel the call */
49 ErrorCode = WsThreadCancelBlockingCall(Thread);
50 if (ErrorCode != ERROR_SUCCESS)
51 {
52 /* Fail */
53 SetLastError(ErrorCode);
54 return ErrorCode;
55 }
56
57 /* Return success */
58 return ERROR_SUCCESS;
59 }
60
61 /*
62 * @implemented
63 */
64 BOOL
65 WSAAPI
66 WSAIsBlocking(VOID)
67 {
68 PWSPROCESS Process;
69 PWSTHREAD Thread;
70 INT ErrorCode;
71 DPRINT("WSAIsBlocking\n");
72
73 /* Call the prolog */
74 ErrorCode = WsApiProlog(&Process, &Thread);
75 if (ErrorCode != ERROR_SUCCESS)
76 {
77 /* Fail unless its because we're busy */
78 if (ErrorCode != WSAEINPROGRESS) return FALSE;
79 }
80
81 /* Return the value from the thread */
82 return Thread->Blocking;
83 }
84
85 /*
86 * @implemented
87 */
88 FARPROC
89 WSAAPI
90 WSASetBlockingHook(IN FARPROC lpBlockFunc)
91 {
92 PWSPROCESS Process;
93 PWSTHREAD Thread;
94 INT ErrorCode;
95 DPRINT("WSASetBlockingHook: %p\n", lpBlockFunc);
96
97 /* Call the prolog */
98 ErrorCode = WsApiProlog(&Process, &Thread);
99 if (ErrorCode != ERROR_SUCCESS)
100 {
101 /* Fail */
102 SetLastError(ErrorCode);
103 return NULL;
104 }
105
106 /* Make sure this isn't a 2.2 client */
107 if (LOBYTE(Process->Version) >= 2)
108 {
109 /* Only valid for 1.x */
110 SetLastError(WSAEOPNOTSUPP);
111 return NULL;
112 }
113
114 /* Make sure the pointer is safe */
115 if (IsBadCodePtr(lpBlockFunc))
116 {
117 /* Invalid pointer */
118 SetLastError(WSAEFAULT);
119 return NULL;
120 }
121
122 /* Set the blocking hook and return the previous one */
123 return WsThreadSetBlockingHook(Thread, lpBlockFunc);
124 }
125
126 /*
127 * @implemented
128 */
129 INT
130 WSAAPI
131 WSAUnhookBlockingHook(VOID)
132 {
133 PWSPROCESS Process;
134 PWSTHREAD Thread;
135 INT ErrorCode;
136 DPRINT("WSAUnhookBlockingHook\n");
137
138 /* Call the prolog */
139 ErrorCode = WsApiProlog(&Process, &Thread);
140 if (ErrorCode != ERROR_SUCCESS)
141 {
142 /* Fail */
143 SetLastError(ErrorCode);
144 return SOCKET_ERROR;
145 }
146
147 /* Make sure this isn't a 2.2 client */
148 if (LOBYTE(Process->Version) >= 2)
149 {
150 /* Only valid for 1.x */
151 SetLastError(WSAEOPNOTSUPP);
152 return SOCKET_ERROR;
153 }
154
155 /* Set the blocking hook and return the previous one */
156 return WsThreadUnhookBlockingHook(Thread);
157 }