source: trunk/src/kernel32/npipe.cpp@ 2745

Last change on this file since 2745 was 2745, checked in by bird, 26 years ago

* empty log message *

File size: 20.9 KB
Line 
1/* $Id: npipe.cpp,v 1.6 2000-02-10 22:39:46 bird Exp $ */
2/*
3 * Win32 Named pipes API
4 *
5 * Copyright 1998 Sander van Leeuwen
6 * Copyright 2000 Przemyslaw Dobrowolski
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 */
10#include <odin.h>
11#include <odinwrap.h>
12#include <os2win.h>
13#include <stdlib.h>
14#include <unicode.h>
15#include <heapstring.h>
16#include <options.h>
17#include "debugtools.h"
18#include "oslibdos.h"
19
20ODINDEBUGCHANNEL(KERNEL32-NPIPE)
21
22//******************************************************************************
23//******************************************************************************
24ODINFUNCTION6(BOOL,PeekNamedPipe,HANDLE ,hPipe,
25 LPVOID ,lpvBuffer,
26 DWORD ,cbBuffer,
27 LPDWORD,lpcbRead,
28 LPDWORD,lpcbAvail,
29 LPDWORD,lpcbMessage)
30{
31 return(OSLibDosPeekNamedPipe(hPipe,lpvBuffer,cbBuffer,lpcbRead,lpcbAvail,lpcbMessage));
32}
33//******************************************************************************
34//LPSECURITY_ATTRIBUTES lpsa; /* address of security attributes */
35//******************************************************************************
36BOOL WIN32API CreatePipe(PHANDLE phRead, PHANDLE phWrite, LPSECURITY_ATTRIBUTES lpsa, DWORD cbPipe)
37{
38 dprintf(("CreatePipe Not Implemented!\n"));
39 return(FALSE);
40}
41//******************************************************************************
42//******************************************************************************
43ODINFUNCTION8(HANDLE,CreateNamedPipeA,LPCTSTR,lpName, DWORD,dwOpenMode, DWORD,dwPipeMode,
44 DWORD, nMaxInstances, DWORD, nOutBufferSize,
45 DWORD, nInBufferSize, DWORD, nDefaultTimeOut,
46 void*, lpSecurityAttributes)
47
48{
49 HANDLE hPipe;
50
51 hPipe = OSLibDosCreateNamedPipe(lpName,
52 dwOpenMode,
53 dwPipeMode,
54 nMaxInstances,
55 nOutBufferSize,
56 nInBufferSize,
57 nDefaultTimeOut,
58 lpSecurityAttributes);
59
60 return hPipe;
61
62}
63//******************************************************************************
64//******************************************************************************
65ODINFUNCTION8(HANDLE,CreateNamedPipeW,LPCWSTR,lpName, DWORD,dwOpenMode, DWORD,dwPipeMode,
66 DWORD, nMaxInstances, DWORD, nOutBufferSize,
67 DWORD, nInBufferSize, DWORD, nDefaultTimeOut,
68 void *,lpSecurityAttributes)
69{
70 char *asciiname;
71 HANDLE hPipe;
72
73 asciiname = UnicodeToAsciiString((LPWSTR)lpName);
74
75 hPipe=OSLibDosCreateNamedPipe(asciiname,
76 dwOpenMode,
77 dwPipeMode,
78 nMaxInstances,
79 nOutBufferSize,
80 nInBufferSize,
81 nDefaultTimeOut,
82 lpSecurityAttributes);
83
84 FreeAsciiString(asciiname);
85
86 return(hPipe);
87}
88//******************************************************************************
89//******************************************************************************
90
91
92/*****************************************************************************
93 * Name : BOOL WIN32API ConnectNamedPipe
94 * Purpose : The ConnectNamedPipe function enables a named pipe server process
95 * to wait for a client process to connect to an instance of a
96 * named pipe. A client process connects by calling either the
97 * CreateFile or CallNamedPipe function.
98 * Parameters: HANDLE hNamedPipe handle to named pipe to connect
99 * LPOVERLAPPED lpOverlapped pointer to overlapped structure
100 * Variables :
101 * Result : If the function succeeds, the return value is nonzero.
102 * If the function fails, the return value is zero.
103 * To get extended error information, call GetLastError.
104 * Remark :
105 * Status : NOT FULLY TESTED
106 *
107 * Author : Przemyslaw Dobrowolski [Sun, 2000/01/02 12:48]
108 *****************************************************************************/
109
110ODINFUNCTION2(BOOL,ConnectNamedPipe,HANDLE,hNamedPipe, LPOVERLAPPED,lpOverlapped)
111{
112 return (OSLibDosConnectNamedPipe(hNamedPipe,lpOverlapped));
113}
114
115/*****************************************************************************
116 * Name : BOOL WIN32AOI CallNamedPipeA
117 * Purpose : The CallNamedPipe function connects to a message-type pipe
118 * (and waits if an instance of the pipe is not available),
119 * writes to and reads from the pipe, and then closes the pipe.
120 * Parameters: LPCSTR lpNamedPipeName pointer to pipe name
121 * LPVOID lpInBuffer pointer to write buffer
122 * DWORD nInBufferSize size, in bytes, of write buffer
123 * LPVOID lpOutBuffer pointer to read buffer
124 * DWORD nOutBufferSize size, in bytes, of read buffer
125 * LPDWORD lpBytesRead pointer to number of bytes read
126 * DWORD nTimeOut time-out time, in milliseconds
127 * Variables :
128 * Result : If the function succeeds, the return value is nonzero.
129 * If the function fails, the return value is zero.
130 * To get extended error information, call GetLastError.
131 * Remark : Calling CallNamedPipe is equivalent to calling the CreateFile
132 * (or WaitNamedPipe, if CreateFile cannot open the pipe immediately),
133 * TransactNamedPipe, and CloseHandle functions. CreateFile is called
134 * with an access flag of GENERIC_READ | GENERIC_WRITE, an inherit
135 * handle flag of FALSE, and a share mode of zero (indicating no
136 * sharing of this pipe instance).
137 * If the message written to the pipe by the server process is
138 * longer than nOutBufferSize, CallNamedPipe returns FALSE, and
139 * GetLastError returns ERROR_MORE_DATA. The remainder of the
140 * message is discarded, because CallNamedPipe closes the handle
141 * to the pipe before returning.
142 *
143 * CallNamedPipe fails if the pipe is a byte-type pipe.
144 * Status : NOT FULLY TESTED
145 *
146 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 13:32]
147 *****************************************************************************/
148
149ODINFUNCTION7(BOOL,CallNamedPipeA,LPCSTR , lpNamedPipeName,
150 LPVOID , lpInBuffer,
151 DWORD , nInBufferSize,
152 LPVOID , lpOutBuffer,
153 DWORD , nOutBufferSize,
154 LPDWORD, lpBytesRead,
155 DWORD , nTimeOut)
156{
157 return(OSLibDosCallNamedPipe(lpNamedPipeName,
158 lpInBuffer,
159 nInBufferSize,
160 lpOutBuffer,
161 nOutBufferSize,
162 lpBytesRead,
163 nTimeOut ));
164}
165
166/*****************************************************************************
167 * Name : BOOL WIN32AOI CallNamedPipeW
168 * Purpose : The CallNamedPipe function connects to a message-type pipe
169 * (and waits if an instance of the pipe is not available),
170 * writes to and reads from the pipe, and then closes the pipe.
171 * Parameters: LPCWSTR lpNamedPipeName pointer to pipe name
172 * LPVOID lpInBuffer pointer to write buffer
173 * DWORD nInBufferSize size, in bytes, of write buffer
174 * LPVOID lpOutBuffer pointer to read buffer
175 * DWORD nOutBufferSize size, in bytes, of read buffer
176 * LPDWORD lpBytesRead pointer to number of bytes read
177 * DWORD nTimeOut time-out time, in milliseconds
178 * Variables :
179 * Result : If the function succeeds, the return value is nonzero.
180 * If the function fails, the return value is zero.
181 * To get extended error information, call GetLastError.
182 * Remark : Calling CallNamedPipe is equivalent to calling the CreateFile
183 * (or WaitNamedPipe, if CreateFile cannot open the pipe immediately),
184 * TransactNamedPipe, and CloseHandle functions. CreateFile is called
185 * with an access flag of GENERIC_READ | GENERIC_WRITE, an inherit
186 * handle flag of FALSE, and a share mode of zero (indicating no
187 * sharing of this pipe instance).
188 * If the message written to the pipe by the server process is
189 * longer than nOutBufferSize, CallNamedPipe returns FALSE, and
190 * GetLastError returns ERROR_MORE_DATA. The remainder of the
191 * message is discarded, because CallNamedPipe closes the handle
192 * to the pipe before returning.
193 *
194 * CallNamedPipe fails if the pipe is a byte-type pipe.
195 * Status : NOT FULLY TESTED
196 *
197 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 13:33]
198 *****************************************************************************/
199ODINFUNCTION7(BOOL,CallNamedPipeW,LPCWSTR , lpNamedPipeName,
200 LPVOID , lpInBuffer,
201 DWORD , nInBufferSize,
202 LPVOID , lpOutBuffer,
203 DWORD , nOutBufferSize,
204 LPDWORD, lpBytesRead,
205 DWORD , nTimeOut)
206{
207 char *asciiname;
208 BOOL rc;
209
210 asciiname = UnicodeToAsciiString((LPWSTR)lpNamedPipeName);
211
212 rc=OSLibDosCallNamedPipe(asciiname,
213 lpInBuffer,
214 nInBufferSize,
215 lpOutBuffer,
216 nOutBufferSize,
217 lpBytesRead,
218 nTimeOut );
219
220 FreeAsciiString(asciiname);
221
222 return(rc);
223}
224/*****************************************************************************
225 * Name : BOOL WIN32API DisconnectNamedPipe
226 * Purpose : The DisconnectNamedPipe function disconnects the server end
227 * of a named pipe instance from a client process.
228 * Parameters: HANDLE hNamedPipe handle to named pipe
229 * Variables :
230 * Result : If the function succeeds, the return value is nonzero.
231 * If the function fails, the return value is zero
232 * Remark :
233 * Status : NOT FULLY TESTED
234 *
235 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 13:34]
236 *****************************************************************************/
237
238ODINFUNCTION1(BOOL,DisconnectNamedPipe,HANDLE,hNamedPipe)
239{
240 return (OSLibDosDisconnectNamedPipe(hNamedPipe));
241}
242
243/*****************************************************************************
244 * Name : BOOL GetNamedPipeHandleStateA
245 * Purpose : The GetNamedPipeHandleStateA function retrieves information about
246 * a specified named pipe. The information returned can vary during
247 * the lifetime of an instance of the named pipe.
248 * Parameters: HANDLE hNamedPipe handle of named pipe
249 * LPDWORD lpState address of flags indicating pipe state
250 * LPDWORD lpCurInstances address of number of current pipe instances
251 * LPDWORD lpMaxCollectionCount address of max. bytes before remote transmission
252 * LPDWORD lpCollectDataTimeout address of max. time before remote transmission
253 * LPTSTR lpUserName address of user name of client process
254 * DWORD nMaxUserNameSize size, in characters, of user name buffer
255 * Variables :
256 * Result : TRUE / FALSE
257 * Remark :
258 * Status : UNTESTED STUB
259 *
260 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
261 *****************************************************************************/
262
263BOOL WIN32API GetNamedPipeHandleStateA(HANDLE hNamedPipe,
264 LPDWORD lpState,
265 LPDWORD lpCurInstances,
266 LPDWORD lpMaxCollectionCount,
267 LPDWORD lpCollectDataTimeout,
268 LPTSTR lpUserName,
269 DWORD nMaxUserNameSize)
270{
271 dprintf(("KERNEL32: GetNamedPipeHandleStateA(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%08xh) not implemented (yet)\n",
272 hNamedPipe,
273 lpState,
274 lpCurInstances,
275 lpMaxCollectionCount,
276 lpCollectDataTimeout,
277 lpUserName,
278 nMaxUserNameSize));
279
280 return (FALSE);
281}
282
283
284/*****************************************************************************
285 * Name : BOOL GetNamedPipeHandleStateW
286 * Purpose : The GetNamedPipeHandleStateW function retrieves information about
287 * a specified named pipe. The information returned can vary during
288 * the lifetime of an instance of the named pipe.
289 * Parameters: HANDLE hNamedPipe handle of named pipe
290 * LPDWORD lpState address of flags indicating pipe state
291 * LPDWORD lpCurInstances address of number of current pipe instances
292 * LPDWORD lpMaxCollectionCount address of max. bytes before remote transmission
293 * LPDWORD lpCollectDataTimeout address of max. time before remote transmission
294 * LPWSTR lpUserName address of user name of client process
295 * DWORD nMaxUserNameSize size, in characters, of user name buffer
296 * Variables :
297 * Result : TRUE / FALSE
298 * Remark :
299 * Status : UNTESTED STUB
300 *
301 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
302 *****************************************************************************/
303
304BOOL WIN32API GetNamedPipeHandleStateW(HANDLE hNamedPipe,
305 LPDWORD lpState,
306 LPDWORD lpCurInstances,
307 LPDWORD lpMaxCollectionCount,
308 LPDWORD lpCollectDataTimeout,
309 LPWSTR lpUserName,
310 DWORD nMaxUserNameSize)
311{
312 dprintf(("KERNEL32: GetNamedPipeHandleStateW(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%08xh) not implemented\n",
313 hNamedPipe,
314 lpState,
315 lpCurInstances,
316 lpMaxCollectionCount,
317 lpCollectDataTimeout,
318 lpUserName,
319 nMaxUserNameSize));
320
321 return (FALSE);
322}
323
324
325/*****************************************************************************
326 * Name : BOOL GetNamedPipeInfo
327 * Purpose : The GetNamedPipeInfo function retrieves information about the specified named pipe.
328 * Parameters: HANDLE hNamedPipe handle of named pipe
329 * LPDWORD lpFlags address of flags indicating type of pipe
330 * LPDWORD lpOutBufferSize address of size, in bytes, of pipe's output buffer
331 * LPDWORD lpInBufferSize address of size, in bytes, of pipe's input buffer
332 * LPDWORD lpMaxInstances address of max. number of pipe instances
333 * Variables :
334 * Result : TRUE / FALSE
335 * Remark :
336 * Status : UNTESTED STUB
337 *
338 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
339 *****************************************************************************/
340
341BOOL WIN32API GetNamedPipeInfo(HANDLE hNamedPipe,
342 LPDWORD lpFlags,
343 LPDWORD lpOutBufferSize,
344 LPDWORD lpInBufferSize,
345 LPDWORD lpMaxInstances)
346{
347 dprintf(("KERNEL32: GetNamedPipeInfo(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented\n",
348 hNamedPipe,
349 lpFlags,
350 lpOutBufferSize,
351 lpInBufferSize,
352 lpMaxInstances));
353
354 return (FALSE);
355}
356
357/*****************************************************************************
358 * Name : BOOL SetNamedPipeHandleState
359 * Purpose : The SetNamedPipeHandleState function sets the read mode and the
360 * blocking mode of the specified named pipe. If the specified handle
361 * is to the client end of a named pipe and if the named pipe server
362 * process is on a remote computer, the function can also be used to
363 * control local buffering.
364 * Parameters: HANDLE hNamedPipe handle of named pipe
365 * LPDWORD lpdwMode address of new pipe mode
366 * LPDWORD lpcbMaxCollect address of max. bytes before remote transmission
367 * LPDWORD lpdwCollectDataTimeout address of max. time before remote transmission
368 * Variables :
369 * Result : TRUE / FALSE
370 * Remark :
371 * Status : UNTESTED STUB
372 *
373 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
374 *****************************************************************************/
375
376BOOL WIN32API SetNamedPipeHandleState(HANDLE hNamedPipe,
377 LPDWORD lpdwMode,
378 LPDWORD lpcbMaxCollect,
379 LPDWORD lpdwCollectDataTimeout)
380{
381 dprintf(("KERNEL32: SetNamedPipeHandleState(%08xh,%08xh,%08xh,%08xh) not implemented.\n",
382 hNamedPipe,
383 lpdwMode,
384 lpcbMaxCollect,
385 lpdwCollectDataTimeout));
386
387 return (FALSE);
388}
389
390/*****************************************************************************
391 * Name : DWORD TransactNamedPipe
392 * Purpose : The TransactNamedPipe function combines into a single network
393 * operation the functions that write a message to and read a
394 * message from the specified named pipe.
395 * Parameters: HANDLE hNamedPipe handle of named pipe
396 * LPVOID lpvWriteBuf address of write buffer
397 * DWORD cbWriteBuf size of the write buffer, in bytes
398 * LPVOID lpvReadBuf address of read buffer
399 * DWORD cbReadBuf size of read buffer, in bytes
400 * LPDWORD lpcbRead address of variable for bytes actually read
401 * LPOVERLAPPED lpo address of overlapped structure
402 * Variables :
403 * Result : TRUE / FALSE
404 * Remark :
405 * Status : NOT FULLY TESTED (YET!)
406 *
407 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 08:48]
408 *****************************************************************************/
409
410ODINFUNCTION7(DWORD,TransactNamedPipe,HANDLE,hNamedPipe,
411 LPVOID,lpvWriteBuf,
412 DWORD,cbWriteBuf,
413 LPVOID,lpvReadBuf,
414 DWORD,cbReadBuf,
415 LPDWORD,lpcbRead,
416 LPOVERLAPPED,lpo)
417{
418 return(OSLibDosTransactNamedPipe( hNamedPipe,
419 lpvWriteBuf,
420 cbWriteBuf,
421 lpvReadBuf,
422 cbReadBuf,
423 lpcbRead,
424 lpo));
425
426}
427
428/*****************************************************************************
429 * Name : BOOL WaitNamedPipeA
430 * Purpose : The WaitNamedPipe function waits until either a time-out interval
431 * elapses or an instance of the specified named pipe is available
432 * to be connected to (that is, the pipe's server process has a
433 * pending ConnectNamedPipe operation on the pipe).
434 * Parameters: LPCTSTR lpszNamedPipeName
435 * DWORD dwTimeout
436 * Variables :
437 * Result : TRUE / FALSE
438 * Remark :
439 * Status : UNTESTED (YET)
440 *
441 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 13:52]
442 *****************************************************************************/
443
444ODINFUNCTION2(BOOL,WaitNamedPipeA,LPCSTR,lpszNamedPipeName, DWORD, dwTimeout)
445{
446 return(OSLibDosWaitNamedPipe(lpszNamedPipeName, dwTimeout));
447}
448
449
450/*****************************************************************************
451 * Name : BOOL WaitNamedPipeW
452 * Purpose : The WaitNamedPipe function waits until either a time-out interval
453 * elapses or an instance of the specified named pipe is available
454 * to be connected to (that is, the pipe's server process has a
455 * pending ConnectNamedPipe operation on the pipe).
456 * Parameters: LPCWSTR lpszNamedPipeName
457 * DWORD dwTimeout
458 * Variables :
459 * Result : TRUE / FALSE
460 * Remark :
461 * Status : UNTESTED (YET)
462 *
463 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 13:44]
464 *****************************************************************************/
465
466ODINFUNCTION2(BOOL,WaitNamedPipeW,LPCWSTR,lpszNamedPipeName, DWORD, dwTimeout)
467{
468 char *asciiname;
469 DWORD rc;
470
471 asciiname = UnicodeToAsciiString((LPWSTR)lpszNamedPipeName);
472
473 rc=OSLibDosWaitNamedPipe(asciiname, dwTimeout);
474
475 FreeAsciiString(asciiname);
476
477 return(rc);
478}
Note: See TracBrowser for help on using the repository browser.