- New implementation of SendMessage, ReceiveMessage, ReplyMessage functions
[wine] / scheduler / pipe.c
1 /*
2  * Win32 pipes
3  *
4  * Copyright 1998 Alexandre Julliard
5  */
6
7 #include <assert.h>
8 #include "windows.h"
9 #include "winerror.h"
10 #include "k32obj.h"
11 #include "process.h"
12 #include "thread.h"
13 #include "heap.h"
14 #include "server/request.h"
15 #include "server.h"
16
17 typedef struct _PIPE
18 {
19     K32OBJ         header;
20 } PIPE;
21
22
23 /***********************************************************************
24  *      CreatePipe    (KERNEL32.170)
25  */
26 BOOL32 WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe,
27                           LPSECURITY_ATTRIBUTES sa, DWORD size )
28 {
29     struct create_pipe_request req;
30     struct create_pipe_reply reply;
31     PIPE *read_pipe, *write_pipe;
32     int len;
33
34     req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
35     CLIENT_SendRequest( REQ_CREATE_PIPE, -1, 1, &req, sizeof(req) );
36     if (CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) ) != ERROR_SUCCESS)
37         return FALSE;
38
39     SYSTEM_LOCK();
40     if (!(read_pipe = (PIPE *)K32OBJ_Create( K32OBJ_PIPE, sizeof(*read_pipe),
41                                              NULL, reply.handle_read,
42                                              STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ,
43                                              sa, hReadPipe )))
44     {
45         CLIENT_CloseHandle( reply.handle_write );
46         /* handle_read already closed by K32OBJ_Create */
47         SYSTEM_UNLOCK();
48         return FALSE;
49     }
50     K32OBJ_DecCount( &read_pipe->header );
51     if (!(write_pipe = (PIPE *)K32OBJ_Create( K32OBJ_PIPE, sizeof(*write_pipe),
52                                               NULL, reply.handle_write,
53                                               STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE,
54                                               sa, hWritePipe )))
55     {
56         CloseHandle( *hReadPipe );
57         *hReadPipe = INVALID_HANDLE_VALUE32;
58         SYSTEM_UNLOCK();
59         return FALSE;
60     }
61     /* everything OK */
62     K32OBJ_DecCount( &write_pipe->header );
63     SetLastError(0); /* FIXME */
64     SYSTEM_UNLOCK();
65     return TRUE;
66 }