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