summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorJörg Budischewski <jbu@openoffice.org>2001-03-14 16:18:00 +0000
committerJörg Budischewski <jbu@openoffice.org>2001-03-14 16:18:00 +0000
commit92e618235574b2cf5a69c8dd585e904033511af5 (patch)
tree6bb117d0a4558275c8f393e7930155ac58d2fe49 /sal
parentb460e7a8353830a07f00b61ffa5e044951719c3c (diff)
pipe+socket now refcounted, add blocking read/write access, removed osl_getIOResources
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/pipe.c319
-rw-r--r--sal/osl/unx/process.c577
-rw-r--r--sal/osl/unx/sockimpl.h32
3 files changed, 211 insertions, 717 deletions
diff --git a/sal/osl/unx/pipe.c b/sal/osl/unx/pipe.c
index 6e8cfa4f1..1db14d296 100644
--- a/sal/osl/unx/pipe.c
+++ b/sal/osl/unx/pipe.c
@@ -2,9 +2,9 @@
*
* $RCSfile: pipe.c,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: mfe $ $Date: 2001-02-26 16:10:09 $
+ * last change: $Author: jbu $ $Date: 2001-03-14 17:18:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -66,6 +66,9 @@
#include <osl/diagnose.h>
/*#include <osl/signal.h>*/
#include <osl/thread.h>
+#include <osl/interlck.h>
+
+#include "sockimpl.h"
#define PIPEDEFAULTPATH "/tmp"
#define PIPEALTERNATEPATH "/var/tmp"
@@ -81,20 +84,6 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
/*****************************************************************************/
-/* enum oslPipeImpl */
-/*****************************************************************************/
-
-typedef struct _oslPipeImpl {
- int m_Socket;
- sal_Char m_Name[PATH_MAX + 1];
-#if defined(LINUX)
- sal_Bool m_bIsAccepting;
- sal_Bool m_bIsInShutdown;
-#endif
-} oslPipeImpl;
-
-
-/*****************************************************************************/
/* enum oslPipeError */
/*****************************************************************************/
@@ -157,16 +146,18 @@ static oslPipeError osl_PipeErrorFromNative(int nativeType)
/* osl_create/destroy-PipeImpl */
/*****************************************************************************/
-oslPipeImpl* __osl_createPipeImpl()
+oslPipe __osl_createPipeImpl()
{
- oslPipeImpl* pPipeImpl;
+ oslPipe pPipeImpl;
- pPipeImpl = (oslPipeImpl*)calloc(1, sizeof(oslPipeImpl));
+ pPipeImpl = (oslPipe)calloc(1, sizeof(struct oslPipeImpl));
+ pPipeImpl->m_nRefCount =1;
+ pPipeImpl->m_bClosed = sal_False;
- return (pPipeImpl);
+ return pPipeImpl;
}
-void __osl_destroyPipeImpl(oslPipeImpl *pImpl)
+void __osl_destroyPipeImpl(oslPipe pImpl)
{
if (pImpl != NULL)
free(pImpl);
@@ -210,7 +201,7 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
struct sockaddr_un addr;
sal_Char name[PATH_MAX + 1];
- oslPipeImpl* pPipeImpl;
+ oslPipe pPipe;
if (access(PIPEDEFAULTPATH, O_RDWR) == 0)
{
@@ -241,24 +232,24 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
/* alloc memory */
- pPipeImpl= __osl_createPipeImpl();
+ pPipe= __osl_createPipeImpl();
/* create socket */
- pPipeImpl->m_Socket = socket(AF_UNIX, SOCK_STREAM, 0);
- if ( pPipeImpl->m_Socket < 0 )
+ pPipe->m_Socket = socket(AF_UNIX, SOCK_STREAM, 0);
+ if ( pPipe->m_Socket < 0 )
{
OSL_TRACE("osl_createPipe socket failed. Errno: %d; %s\n",errno, strerror(errno));
- __osl_destroyPipeImpl(pPipeImpl);
+ __osl_destroyPipeImpl(pPipe);
return NULL;
}
-/* OSL_TRACE("osl_createPipe : new Pipe on fd %i\n",pPipeImpl->m_Socket);*/
+/* OSL_TRACE("osl_createPipe : new Pipe on fd %i\n",pPipe->m_Socket);*/
/* set close-on-exec flag */
- if ((Flags = fcntl(pPipeImpl->m_Socket, F_GETFD, 0)) != -1)
+ if ((Flags = fcntl(pPipe->m_Socket, F_GETFD, 0)) != -1)
{
Flags |= FD_CLOEXEC;
- if (fcntl(pPipeImpl->m_Socket, F_SETFD, Flags) == -1)
+ if (fcntl(pPipe->m_Socket, F_SETFD, Flags) == -1)
{
OSL_TRACE("osl_createPipe failed changing socket flags. Errno: %d; %s\n",errno,strerror(errno));
}
@@ -280,11 +271,11 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
if ( ( stat(name, &status) == 0) &&
( S_ISSOCK(status.st_mode) || S_ISFIFO(status.st_mode) ) )
{
- if ( connect(pPipeImpl->m_Socket,(struct sockaddr *)&addr,len) >= 0 )
+ if ( connect(pPipe->m_Socket,(struct sockaddr *)&addr,len) >= 0 )
{
OSL_TRACE("osl_createPipe : Pipe already in use. Errno: %d; %s\n",errno,strerror(errno));
- close (pPipeImpl->m_Socket);
- __osl_destroyPipeImpl(pPipeImpl);
+ close (pPipe->m_Socket);
+ __osl_destroyPipeImpl(pPipe);
return NULL;
}
@@ -292,93 +283,94 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
}
/* ok, fs clean */
- if ( bind(pPipeImpl->m_Socket, (struct sockaddr *)&addr, len) < 0 )
+ if ( bind(pPipe->m_Socket, (struct sockaddr *)&addr, len) < 0 )
{
OSL_TRACE("osl_createPipe : failed to bind socket. Errno: %d; %s\n",errno,strerror(errno));
- close (pPipeImpl->m_Socket);
- __osl_destroyPipeImpl(pPipeImpl);
+ close (pPipe->m_Socket);
+ __osl_destroyPipeImpl(pPipe);
return NULL;
}
chmod(name,S_IRWXU | S_IRWXG |S_IRWXO);
- strcpy(pPipeImpl->m_Name, name);
+ strcpy(pPipe->m_Name, name);
- if ( listen(pPipeImpl->m_Socket, 5) < 0 )
+ if ( listen(pPipe->m_Socket, 5) < 0 )
{
OSL_TRACE("osl_createPipe failed to listen. Errno: %d; %s\n",errno,strerror(errno));
unlink(name); /* remove filesystem entry */
- close (pPipeImpl->m_Socket);
- __osl_destroyPipeImpl(pPipeImpl);
+ close (pPipe->m_Socket);
+ __osl_destroyPipeImpl(pPipe);
return NULL;
}
- return (pPipeImpl);
+ return (pPipe);
}
else
{ /* osl_pipe_OPEN */
if ( access(name, F_OK) != -1 )
{
- if ( connect( pPipeImpl->m_Socket, (struct sockaddr *)&addr, len) >= 0 )
+ if ( connect( pPipe->m_Socket, (struct sockaddr *)&addr, len) >= 0 )
{
- return (pPipeImpl);
+ return (pPipe);
}
OSL_TRACE("osl_createPipe failed to connect. Errno: %d; %s\n",errno,strerror(errno));
}
- close (pPipeImpl->m_Socket);
- __osl_destroyPipeImpl(pPipeImpl);
+ close (pPipe->m_Socket);
+ __osl_destroyPipeImpl(pPipe);
return NULL;
}
/* if we reach here something went wrong */
/* should never come here */
- close (pPipeImpl->m_Socket);
- __osl_destroyPipeImpl(pPipeImpl);
+ close (pPipe->m_Socket);
+ __osl_destroyPipeImpl(pPipe);
return NULL;
}
/*****************************************************************************/
/* osl_copyPipe */
/*****************************************************************************/
-oslPipe SAL_CALL osl_copyPipe(oslPipe Pipe)
+oslPipe SAL_CALL osl_copyPipe(oslPipe pPipe)
{
- oslPipeImpl* pPipeImpl;
- oslPipeImpl* pParamPipeImpl;
+ osl_acceptPipe( pPipe );
+ return pPipe;
+}
- OSL_ASSERT(Pipe);
+void SAL_CALL osl_acquirePipe( oslPipe pPipe )
+{
+ osl_incrementInterlockedCount( &(pPipe->m_nRefCount) );
+}
- if ( Pipe == 0 )
- {
- return 0;
- }
+void SAL_CALL osl_releasePipe( oslPipe pPipe )
+{
- /* alloc memory */
- pPipeImpl= __osl_createPipeImpl();
-
- OSL_ASSERT(pPipeImpl);
-
- if ( pPipeImpl == 0 )
+ if( 0 == pPipe )
+ return;
+
+ if( 0 == osl_decrementInterlockedCount( &(pPipe->m_nRefCount) ) )
{
- return 0;
+ if( ! pPipe->m_bClosed )
+ osl_closePipe( pPipe );
+
+ /* REMOVE THIS HACK AS SOON AS osl_closePipe MUST change has been applied ! */
+#ifdef LINUX
+ if ( pPipe->m_bIsAccepting == sal_False )
+ {
+#endif
+ /* free memory */
+ __osl_destroyPipeImpl(pPipe);
+#ifdef LINUX
+ }
+#endif
+ __osl_destroyPipeImpl( pPipe );
}
-
- pParamPipeImpl= (oslPipeImpl*)Pipe;
-
- /* copy socket */
- memcpy(pPipeImpl, pParamPipeImpl, sizeof(oslPipeImpl));
-
- return (oslPipe)pPipeImpl;
}
-
-/*****************************************************************************/
-/* osl_destroyPipe */
-/*****************************************************************************/
-void SAL_CALL osl_destroyPipe(oslPipe Pipe)
+void SAL_CALL osl_closePipe( oslPipe pPipe )
{
- oslPipeImpl* pPipeImpl;
int nRet;
#if defined(LINUX)
size_t len;
@@ -387,27 +379,29 @@ void SAL_CALL osl_destroyPipe(oslPipe Pipe)
#endif
int ConnFD;
- /* socket already invalid */
- if( Pipe == NULL )
+ if( ! pPipe )
+ {
return;
+ }
- OSL_TRACE("In osl_destroyPipe");
-
- pPipeImpl = (oslPipeImpl*) Pipe;
+ if( pPipe->m_bClosed )
+ {
+ return;
+ }
- ConnFD = pPipeImpl->m_Socket;
+ ConnFD = pPipe->m_Socket;
#if defined(LINUX)
- if ( pPipeImpl->m_bIsAccepting == sal_True )
+ if ( pPipe->m_bIsAccepting == sal_True )
{
- pPipeImpl->m_bIsInShutdown = sal_True;
- pPipeImpl->m_Socket = -1;
+ pPipe->m_bIsInShutdown = sal_True;
+ pPipe->m_Socket = -1;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
memset(&addr, 0, sizeof(addr));
- OSL_TRACE("osl_destroyPipe : Pipe Name '%s'",pPipeImpl->m_Name);
+ OSL_TRACE("osl_destroyPipe : Pipe Name '%s'",pPipe->m_Name);
addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, pPipeImpl->m_Name);
+ strcpy(addr.sun_path, pPipe->m_Name);
len = sizeof(addr.sun_family) + strlen(addr.sun_path);
nRet = connect( fd, (struct sockaddr *)&addr, len);
@@ -434,51 +428,47 @@ void SAL_CALL osl_destroyPipe(oslPipe Pipe)
OSL_TRACE("close in destroyPipe failed : '%s'\n",strerror(errno));
}
/* remove filesystem entry */
- if ( strlen(pPipeImpl->m_Name) > 0 )
+ if ( strlen(pPipe->m_Name) > 0 )
{
- unlink(pPipeImpl->m_Name);
- }
-
-#ifdef LINUX
- if ( pPipeImpl->m_bIsAccepting == sal_False )
- {
-#endif
- /* free memory */
- __osl_destroyPipeImpl(pPipeImpl);
-#ifdef LINUX
+ unlink(pPipe->m_Name);
}
-#endif
- OSL_TRACE("Out osl_destroyPipe");
+/* OSL_TRACE("Out osl_destroyPipe"); */
+}
+
+
+/*****************************************************************************/
+/* osl_destroyPipe */
+/*****************************************************************************/
+void SAL_CALL osl_destroyPipe(oslPipe pPipe)
+{
+ osl_releasePipe( pPipe );
}
/*****************************************************************************/
/* osl_acceptPipe */
/*****************************************************************************/
-oslPipe SAL_CALL osl_acceptPipe(oslPipe Pipe)
+oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
{
int s;
- oslPipeImpl* pPipeImpl;
- oslPipeImpl* pParamPipeImpl;
- OSL_ASSERT(Pipe);
+ oslPipe pAcceptedPipe;
+ OSL_ASSERT(pPipe);
- if ( Pipe == 0 )
+ if ( pPipe == 0 )
{
return 0;
}
- pParamPipeImpl= (oslPipeImpl*)Pipe;
-
- OSL_ASSERT(strlen(pParamPipeImpl->m_Name) > 0);
+ OSL_ASSERT(strlen(pPipe->m_Name) > 0);
#if defined(LINUX)
pParamPipeImpl->m_bIsAccepting = sal_True;
#endif
- s = accept(pParamPipeImpl->m_Socket, NULL, NULL);
+ s = accept(pPipe->m_Socket, NULL, NULL);
#if defined(LINUX)
- pParamPipeImpl->m_bIsAccepting = sal_False;
+ pPipe->m_bIsAccepting = sal_False;
#endif
if ( s < 0 )
@@ -490,7 +480,7 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe Pipe)
}
#if defined(LINUX)
- if ( pParamPipeImpl->m_bIsInShutdown == sal_True )
+ if ( pPipe->m_bIsInShutdown == sal_True )
{
close(s);
__osl_destroyPipeImpl(pParamPipeImpl);
@@ -504,60 +494,46 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe Pipe)
else
{
/* alloc memory */
- pPipeImpl= __osl_createPipeImpl();
+ pAcceptedPipe= __osl_createPipeImpl();
- OSL_ASSERT(pPipeImpl);
+ OSL_ASSERT(pAcceptedPipe);
- if(pPipeImpl==NULL)
+ if(pAcceptedPipe==NULL)
return NULL;
- pPipeImpl->m_Socket = s;
+ pAcceptedPipe->m_Socket = s;
}
-
- return (oslPipe)pPipeImpl;
+ return pAcceptedPipe;
}
/*****************************************************************************/
/* osl_receivePipe */
/*****************************************************************************/
-sal_Int32 SAL_CALL osl_receivePipe(oslPipe Pipe,
+sal_Int32 SAL_CALL osl_receivePipe(oslPipe pPipe,
void* pBuffer,
- sal_uInt32 BytesToRead)
+ sal_Int32 BytesToRead)
{
- oslPipeImpl* pPipeImpl;
int nRet = 0;
- OSL_ASSERT(Pipe);
+ OSL_ASSERT(pPipe);
- if ( Pipe == 0 )
+ if ( pPipe == 0 )
{
OSL_TRACE("osl_receivePipe : Invalid socket");
errno=EINVAL;
return -1;
}
- pPipeImpl= (oslPipeImpl*)Pipe;
-
-/* OSL_TRACE("osl_receivePipe : receiving %i bytes on fd %i\n",BytesToRead,pPipeImpl->m_Socket);*/
-
- nRet = recv(pPipeImpl->m_Socket,
+ nRet = recv(pPipe->m_Socket,
(sal_Char*)pBuffer,
BytesToRead, 0);
-
if ( nRet <= 0 )
{
OSL_TRACE("osl_receivePipe failed : %i '%s'",nRet,strerror(errno));
}
-/* fprintf(stderr,"osl_receivePipe : received "); */
-/* for ( i = 0 ; i < nRet ; i++ ) */
-/* { */
-/* fprintf(stderr," '%c'",((sal_Char*)pBuffer)[i]); */
-/* } */
-/* fprintf(stderr,"\n"); */
-
return nRet;
}
@@ -565,27 +541,22 @@ sal_Int32 SAL_CALL osl_receivePipe(oslPipe Pipe,
/*****************************************************************************/
/* osl_sendPipe */
/*****************************************************************************/
-sal_Int32 SAL_CALL osl_sendPipe(oslPipe Pipe,
+sal_Int32 SAL_CALL osl_sendPipe(oslPipe pPipe,
const void* pBuffer,
- sal_uInt32 BytesToSend)
+ sal_Int32 BytesToSend)
{
- oslPipeImpl* pPipeImpl;
int nRet=0;
- OSL_ASSERT(Pipe);
+ OSL_ASSERT(pPipe);
- if ( Pipe == 0 )
+ if ( pPipe == 0 )
{
OSL_TRACE("osl_sendPipe : Invalid socket");
errno=EINVAL;
return -1;
}
- pPipeImpl= (oslPipeImpl*)Pipe;
-
-/* OSL_TRACE("osl_sendPipe : sending %i bytes on fd %i\n",BytesToSend,pPipeImpl->m_Socket);*/
-
- nRet = send(pPipeImpl->m_Socket,
+ nRet = send(pPipe->m_Socket,
(sal_Char*)pBuffer,
BytesToSend, 0);
@@ -595,13 +566,6 @@ sal_Int32 SAL_CALL osl_sendPipe(oslPipe Pipe,
OSL_TRACE("osl_sendPipe failed : %i '%s'",nRet,strerror(errno));
}
-/* fprintf(stderr,"osl_sendPipe : sended "); */
-/* for ( i = 0 ; i < nRet ; i++ ) */
-/* { */
-/* fprintf(stderr," '%c'",((sal_Char*)pBuffer)[i]); */
-/* } */
-/* fprintf(stderr,"\n"); */
-
return nRet;
}
@@ -609,9 +573,62 @@ sal_Int32 SAL_CALL osl_sendPipe(oslPipe Pipe,
/*****************************************************************************/
/* osl_getLastPipeError */
/*****************************************************************************/
-oslPipeError SAL_CALL osl_getLastPipeError(oslPipe Pipe)
+oslPipeError SAL_CALL osl_getLastPipeError(oslPipe pPipe)
{
return ERROR_FROM_NATIVE(errno);
}
+sal_Int32 SAL_CALL osl_writePipe( oslPipe pPipe, const void *pBuffer , sal_Int32 n )
+{
+ /* loop until all desired bytes were send or an error occured */
+ sal_Int32 BytesSend= 0;
+ sal_Int32 BytesToSend= n;
+
+ OSL_ASSERT(pPipe);
+ while (BytesToSend > 0)
+ {
+ sal_Int32 RetVal;
+
+ RetVal= osl_sendPipe(pPipe, pBuffer, BytesToSend);
+
+ /* error occured? */
+ if(RetVal <= 0)
+ {
+ break;
+ }
+
+ BytesToSend -= RetVal;
+ BytesSend += RetVal;
+ pBuffer= (sal_Char*)pBuffer + RetVal;
+ }
+
+ return BytesSend;
+}
+
+sal_Int32 SAL_CALL osl_readPipe( oslPipe pPipe, void *pBuffer , sal_Int32 n )
+{
+ /* loop until all desired bytes were read or an error occured */
+ sal_Int32 BytesRead= 0;
+ sal_Int32 BytesToRead= n;
+
+ OSL_ASSERT( pPipe );
+ while (BytesToRead > 0)
+ {
+ sal_Int32 RetVal;
+ RetVal= osl_receivePipe(pPipe, pBuffer, BytesToRead);
+
+ /* error occured? */
+ if(RetVal <= 0)
+ {
+ break;
+ }
+
+ BytesToRead -= RetVal;
+ BytesRead += RetVal;
+ pBuffer= (sal_Char*)pBuffer + RetVal;
+ }
+ return BytesRead;
+}
+
+
diff --git a/sal/osl/unx/process.c b/sal/osl/unx/process.c
index 199f215fa..a54c9573b 100644
--- a/sal/osl/unx/process.c
+++ b/sal/osl/unx/process.c
@@ -2,9 +2,9 @@
*
* $RCSfile: process.c,v $
*
- * $Revision: 1.8 $
+ * $Revision: 1.9 $
*
- * last change: $Author: mfe $ $Date: 2001-02-26 16:17:49 $
+ * last change: $Author: jbu $ $Date: 2001-03-14 17:18:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -94,16 +94,9 @@
#include "secimpl.h"
-
-
-#define FIFO_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
#define MAX_ARGS 255
#define MAX_ENVS 255
-#define PIPEDEFAULTPATH "/tmp"
-#define PIPEALTERNATEPATH "/var/tmp"
-#define PIPENAMEMASK "OSL_IOT_%u"
-
#if defined(MACOSX) || defined(IORESOURCE_TRANSFER_BSD)
#define CONTROLLEN (sizeof(struct cmsghdr) + sizeof(int))
#endif
@@ -116,21 +109,6 @@
*
******************************************************************************/
-typedef enum {
- MSG_DATA,
- MSG_END,
- MSG_ACK,
- MSG_REL,
- MSG_UNKNOWN
-} MessageType;
-
-typedef struct {
- MessageType m_Type;
- oslDescriptorFlag m_Flags;
- oslDescriptorType m_Data;
- int m_Value;
-} Message;
-
typedef struct {
int m_hPipe;
int m_hConn;
@@ -150,11 +128,6 @@ typedef struct {
oslProcessImpl* m_pProcImpl;
} ProcessData;
-typedef struct _oslSocketCallbackArg {
- int m_ident;
- Pipe* m_pipe;
-} oslSocketCallbackArg;
-
typedef struct _oslPipeImpl {
int m_Socket;
sal_Char m_Name[PATH_MAX + 1];
@@ -168,14 +141,6 @@ typedef struct _oslPipeImpl {
*****************************************************************************/
static sal_Char *getCmdLine();
-static Pipe* openPipe(pid_t pid);
-static void closePipe(Pipe* pipe);
-static sal_Bool connectPipe(Pipe* pipe);
-static int send_fd(Pipe* pipe, int fd);
-static int recv_fd(Pipe* pipe);
-static void* socketCloseCallback(void* pArg);
-static sal_Bool sendIOResources(Pipe* pipe, oslIOResource ioRes[]);
-static void ChildStatusProc(void *pData);
oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName,
sal_Char *pszArguments[],
@@ -616,511 +581,6 @@ oslProcessError SAL_CALL osl_getCommandArgs(sal_Char* pszBuffer, sal_uInt32 Max)
return osl_Process_E_None;
}
-
-/******************************************************************************
- *
- * Functions pipe stuff and io resource transfer
- *
- *****************************************************************************/
-
-static Pipe* openPipe(pid_t pid)
-{
- Pipe* ppipe = NULL;
-
-#if defined(IORESOURCE_TRANSFER_SYSV) || defined(IORESOURCE_TRANSFER_BSD)
- int fd;
- sal_Char name[PATH_MAX + 1];
-
- if (access(PIPEDEFAULTPATH, O_RDWR) == 0)
- strcpy(name, PIPEDEFAULTPATH);
- else
- strcpy(name, PIPEALTERNATEPATH);
-
- strcat(name, "/");
-
- sprintf(&name[strlen(name)], PIPENAMEMASK, pid);
-
-#ifdef IORESOURCE_TRANSFER_BSD
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
-
- if (fd != -1)
- {
- int len;
- struct sockaddr_un addr;
- struct stat status;
-
- memset(&addr, 0, sizeof(addr));
-
- addr.sun_family = AF_UNIX;
- strcpy(addr.sun_path, name);
- len = sizeof(addr.sun_family) + strlen(addr.sun_path);
-
- if (access(name, O_RDWR) < 0)
- {
- int msk;
-
- /* check if there exists an orphan filesystem entry */
- if ((stat(name, &status) == 0) &&
- (S_ISSOCK(status.st_mode) || S_ISFIFO(status.st_mode)) &&
- (kill((pid_t)status.st_atime, 0) < 0))
- unlink(name);
-
- /* try to create a named file a base for the pipe */
- msk = umask(0);
- if (bind(fd, (const struct sockaddr *)&addr, len) >= 0)
- {
- struct utimbuf times;
-
- /* set access time to our pid for marking the owner */
- stat(name, &status);
- times.actime = (time_t)getpid();
- times.modtime = status.st_mtime;
- utime(name, &times);
-
- if (listen(fd, 5) >= 0)
- {
- ppipe = (Pipe*) malloc(sizeof(Pipe));
-
- ppipe->m_hConn = fd;
- ppipe->m_hPipe = -1;
-
- strncpy(ppipe->m_Name, name, sizeof(ppipe->m_Name));
- }
- else
- {
- unlink(name); /* remove filesystem entry */
- }
- }
- umask(msk);
- }
- else
- {
- /* connect to socket */
- if (connect(fd, (const struct sockaddr *)&addr, len) >= 0)
- {
- ppipe = (Pipe*) malloc(sizeof(Pipe));
- ppipe->m_hPipe = fd;
- ppipe->m_hConn = -1;
- ppipe->m_Name[0] = '\0';
- }
- }
-
- if (ppipe == NULL)
- close(fd);
- }
-#endif
-
-#ifdef IORESOURCE_TRANSFER_SYSV
- if (access(name, O_RDWR) < 0)
- {
- int pd[2];
- int msk;
-
- /* try to create a named file a base for the pipe */
- msk = umask(0);
- fd = creat(name, FIFO_MODE);
- umask(msk);
-
- if (fd >= 0)
- close(fd);
- else
- return 0;
-
- /* create pipe */
- if (pipe(pd) < 0)
- return 0;
-
- /* bind pipe to name */
- if (((fd = ioctl(pd[1], I_PUSH, "connld" )) < 0) ||
- (fattach(pd[1], name) < 0 ))
- return 0;
-
- ppipe = (Pipe*) malloc(sizeof(Pipe));
-
- ppipe->m_hConn = pd[0];
- ppipe->m_hPipe = -1;
-
- strncpy(ppipe->m_Name, name, sizeof(ppipe->m_Name));
- }
- else
- {
- ppipe = (Pipe*) malloc(sizeof(Pipe));
- ppipe->m_hPipe = open(name, O_RDWR);
- ppipe->m_hConn = -1;
- ppipe->m_Name[0] = '\0';
- }
-#endif
-
-#endif
-
- return ppipe;
-}
-
-static void closePipe(Pipe* pipe)
-{
-
-#if defined(IORESOURCE_TRANSFER_SYSV) || defined(IORESOURCE_TRANSFER_BSD)
- if (pipe->m_hPipe != -1)
- close(pipe->m_hPipe);
-
- if (pipe->m_hConn!= -1)
- {
- close(pipe->m_hConn);
-
- if (pipe->m_Name[0] != '\0')
- unlink(pipe->m_Name);
- }
-
- free(pipe);
-#endif
-
-}
-
-static sal_Bool connectPipe(Pipe* pipe)
-{
-
-#ifdef IORESOURCE_TRANSFER_BSD
- int fd;
-
- if ((fd = accept(pipe->m_hConn, NULL, NULL)) < 0)
- return(False);
-
- pipe->m_hPipe = fd;
-
- return sal_True;
-#endif
-
-#ifdef IORESOURCE_TRANSFER_SYSV
- struct strrecvfd recvfd;
-
- if (ioctl(pipe->m_hConn, I_RECVFD, &recvfd) < 0)
- return sal_False;
-
- pipe->m_hPipe = recvfd.fd;
-
- return sal_True;
-#endif
-
-#if !defined(IORESOURCE_TRANSFER_SYSV) && !defined(IORESOURCE_TRANSFER_BSD)
- return sal_False;
-#endif
-
-}
-
-static int send_fd(Pipe* pipe, int fd)
-{
-
-#if defined(IORESOURCE_TRANSFER_SYSV) || defined(IORESOURCE_TRANSFER_BSD)
-
-#ifdef IORESOURCE_TRANSFER_BSD
- struct msghdr msghdr;
- struct iovec iov[1];
- char buffer[2];
-
- struct cmsghdr* cmptr = (struct cmsghdr*)malloc(CONTROLLEN);
-
- iov[0].iov_base = buffer;
- iov[0].iov_len = 2;
- msghdr.msg_iov = iov;
- msghdr.msg_iovlen = 1;
- msghdr.msg_name = NULL;
- msghdr.msg_namelen = 0;
- msghdr.msg_control = (caddr_t) cmptr;
- msghdr.msg_controllen = CONTROLLEN;
-
- cmptr->cmsg_level = SOL_SOCKET;
- cmptr->cmsg_type = SCM_RIGHTS;
- cmptr->cmsg_len = CONTROLLEN;
- *(int*)CMSG_DATA(cmptr) = fd;
-
- if (sendmsg(pipe->m_hPipe, &msghdr, 0) < 0)
- {
- free(cmptr);
- return(-1);
- }
-
- free(cmptr);
-#endif
-
-#ifdef IORESOURCE_TRANSFER_SYSV
- if (ioctl(pipe->m_hPipe, I_SENDFD, fd) < 0)
- return(-1);
-#endif
-
- return(0);
-#endif
-
-#if !defined(IORESOURCE_TRANSFER_SYSV) && !defined(IORESOURCE_TRANSFER_BSD)
- return(-1);
-#endif
-}
-
-static int recv_fd(Pipe* pipe)
-{
- int newFd = -1;
-
-#if defined(IORESOURCE_TRANSFER_SYSV) || defined(IORESOURCE_TRANSFER_BSD)
-
-#ifdef IORESOURCE_TRANSFER_BSD
- struct msghdr msghdr;
- struct iovec iov[1];
- char buffer[PATH_MAX];
-
- struct cmsghdr* cmptr = (struct cmsghdr*)malloc(CONTROLLEN);
-
- iov[0].iov_base = buffer;
- iov[0].iov_len = sizeof(buffer);
- msghdr.msg_name = NULL;
- msghdr.msg_namelen = 0;
- msghdr.msg_iov = iov;
- msghdr.msg_iovlen = 1;
- msghdr.msg_control = (caddr_t) cmptr;
- msghdr.msg_controllen = CONTROLLEN;
-
- if (recvmsg(pipe->m_hPipe, &msghdr, 0) >= 0)
- {
- newFd = *(int*) CMSG_DATA(cmptr);
- }
-
- free(cmptr);
-#endif
-
-#ifdef IORESOURCE_TRANSFER_SYSV
- struct strrecvfd recvfd;
-
- if (ioctl(pipe->m_hPipe, I_RECVFD, &recvfd) >= 0)
- {
- newFd = recvfd.fd;
- }
-#endif
-
-#endif
-
- return(newFd);
-}
-
-/* Callback is called when the socket is closed by the owner */
-static void* socketCloseCallback(void* pArg)
-{
- oslSocketCallbackArg* callbackArg = (oslSocketCallbackArg*) pArg;
- Message msg;
-
- msg.m_Type = MSG_REL;
- msg.m_Data = osl_Process_TypeSocket;
- msg.m_Flags = 0;
- msg.m_Value = callbackArg->m_ident;
- write(callbackArg->m_pipe->m_hPipe, &msg, sizeof(msg));
-
- if (read(callbackArg->m_pipe->m_hPipe, &msg, sizeof(msg)) == sizeof(msg))
- {
- if (msg.m_Type == MSG_END)
- closePipe(callbackArg->m_pipe);
- }
-
- free(callbackArg);
-
- return NULL;
-}
-
-static sal_Bool sendIOResources(Pipe* pipe, oslIOResource ioRes[])
-{
-
-#if defined(IORESOURCE_TRANSFER_SYSV) || defined(IORESOURCE_TRANSFER_BSD)
- int socket;
- Message msg;
- int i = 0;
- oslSocketCallbackArg* callbackArg;
-
- if (connectPipe(pipe))
- {
- while (ioRes[i].Type != osl_Process_TypeNone)
- {
- switch (ioRes[i].Type)
- {
- case osl_Process_TypeSocket:
- {
- socket = ((oslSocketImpl *)(ioRes[0].Descriptor.Socket))->m_Socket;
-
- if (ioRes[i].Flags & osl_Process_DFWAIT)
- {
- callbackArg = (oslSocketCallbackArg*) malloc(sizeof(oslSocketCallbackArg));
-
- callbackArg->m_ident = i;
- callbackArg->m_pipe = pipe;
-
-/* osl_registerSocketCallBack(ioRes[i].Descriptor.Socket,&socketCloseCallback,callbackArg); */
-
- ((oslSocketImpl *)(ioRes[i].Descriptor.Socket))->m_CloseCallback = &socketCloseCallback;
- ((oslSocketImpl *)(ioRes[i].Descriptor.Socket))->m_CallbackArg = callbackArg;
- }
-
- msg.m_Type = MSG_DATA;
- msg.m_Data = osl_Process_TypeSocket;
- msg.m_Flags = ioRes[i].Flags;
- msg.m_Value = i;
-
- if (write(pipe->m_hPipe, &msg, sizeof(msg)) != sizeof(msg))
- {
- OSL_TRACE("Write error to pipe while transfering IO-resources, errno=%d (%s)\n", errno, strerror(errno));
- return sal_False;
- }
- else
- {
- if (send_fd(pipe, socket) < 0)
- {
- OSL_TRACE("IOCTL error at pipe while transfering IO-resources, errno=%d (%s)\n", errno, strerror(errno));
- return sal_False;
- }
- }
- break;
- }
-
- default:
- OSL_TRACE("Not implemented\n");
- OSL_ASSERT(sal_False);
- break;
- }
-
- i++;
- }
-
- msg.m_Type = MSG_END;
- msg.m_Data = osl_Process_TypeNone;
- msg.m_Flags = 0;
- msg.m_Value = 0;
-
- write(pipe->m_hPipe, &msg, sizeof(msg));
-
- if ((read(pipe->m_hPipe, &msg, sizeof(msg)) == sizeof(msg)) &&
- ((msg.m_Type == MSG_ACK) || (msg.m_Type == MSG_END)))
- {
- if (msg.m_Type == MSG_END)
- closePipe(pipe);
-
- return sal_True;
- }
- else
- {
- closePipe(pipe);
-
- return sal_False;
- }
-
- }
-#endif
-
- return sal_False;
-}
-
-
-oslProcessError SAL_CALL osl_getIOResources(oslIOResource Resources[], sal_uInt32 Max)
-{
- oslProcessError ret = osl_Process_E_Unknown;
-
-#if defined(IORESOURCE_TRANSFER_SYSV) || defined(IORESOURCE_TRANSFER_BSD)
- Message msg;
- int wait = 0;
- int i = 0;
- int newFd = -1;
- Pipe* pipe = NULL;
-/* sal_Bool acceptMsg = sal_False;*/
-
- pipe = openPipe(getpid());
-
- while ((read(pipe->m_hPipe, &msg, sizeof(msg)) == sizeof(msg))
- && (msg.m_Type != MSG_END))
- {
- if (i < (int)Max)
- {
- switch (msg.m_Type)
- {
- case MSG_DATA:
- switch (msg.m_Data)
- {
- case osl_Process_TypeSocket:
- if ((newFd = recv_fd(pipe)) >= 0)
- {
- oslSocketImpl *pImpl = __osl_createSocketImpl(newFd);
-
- OSL_ASSERT(i == msg.m_Value);
-
- Resources[i].Type = osl_Process_TypeSocket;
- Resources[i].Flags = msg.m_Flags;
- Resources[i].Descriptor.Socket = (oslSocket)pImpl;
-
- if (msg.m_Flags & osl_Process_DFWAIT)
- wait++;
- }
-
- i++;
-
- break;
-
- default:
- OSL_TRACE("Not implemented\n");
- OSL_ASSERT(sal_False);
- break;
- }
- default:
- break;
- }
- }
- }
-
- Resources[i].Type = osl_Process_TypeNone;
-
- if (msg.m_Type == MSG_END)
- {
- if (wait > 0)
- {
- msg.m_Type = MSG_ACK;
- msg.m_Data = osl_Process_TypeNone;
- msg.m_Flags = 0;
- write(pipe->m_hPipe, &msg, sizeof(msg));
-
- do
- {
- if ((read(pipe->m_hPipe, &msg, sizeof(msg)) != sizeof(msg))
- || (msg.m_Type != MSG_REL))
- break;
-
- i = msg.m_Value;
-
- if (Resources[i].Type != osl_Process_TypeNone)
- {
- OSL_ASSERT(Resources[i].Type == msg.m_Data);
- OSL_ASSERT(Resources[i].Flags & osl_Process_DFWAIT);
-
- Resources[i].Flags &= ~osl_Process_DFWAIT;
-
- if (--wait > 0)
- {
- msg.m_Type = MSG_ACK;
- msg.m_Data = osl_Process_TypeNone;
- msg.m_Flags = 0;
- write(pipe->m_hPipe, &msg, sizeof(msg));
- }
- }
- }
- while (wait > 0);
- }
-
- msg.m_Type = MSG_END;
- msg.m_Data = osl_Process_TypeNone;
- msg.m_Flags = 0;
- write(pipe->m_hPipe, &msg, sizeof(msg));
-
- ret = osl_Process_E_None;
- }
-
- closePipe(pipe);
-
-#endif
-
- return ret;
-}
-
-
/******************************************************************************
*
* New io resource transfer functions
@@ -1208,9 +668,9 @@ sal_Bool sendFdPipe(int PipeFD, int SocketFD)
}
-oslSocketImpl* receiveFdPipe(int PipeFD)
+oslSocket receiveFdPipe(int PipeFD)
{
- oslSocketImpl* pSocket = 0;
+ oslSocket pSocket = 0;
struct msghdr msghdr;
struct iovec iov[1];
char buffer[PATH_MAX];
@@ -1287,11 +747,8 @@ oslSocketImpl* receiveFdPipe(int PipeFD)
return pSocket;
}
-sal_Bool osl_sendResourcePipe(oslPipe Pipe, oslSocket Socket)
+sal_Bool osl_sendResourcePipe(oslPipe pPipe, oslSocket pSocket)
{
- oslSocketImpl* pSocket = (oslSocketImpl*) Socket;
- oslPipeImpl* pPipe = (oslPipeImpl*) Pipe;
-
sal_Bool bRet = sal_False;
if ( pSocket == 0 || pPipe == 0 )
@@ -1305,10 +762,9 @@ sal_Bool osl_sendResourcePipe(oslPipe Pipe, oslSocket Socket)
}
-oslSocket osl_receiveResourcePipe(oslPipe Pipe)
+oslSocket osl_receiveResourcePipe(oslPipe pPipe)
{
- oslPipeImpl* pPipe = (oslPipeImpl*) Pipe;
- oslSocketImpl* pSocket=0;
+ oslSocket pSocket=0;
if ( pPipe == 0 )
{
@@ -1359,13 +815,13 @@ static void ChildStatusProc(void *pData)
create the communiction pipe */
if (data.m_pRes)
{
- pid_t id;
+/* pid_t id; */
- while (((i = read(channel[1], &id, sizeof(id))) < 0))
- {
- if (errno != EINTR)
- break;
- }
+/* while (((i = read(channel[1], &id, sizeof(id))) < 0)) */
+/* { */
+/* if (errno != EINTR) */
+/* break; */
+/* } */
}
if ((data.m_uid != (uid_t)-1) && ((data.m_uid != getuid()) || (data.m_gid != getgid())))
@@ -1421,10 +877,11 @@ static void ChildStatusProc(void *pData)
if (pdata->m_pRes)
{
- rpipe = openPipe(pid);
- write(channel[0], &pid, sizeof(pid));
+/* jbu: removed
+/* rpipe = openPipe(pid); */
+/* write(channel[0], &pid, sizeof(pid)); */
- sendIOResources(rpipe, pdata->m_pRes);
+/* sendIOResources(rpipe, pdata->m_pRes); */
}
while (((i = read(channel[0], &status, sizeof(status))) < 0))
diff --git a/sal/osl/unx/sockimpl.h b/sal/osl/unx/sockimpl.h
index 5df0da81d..7fb3d5503 100644
--- a/sal/osl/unx/sockimpl.h
+++ b/sal/osl/unx/sockimpl.h
@@ -2,9 +2,9 @@
*
* $RCSfile: sockimpl.h,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: mfe $ $Date: 2001-02-26 16:11:46 $
+ * last change: $Author: jbu $ $Date: 2001-03-14 17:18:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -62,7 +62,9 @@
#ifndef _OSL_SOCKETIMPL_H_
#define _OSL_SOCKETIMPL_H_
+#include <osl/pipe.h>
#include <osl/socket.h>
+#include <osl/interlck.h>
#ifdef __cplusplus
extern "C" {
@@ -70,19 +72,37 @@ extern "C" {
typedef void* (*oslCloseCallback) (void*);
-typedef struct _oslSocketImpl {
+struct oslSocketImpl {
int m_Socket;
int m_nLastError;
oslCloseCallback m_CloseCallback;
void* m_CallbackArg;
+ oslInterlockedCount m_nRefCount;
#if defined(LINUX)
sal_Bool m_bIsAccepting;
sal_Bool m_bIsInShutdown;
#endif
-} oslSocketImpl;
+};
-oslSocketImpl* __osl_createSocketImpl(int Socket);
-void __osl_destroySocketImpl(oslSocketImpl *pImpl);
+struct oslSocketAddrImpl
+{
+ sal_Int32 m_nRefCount;
+ struct sockaddr m_sockaddr;
+};
+
+struct oslPipeImpl {
+ int m_Socket;
+ sal_Char m_Name[PATH_MAX + 1];
+ oslInterlockedCount m_nRefCount;
+ sal_Bool m_bClosed;
+#if defined(LINUX)
+ sal_Bool m_bIsAccepting;
+ sal_Bool m_bIsInShutdown;
+#endif
+};
+
+oslSocket __osl_createSocketImpl(int Socket);
+void __osl_destroySocketImpl(oslSocket pImpl);
#ifdef __cplusplus
}