xref: /AOO41X/main/sal/osl/os2/pipe.cxx (revision 87d2adbc9cadf14644c3679b041b9226f7630199)
1*87d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*87d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*87d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*87d2adbcSAndrew Rist  * distributed with this work for additional information
6*87d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*87d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*87d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
9*87d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*87d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*87d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*87d2adbcSAndrew Rist  * software distributed under the License is distributed on an
15*87d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*87d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*87d2adbcSAndrew Rist  * specific language governing permissions and limitations
18*87d2adbcSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*87d2adbcSAndrew Rist  *************************************************************/
21*87d2adbcSAndrew Rist 
22*87d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir //#define INCL_DOSERRORS
25cdf0e10cSrcweir #include "system.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <osl/pipe.h>
28cdf0e10cSrcweir #include <osl/diagnose.h>
29cdf0e10cSrcweir #include <osl/thread.h>
30cdf0e10cSrcweir #include <osl/mutex.h>
31cdf0e10cSrcweir #include <osl/semaphor.h>
32cdf0e10cSrcweir #include <osl/conditn.h>
33cdf0e10cSrcweir #include <osl/interlck.h>
34cdf0e10cSrcweir #include <osl/process.h>
35cdf0e10cSrcweir #include <rtl/ustring.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #define PIPENAMEMASK	"OSL_PIPE_%s"
38cdf0e10cSrcweir #define SECPIPENAMEMASK	"OSL_PIPE_%s_%s"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir typedef enum {
41cdf0e10cSrcweir 	MSG_SYN,
42cdf0e10cSrcweir 	MSG_FIN,
43cdf0e10cSrcweir 	MSG_DATA,
44cdf0e10cSrcweir 	MSG_UNKNOWN
45cdf0e10cSrcweir } MessageType;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir struct oslPipeImpl {
48cdf0e10cSrcweir 	oslInterlockedCount m_Reference;
49cdf0e10cSrcweir     HPIPE  				hPipe;
50cdf0e10cSrcweir 	HMTX				m_NamedObject;
51cdf0e10cSrcweir     APIRET 				nLastError;
52cdf0e10cSrcweir     //oslSecurity  		m_Security;
53cdf0e10cSrcweir 	sal_Bool            m_bClosed;
54cdf0e10cSrcweir };
55cdf0e10cSrcweir 
56cdf0e10cSrcweir /* default size for input/output buffer */
57cdf0e10cSrcweir static const ULONG ulBufSize = 4096;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir /* OS/2 path for pipes */
60cdf0e10cSrcweir static const CHAR  pszPipePath[] = "\\PIPE\\";
61cdf0e10cSrcweir static const UCHAR nPipePathLen  = sizeof (pszPipePath) - 1;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /* global last error value to be returned from oslGetLastPipeError */
64cdf0e10cSrcweir static APIRET ngLastError;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir using rtl::OString;
67cdf0e10cSrcweir using rtl::OUString;
68cdf0e10cSrcweir using rtl::OUStringToOString;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir /*****************************************************************************/
71cdf0e10cSrcweir /* osl_create/destroy-PipeImpl */
72cdf0e10cSrcweir /*****************************************************************************/
73cdf0e10cSrcweir 
74cdf0e10cSrcweir static oslInterlockedCount nPipes = 0;
75cdf0e10cSrcweir 
__osl_createPipeImpl(void)76cdf0e10cSrcweir oslPipe __osl_createPipeImpl(void)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	oslPipe pPipe;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	pPipe = (oslPipe) calloc(1,sizeof(struct oslPipeImpl));
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	pPipe->m_bClosed = sal_False;
83cdf0e10cSrcweir 	pPipe->m_Reference = 1;
84cdf0e10cSrcweir 	pPipe->hPipe = NULL;
85cdf0e10cSrcweir 	pPipe->m_NamedObject = NULL;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	return pPipe;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
__osl_destroyPipeImpl(oslPipe pPipe)90cdf0e10cSrcweir void __osl_destroyPipeImpl(oslPipe pPipe)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	if (pPipe != NULL)
93cdf0e10cSrcweir 	{
94cdf0e10cSrcweir 		DosCloseMutexSem( pPipe->m_NamedObject);
95cdf0e10cSrcweir 		free(pPipe);
96cdf0e10cSrcweir 	}
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
100cdf0e10cSrcweir /*****************************************************************************/
101cdf0e10cSrcweir /* osl_createPipe  */
102cdf0e10cSrcweir /*****************************************************************************/
osl_createPipe(rtl_uString * ustrPipeName,oslPipeOptions Options,oslSecurity Security)103cdf0e10cSrcweir oslPipe SAL_CALL osl_createPipe(rtl_uString *ustrPipeName, oslPipeOptions Options,
104cdf0e10cSrcweir 					   oslSecurity Security)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     oslPipe pPipe;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     ULONG  ulAction;
109cdf0e10cSrcweir     CHAR   strPipeNameBuffer [CCHMAXPATHCOMP];
110cdf0e10cSrcweir 	rtl_String* strPipeName=0;
111cdf0e10cSrcweir 	sal_Char* pszPipeName=0;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     /* check parameters */
114cdf0e10cSrcweir     OSL_ASSERT( ustrPipeName );
115cdf0e10cSrcweir     //YD 17/04/06 OSL_ASSERT( Security == 0 );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /* allocate impl-structure */
118cdf0e10cSrcweir     pPipe = __osl_createPipeImpl();
119cdf0e10cSrcweir     if (!pPipe)
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         OSL_TRACE( "osl_createPipe failed allocating memory.\n" );
122cdf0e10cSrcweir         return NULL;
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     /* create pipe name */
126cdf0e10cSrcweir     OString sPipe = OUStringToOString(ustrPipeName, RTL_TEXTENCODING_ASCII_US);
127cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>0
128cdf0e10cSrcweir     debug_printf("osl_createPipe options 0x%x\n", Options);
129cdf0e10cSrcweir #endif
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     switch( Options )
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir     case osl_Pipe_OPEN:
134cdf0e10cSrcweir 		{
135cdf0e10cSrcweir 			APIRET	fPipeAvailable;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 			sprintf (strPipeNameBuffer, "\\PIPE\\OSL_PIPE_%s", sPipe.getStr());
138cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>0
139cdf0e10cSrcweir 		    debug_printf("osl_createPipe %s\n", strPipeNameBuffer);
140cdf0e10cSrcweir #endif
141cdf0e10cSrcweir 			ngLastError = DosOpen( (PCSZ)strPipeNameBuffer,
142cdf0e10cSrcweir 								&(pPipe->hPipe), &ulAction,
143cdf0e10cSrcweir 								0, FILE_NORMAL,	FILE_OPEN,
144cdf0e10cSrcweir 								OPEN_ACCESS_READWRITE |	OPEN_SHARE_DENYREADWRITE,
145cdf0e10cSrcweir 								(PEAOP2) NULL);
146cdf0e10cSrcweir 			// if pipe is busy, wait for it
147cdf0e10cSrcweir 			if (ngLastError == ERROR_PIPE_BUSY)
148cdf0e10cSrcweir 				do
149cdf0e10cSrcweir 				{
150cdf0e10cSrcweir 					/* free instance should be available first */
151cdf0e10cSrcweir 					fPipeAvailable = DosWaitNPipe( (PCSZ)strPipeNameBuffer, -1);
152cdf0e10cSrcweir 					/* first try to open system pipe */
153cdf0e10cSrcweir 					if ( fPipeAvailable == NO_ERROR )
154cdf0e10cSrcweir 					{
155cdf0e10cSrcweir 						// We got it !
156cdf0e10cSrcweir 						ngLastError = NO_ERROR;
157cdf0e10cSrcweir 						break;
158cdf0e10cSrcweir 					}
159cdf0e10cSrcweir 					// Pipe instance maybe catched by another client -> try again
160cdf0e10cSrcweir 					printf("osl_createPipe wait for Pipe available\n");
161cdf0e10cSrcweir 				} while ( fPipeAvailable );
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir         break;
164cdf0e10cSrcweir     case osl_Pipe_CREATE:
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir 			sprintf (strPipeNameBuffer, "\\SEM32\\OSL_SEM_%s", sPipe.getStr());
167cdf0e10cSrcweir 			// check if semaphore exists (pipe create must fail for existig pipes)
168cdf0e10cSrcweir 			ngLastError = DosCreateMutexSem( (PCSZ)strPipeNameBuffer, &(pPipe->m_NamedObject), 0, TRUE );
169cdf0e10cSrcweir 			if (ngLastError)
170cdf0e10cSrcweir 				break;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 			sprintf (strPipeNameBuffer, "\\PIPE\\OSL_PIPE_%s", sPipe.getStr());
173cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>0
174cdf0e10cSrcweir 		    debug_printf("osl_createPipe %s\n", strPipeNameBuffer);
175cdf0e10cSrcweir #endif
176cdf0e10cSrcweir 			ngLastError = DosCreateNPipe( (PCSZ)strPipeNameBuffer,
177cdf0e10cSrcweir                             &(pPipe->hPipe),
178cdf0e10cSrcweir                             NP_ACCESS_DUPLEX,    /* open pipe for read and write access */
179cdf0e10cSrcweir                             0xFF,                /* allow unlimited number of instances */
180cdf0e10cSrcweir                             ulBufSize,           /* output buffer size */
181cdf0e10cSrcweir                             ulBufSize,           /* input buffer size */
182cdf0e10cSrcweir                             0L                   /* use default time-out time */
183cdf0e10cSrcweir                           );
184cdf0e10cSrcweir 		}
185cdf0e10cSrcweir         break;
186cdf0e10cSrcweir     default:
187cdf0e10cSrcweir         ngLastError = ERROR_INVALID_PARAMETER;
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     /* if failed, release allocated memory */
191cdf0e10cSrcweir     if (ngLastError)
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         OSL_TRACE( "osl_createPipe failed %s the pipe %s, Error Code %d.\n",
194cdf0e10cSrcweir                    Options == osl_Pipe_OPEN ? "opening" : "creating",
195cdf0e10cSrcweir                    strPipeNameBuffer,
196cdf0e10cSrcweir                    ngLastError );
197cdf0e10cSrcweir 		__osl_destroyPipeImpl(pPipe);
198cdf0e10cSrcweir         return NULL;
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     pPipe->m_Reference= 1;
202cdf0e10cSrcweir     pPipe->m_bClosed  = sal_False;
203cdf0e10cSrcweir     //pPipe->m_Security = Security;
204cdf0e10cSrcweir     pPipe->nLastError = NO_ERROR;
205cdf0e10cSrcweir     return (oslPipe)pPipe;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir /*****************************************************************************/
209cdf0e10cSrcweir /* osl_copyPipe  */
210cdf0e10cSrcweir /*****************************************************************************/
osl_copyPipe(oslPipe pPipe)211cdf0e10cSrcweir oslPipe SAL_CALL osl_copyPipe(oslPipe pPipe)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     //oslPipe* pPipe = (oslPipe*) Pipe;
214cdf0e10cSrcweir     oslPipe pNewPipe;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     /* check parameter */
218cdf0e10cSrcweir     OSL_ASSERT (pPipe);
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     /* allocate impl-structure */
221cdf0e10cSrcweir     pNewPipe = __osl_createPipeImpl();
222cdf0e10cSrcweir     if (!pNewPipe) return NULL;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     /* create new handle */
225cdf0e10cSrcweir     pNewPipe->hPipe = (HPIPE) -1;
226cdf0e10cSrcweir     ngLastError  = DosDupHandle( pPipe->hPipe, &(pNewPipe->hPipe) );
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     /* if failed, release allocated memory */
229cdf0e10cSrcweir     if (ngLastError)
230cdf0e10cSrcweir     {
231cdf0e10cSrcweir         OSL_TRACE( "osl_copyPipe failed duplicating pipe handle, Error-Code: %d.\n",
232cdf0e10cSrcweir                    ngLastError );
233cdf0e10cSrcweir         free (pNewPipe);
234cdf0e10cSrcweir         return NULL;
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     pNewPipe->nLastError = NO_ERROR;
238cdf0e10cSrcweir 	return (oslPipe)pNewPipe;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
osl_acquirePipe(oslPipe pPipe)241cdf0e10cSrcweir void SAL_CALL osl_acquirePipe( oslPipe pPipe )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir 	osl_incrementInterlockedCount( &(pPipe->m_Reference) );
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
osl_releasePipe(oslPipe pPipe)246cdf0e10cSrcweir void SAL_CALL osl_releasePipe( oslPipe pPipe )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir //  	OSL_ASSERT( pPipe );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	if( 0 == pPipe )
251cdf0e10cSrcweir 		return;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 	if( 0 == osl_decrementInterlockedCount( &(pPipe->m_Reference) ) )
254cdf0e10cSrcweir 	{
255cdf0e10cSrcweir 		if( ! pPipe->m_bClosed )
256cdf0e10cSrcweir 			osl_closePipe( pPipe );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 		__osl_destroyPipeImpl( pPipe );
259cdf0e10cSrcweir 	}
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir /*****************************************************************************/
263cdf0e10cSrcweir /* osl_destroyPipe  */
264cdf0e10cSrcweir /*************close****************************************************************/
osl_closePipe(oslPipe pPipe)265cdf0e10cSrcweir void SAL_CALL osl_closePipe(oslPipe pPipe)
266cdf0e10cSrcweir {
267cdf0e10cSrcweir     //oslPipe* pPipe = (oslPipe*) Pipe;
268cdf0e10cSrcweir     /* check parameter */
269cdf0e10cSrcweir     OSL_ASSERT (pPipe);
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	if( pPipe && ! pPipe->m_bClosed )
272cdf0e10cSrcweir 	{
273cdf0e10cSrcweir 		pPipe->m_bClosed = sal_True;
274cdf0e10cSrcweir 		/* if we have a system pipe close it */
275cdf0e10cSrcweir 		if (pPipe->hPipe != 0)
276cdf0e10cSrcweir 		{
277cdf0e10cSrcweir 			/* disconnect client */
278cdf0e10cSrcweir 			DosDisConnectNPipe (pPipe->hPipe);
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 			/* close the pipe */
281cdf0e10cSrcweir 			DosClose (pPipe->hPipe);
282cdf0e10cSrcweir 		}
283cdf0e10cSrcweir 	}
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir /*****************************************************************************/
287cdf0e10cSrcweir /* osl_acceptPipe  */
288cdf0e10cSrcweir /*****************************************************************************/
osl_acceptPipe(oslPipe pPipe)289cdf0e10cSrcweir oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
290cdf0e10cSrcweir {
291cdf0e10cSrcweir 
292cdf0e10cSrcweir #define PINFO ((PIPEINFO *) &PipeInfoBuffer)
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     ///oslPipe* pPipe = (oslPipe*) Pipe;
295cdf0e10cSrcweir     oslPipe pNewPipe;
296cdf0e10cSrcweir     BYTE     PipeInfoBuffer[sizeof(PIPEINFO) + CCHMAXPATHCOMP];
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     /* check parameter */
299cdf0e10cSrcweir     OSL_ASSERT (pPipe);
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     /* get pipe information */
302cdf0e10cSrcweir     pPipe->nLastError = DosQueryNPipeInfo(pPipe->hPipe,
303cdf0e10cSrcweir                                          1,
304cdf0e10cSrcweir                                          (PVOID) &PipeInfoBuffer,
305cdf0e10cSrcweir                                          sizeof(PipeInfoBuffer));
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     if (pPipe->nLastError)
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         OSL_TRACE( "osl_acceptPipe failed for requesting pipe information.\n",
310cdf0e10cSrcweir                    pPipe->nLastError );
311cdf0e10cSrcweir         return NULL;
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     /* create a new instance of the pipe if possible */
315cdf0e10cSrcweir     if (PINFO->cbMaxInst == -1 ||                   /* unlimited instances */
316cdf0e10cSrcweir         PINFO->cbMaxInst > PINFO->cbCurInst)
317cdf0e10cSrcweir     {
318cdf0e10cSrcweir         HPIPE hPipe;
319cdf0e10cSrcweir 
320cdf0e10cSrcweir         pNewPipe = __osl_createPipeImpl();
321cdf0e10cSrcweir 
322cdf0e10cSrcweir         if (!pNewPipe)
323cdf0e10cSrcweir         {
324cdf0e10cSrcweir             OSL_TRACE( "osl_acceptPipe failed creating new instance.\n", ngLastError );
325cdf0e10cSrcweir             free(pNewPipe);
326cdf0e10cSrcweir             return NULL;
327cdf0e10cSrcweir         }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir         //pNewPipe->m_Security = pPipe->m_Security;
330cdf0e10cSrcweir 
331cdf0e10cSrcweir         pNewPipe->nLastError =
332cdf0e10cSrcweir             DosCreateNPipe( (PCSZ)PINFO->szName,
333cdf0e10cSrcweir                             &(pNewPipe->hPipe),
334cdf0e10cSrcweir                             NP_ACCESS_DUPLEX,    /* open pipe for read and write access */
335cdf0e10cSrcweir                             0xFF,                /* allow unlimited number of instances */
336cdf0e10cSrcweir                             ulBufSize,           /* output buffer size */
337cdf0e10cSrcweir                             ulBufSize,           /* input buffer size */
338cdf0e10cSrcweir                             0L                   /* use default time-out time */
339cdf0e10cSrcweir                           );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir         if (pNewPipe->nLastError)
342cdf0e10cSrcweir         {
343cdf0e10cSrcweir             OSL_TRACE( "osl_acceptPipe failed creating new named pipe, Error-Code: %d.\n",
344cdf0e10cSrcweir                        pNewPipe->nLastError );
345cdf0e10cSrcweir             free(pNewPipe);
346cdf0e10cSrcweir             return NULL;
347cdf0e10cSrcweir         }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir         /* switch pipe handles */
350cdf0e10cSrcweir         hPipe = pPipe->hPipe;
351cdf0e10cSrcweir         pPipe->hPipe  = pNewPipe->hPipe;
352cdf0e10cSrcweir         pNewPipe->hPipe = hPipe;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         /* connect new handle to client */
355cdf0e10cSrcweir         pNewPipe->nLastError = DosConnectNPipe( pNewPipe->hPipe );
356cdf0e10cSrcweir 
357cdf0e10cSrcweir         /* if failed, release allocated memory */
358cdf0e10cSrcweir         if (pNewPipe->nLastError)
359cdf0e10cSrcweir         {
360cdf0e10cSrcweir             OSL_TRACE( "osl_acceptPipe failed connecting pipe to client, Error-Code: %d.\n",
361cdf0e10cSrcweir                        pNewPipe->nLastError );
362cdf0e10cSrcweir 
363cdf0e10cSrcweir             osl_closePipe((oslPipe)pNewPipe);
364cdf0e10cSrcweir             return NULL;
365cdf0e10cSrcweir         }
366cdf0e10cSrcweir         return (oslPipe)pNewPipe;
367cdf0e10cSrcweir     }
368cdf0e10cSrcweir     else
369cdf0e10cSrcweir     {
370cdf0e10cSrcweir         /* connect original handle to client */
371cdf0e10cSrcweir         pPipe->nLastError = DosConnectNPipe( pPipe->hPipe );
372cdf0e10cSrcweir 
373cdf0e10cSrcweir         if (pPipe->nLastError)
374cdf0e10cSrcweir         {
375cdf0e10cSrcweir             OSL_TRACE( "osl_acceptPipe failed connecting pipe to client, Error-Code: %d.\n",
376cdf0e10cSrcweir                        pPipe->nLastError );
377cdf0e10cSrcweir             return NULL;
378cdf0e10cSrcweir         }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir         return (oslPipe)pPipe;
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir /*****************************************************************************/
385cdf0e10cSrcweir /* osl_receivePipe  */
386cdf0e10cSrcweir /*****************************************************************************/
osl_receivePipe(oslPipe pPipe,void * pBuffer,sal_Int32 BytesToRead)387cdf0e10cSrcweir sal_Int32 SAL_CALL osl_receivePipe(oslPipe pPipe,
388cdf0e10cSrcweir 					    void* pBuffer,
389cdf0e10cSrcweir 					    sal_Int32 BytesToRead)
390cdf0e10cSrcweir {
391cdf0e10cSrcweir     //oslPipe* pPipe = (oslPipe*) Pipe;
392cdf0e10cSrcweir     ULONG  ulActual;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     /* check parameter */
395cdf0e10cSrcweir     OSL_ASSERT (pPipe);
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     /* read data from pipe */
398cdf0e10cSrcweir     pPipe->nLastError = DosRead( pPipe->hPipe, pBuffer, BytesToRead, &ulActual );
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     /* return -1 if failed */
401cdf0e10cSrcweir     if( pPipe->nLastError )
402cdf0e10cSrcweir     {
403cdf0e10cSrcweir         OSL_TRACE( "osl_receivePipe failed receiving from Pipe, Error-Code: %d.\n",
404cdf0e10cSrcweir                    pPipe->nLastError );
405cdf0e10cSrcweir         return -1;
406cdf0e10cSrcweir     }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     return ulActual;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 
412cdf0e10cSrcweir /*****************************************************************************/
413cdf0e10cSrcweir /* osl_sendPipe  */
414cdf0e10cSrcweir /*****************************************************************************/
osl_sendPipe(oslPipe pPipe,const void * pBuffer,sal_Int32 BytesToSend)415cdf0e10cSrcweir sal_Int32 SAL_CALL osl_sendPipe(oslPipe pPipe,
416cdf0e10cSrcweir 				       const void* pBuffer,
417cdf0e10cSrcweir 				       sal_Int32 BytesToSend)
418cdf0e10cSrcweir {
419cdf0e10cSrcweir     //oslPipe* pPipe = (oslPipe*) Pipe;
420cdf0e10cSrcweir     ULONG  ulActual;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir     /* check parameter */
423cdf0e10cSrcweir     OSL_ASSERT (pPipe);
424cdf0e10cSrcweir 
425cdf0e10cSrcweir     /* read data from pipe */
426cdf0e10cSrcweir     pPipe->nLastError = DosWrite( pPipe->hPipe, (PVOID) pBuffer, BytesToSend, &ulActual );
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     /* return -1 if failed */
429cdf0e10cSrcweir     if( pPipe->nLastError )
430cdf0e10cSrcweir     {
431cdf0e10cSrcweir         OSL_TRACE( "osl_receivePipe failed writing to Pipe, Error-Code: %d.\n",
432cdf0e10cSrcweir                    pPipe->nLastError );
433cdf0e10cSrcweir         return -1;
434cdf0e10cSrcweir     }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     return ulActual;
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 
440cdf0e10cSrcweir /*****************************************************************************/
441cdf0e10cSrcweir /* osl_getLastPipeError  */
442cdf0e10cSrcweir /*****************************************************************************/
443cdf0e10cSrcweir 
osl_getLastPipeError(oslPipe pPipe)444cdf0e10cSrcweir oslPipeError SAL_CALL osl_getLastPipeError(oslPipe pPipe)
445cdf0e10cSrcweir {
446cdf0e10cSrcweir     //oslPipe* pPipe = (oslPipe*) Pipe;
447cdf0e10cSrcweir     APIRET rc;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     /* return local error value if possible */
450cdf0e10cSrcweir     if (pPipe)
451cdf0e10cSrcweir 	{
452cdf0e10cSrcweir         rc = pPipe->nLastError;
453cdf0e10cSrcweir 		pPipe->nLastError = NO_ERROR;
454cdf0e10cSrcweir     } else
455cdf0e10cSrcweir         rc = ngLastError;
456cdf0e10cSrcweir 
457cdf0e10cSrcweir     /* map OS/2 error values */
458cdf0e10cSrcweir     switch (rc)
459cdf0e10cSrcweir     {
460cdf0e10cSrcweir     case NO_ERROR:                return osl_Pipe_E_None;
461cdf0e10cSrcweir     case ERROR_PATH_NOT_FOUND:    return osl_Pipe_E_NotFound;
462cdf0e10cSrcweir     case ERROR_NOT_ENOUGH_MEMORY: return osl_Pipe_E_NoBufferSpace;
463cdf0e10cSrcweir     default:                      return osl_Pipe_E_invalidError;
464cdf0e10cSrcweir     }
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir /*****************************************************************************/
468cdf0e10cSrcweir 
osl_writePipe(oslPipe pPipe,const void * pBuffer,sal_Int32 n)469cdf0e10cSrcweir sal_Int32 SAL_CALL osl_writePipe( oslPipe pPipe, const void *pBuffer , sal_Int32 n )
470cdf0e10cSrcweir {
471cdf0e10cSrcweir 	/* loop until all desired bytes were send or an error occured */
472cdf0e10cSrcweir 	sal_Int32 BytesSend= 0;
473cdf0e10cSrcweir 	sal_Int32 BytesToSend= n;
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 	OSL_ASSERT(pPipe);
476cdf0e10cSrcweir 	while (BytesToSend > 0)
477cdf0e10cSrcweir 	{
478cdf0e10cSrcweir 		sal_Int32 RetVal;
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 		RetVal= osl_sendPipe(pPipe, pBuffer, BytesToSend);
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 		/* error occured? */
483cdf0e10cSrcweir 		if(RetVal <= 0)
484cdf0e10cSrcweir 		{
485cdf0e10cSrcweir 			break;
486cdf0e10cSrcweir 		}
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 		BytesToSend -= RetVal;
489cdf0e10cSrcweir 		BytesSend += RetVal;
490cdf0e10cSrcweir 		pBuffer= (sal_Char*)pBuffer + RetVal;
491cdf0e10cSrcweir 	}
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 	return BytesSend;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
osl_readPipe(oslPipe pPipe,void * pBuffer,sal_Int32 n)496cdf0e10cSrcweir sal_Int32 SAL_CALL osl_readPipe( oslPipe pPipe, void *pBuffer , sal_Int32 n )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir 	/* loop until all desired bytes were read or an error occured */
499cdf0e10cSrcweir 	sal_Int32 BytesRead= 0;
500cdf0e10cSrcweir 	sal_Int32 BytesToRead= n;
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 	OSL_ASSERT( pPipe );
503cdf0e10cSrcweir 	while (BytesToRead > 0)
504cdf0e10cSrcweir 	{
505cdf0e10cSrcweir 		sal_Int32 RetVal;
506cdf0e10cSrcweir 		RetVal= osl_receivePipe(pPipe, pBuffer, BytesToRead);
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 		/* error occured? */
509cdf0e10cSrcweir 		if(RetVal <= 0)
510cdf0e10cSrcweir 		{
511cdf0e10cSrcweir 			break;
512cdf0e10cSrcweir 		}
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 		BytesToRead -= RetVal;
515cdf0e10cSrcweir 		BytesRead += RetVal;
516cdf0e10cSrcweir 		pBuffer= (sal_Char*)pBuffer + RetVal;
517cdf0e10cSrcweir 	}
518cdf0e10cSrcweir 	return BytesRead;
519cdf0e10cSrcweir }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 
522cdf0e10cSrcweir /******************************************************************************
523cdf0e10cSrcweir  *
524cdf0e10cSrcweir  *                  New io resource transfer functions
525cdf0e10cSrcweir  *
526cdf0e10cSrcweir  *****************************************************************************/
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 
529cdf0e10cSrcweir /**********************************************
530cdf0e10cSrcweir  osl_sendResourcePipe
531cdf0e10cSrcweir  *********************************************/
532cdf0e10cSrcweir 
osl_sendResourcePipe(oslPipe pPipe,oslSocket pSocket)533cdf0e10cSrcweir sal_Bool osl_sendResourcePipe(oslPipe pPipe, oslSocket pSocket)
534cdf0e10cSrcweir {
535cdf0e10cSrcweir     sal_Bool bRet = sal_False;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     return bRet;
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir /**********************************************
541cdf0e10cSrcweir  osl_receiveResourcePipe
542cdf0e10cSrcweir  *********************************************/
543cdf0e10cSrcweir 
osl_receiveResourcePipe(oslPipe pPipe)544cdf0e10cSrcweir oslSocket osl_receiveResourcePipe(oslPipe pPipe)
545cdf0e10cSrcweir {
546cdf0e10cSrcweir     oslSocket pSocket=0;
547cdf0e10cSrcweir 
548cdf0e10cSrcweir     return (oslSocket) pSocket;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 
552