[Libreoffice-commits] core.git: sal/osl
Chris Sherlock
chris.sherlock79 at gmail.com
Sun Jun 25 06:15:25 UTC 2017
sal/osl/unx/pipe.cxx | 195 +++++++++++++++++++++------------------------------
sal/osl/w32/pipe.cxx | 111 ++++++++++++++---------------
2 files changed, 139 insertions(+), 167 deletions(-)
New commits:
commit e7884518b41d5fa94bfab8083c453ae41cc39426
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Sun Jun 25 07:58:32 2017 +1000
osl: whitespace cleanup of pipe.cxx for unx and w32
Change-Id: I9c8933616d36027314c990301e67a54c567429b5
Reviewed-on: https://gerrit.libreoffice.org/39222
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Chris Sherlock <chris.sherlock79 at gmail.com>
diff --git a/sal/osl/unx/pipe.cxx b/sal/osl/unx/pipe.cxx
index 4cda5053cdcd..93da6c3d3a9d 100644
--- a/sal/osl/unx/pipe.cxx
+++ b/sal/osl/unx/pipe.cxx
@@ -34,8 +34,8 @@
#define PIPEDEFAULTPATH "/tmp"
#define PIPEALTERNATEPATH "/var/tmp"
-#define PIPENAMEMASK "OSL_PIPE_%s"
-#define SECPIPENAMEMASK "OSL_PIPE_%s_%s"
+#define PIPENAMEMASK "OSL_PIPE_%s"
+#define SECPIPENAMEMASK "OSL_PIPE_%s_%s"
oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Options, oslSecurity Security);
@@ -68,7 +68,10 @@ static oslPipeError osl_PipeErrorFromNative(int nativeType)
int i = 0;
while ((PipeError[i].error != osl_Pipe_E_invalidError) &&
- (PipeError[i].errcode != nativeType)) i++;
+ (PipeError[i].errcode != nativeType))
+ {
+ i++;
+ }
return PipeError[i].error;
}
@@ -77,15 +80,17 @@ static oslPipe createPipeImpl()
{
oslPipe pPipeImpl;
- pPipeImpl = static_cast<oslPipe>(calloc(1, sizeof(struct oslPipeImpl)));
+ pPipeImpl = static_cast< oslPipe >(calloc(1, sizeof(struct oslPipeImpl)));
if (pPipeImpl == nullptr)
return nullptr;
- pPipeImpl->m_nRefCount =1;
+
+ pPipeImpl->m_nRefCount = 1;
pPipeImpl->m_bClosed = false;
#if defined(CLOSESOCKET_DOESNT_WAKE_UP_ACCEPT)
pPipeImpl->m_bIsInShutdown = false;
pPipeImpl->m_bIsAccepting = false;
#endif
+
return pPipeImpl;
}
@@ -97,23 +102,21 @@ static void destroyPipeImpl(oslPipe pImpl)
oslPipe SAL_CALL osl_createPipe(rtl_uString *ustrPipeName, oslPipeOptions Options, oslSecurity Security)
{
- oslPipe pPipe=nullptr;
- rtl_String* strPipeName=nullptr;
+ oslPipe pPipe = nullptr;
+ rtl_String* strPipeName = nullptr;
- if ( ustrPipeName != nullptr )
+ if (ustrPipeName != nullptr)
{
- rtl_uString2String( &strPipeName,
- rtl_uString_getStr(ustrPipeName),
- rtl_uString_getLength(ustrPipeName),
- osl_getThreadTextEncoding(),
- OUSTRING_TO_OSTRING_CVTFLAGS );
+ rtl_uString2String(&strPipeName,
+ rtl_uString_getStr(ustrPipeName),
+ rtl_uString_getLength(ustrPipeName),
+ osl_getThreadTextEncoding(),
+ OUSTRING_TO_OSTRING_CVTFLAGS);
sal_Char* pszPipeName = rtl_string_getStr(strPipeName);
pPipe = osl_psz_createPipe(pszPipeName, Options, Security);
- if ( strPipeName != nullptr )
- {
+ if (strPipeName != nullptr)
rtl_string_release(strPipeName);
- }
}
return pPipe;
@@ -157,28 +160,23 @@ cpyBootstrapSocketPath(sal_Char *name, size_t len)
oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Options,
oslSecurity Security)
{
- int Flags;
- size_t len;
+ int Flags;
+ size_t len;
struct sockaddr_un addr;
- sal_Char name[PATH_MAX + 1];
+ sal_Char name[PATH_MAX+1];
size_t nNameLength = 0;
bool bNameTooLong = false;
- oslPipe pPipe;
+ oslPipe pPipe;
if (access(PIPEDEFAULTPATH, W_OK) == 0)
- {
strncpy(name, PIPEDEFAULTPATH, sizeof(name));
- }
else if (access(PIPEALTERNATEPATH, W_OK) == 0)
- {
strncpy(name, PIPEALTERNATEPATH, sizeof(name));
- }
else if (!cpyBootstrapSocketPath (name, sizeof (name)))
- {
return nullptr;
- }
- name[sizeof(name) - 1] = '\0'; // ensure the string is NULL-terminated
+
+ name[sizeof(name)-1] = '\0'; // ensure the string is NULL-terminated
nNameLength = strlen(name);
bNameTooLong = nNameLength > sizeof(name) - 2;
@@ -221,7 +219,7 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
/* create socket */
pPipe->m_Socket = socket(AF_UNIX, SOCK_STREAM, 0);
- if ( pPipe->m_Socket < 0 )
+ if (pPipe->m_Socket < 0)
{
SAL_WARN("sal.osl.pipe", "socket() failed: " << strerror(errno));
destroyPipeImpl(pPipe);
@@ -250,15 +248,15 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
len = sizeof(addr);
#endif
- if ( Options & osl_Pipe_CREATE )
+ if (Options & osl_Pipe_CREATE)
{
struct stat status;
/* check if there exists an orphan filesystem entry */
- if ( ( stat(name, &status) == 0) &&
- ( S_ISSOCK(status.st_mode) || S_ISFIFO(status.st_mode) ) )
+ if ((stat(name, &status) == 0) &&
+ (S_ISSOCK(status.st_mode) || S_ISFIFO(status.st_mode)))
{
- if ( connect(pPipe->m_Socket, reinterpret_cast<sockaddr *>(&addr), len) >= 0 )
+ if (connect(pPipe->m_Socket, reinterpret_cast< sockaddr* >(&addr), len) >= 0)
{
close (pPipe->m_Socket);
destroyPipeImpl(pPipe);
@@ -269,10 +267,10 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
}
/* ok, fs clean */
- if ( bind(pPipe->m_Socket, reinterpret_cast<sockaddr *>(&addr), len) < 0 )
+ if (bind(pPipe->m_Socket, reinterpret_cast< sockaddr* >(&addr), len) < 0)
{
SAL_WARN("sal.osl.pipe", "bind() failed: " << strerror(errno));
- close (pPipe->m_Socket);
+ close(pPipe->m_Socket);
destroyPipeImpl(pPipe);
return nullptr;
}
@@ -280,12 +278,12 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
/* Only give access to all if no security handle was specified, otherwise security
depends on umask */
- if ( !Security )
+ if (!Security)
chmod(name,S_IRWXU | S_IRWXG |S_IRWXO);
strncpy(pPipe->m_Name, name, sizeof(pPipe->m_Name) - 1);
- if ( listen(pPipe->m_Socket, 5) < 0 )
+ if (listen(pPipe->m_Socket, 5) < 0)
{
SAL_WARN("sal.osl.pipe", "listen() failed: " << strerror(errno));
// coverity[toctou] cid#1255391 warns about unlink(name) after
@@ -293,7 +291,7 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
// those two clearly unrelated, as it would fail if name existed at
// that point in time:
unlink(name); /* remove filesystem entry */
- close (pPipe->m_Socket);
+ close(pPipe->m_Socket);
destroyPipeImpl(pPipe);
return nullptr;
}
@@ -302,12 +300,11 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
}
/* osl_pipe_OPEN */
- if ( access(name, F_OK) != -1 )
+ if (access(name, F_OK) != -1)
{
- if ( connect( pPipe->m_Socket, reinterpret_cast<sockaddr *>(&addr), len) >= 0 )
- {
+ if (connect(pPipe->m_Socket, reinterpret_cast< sockaddr* >(&addr), len) >= 0)
return pPipe;
- }
+
SAL_WARN("sal.osl.pipe", "connect() failed: " << strerror(errno));
}
@@ -316,60 +313,56 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
return nullptr;
}
-void SAL_CALL osl_acquirePipe( oslPipe pPipe )
+void SAL_CALL osl_acquirePipe(oslPipe pPipe)
{
- osl_atomic_increment( &(pPipe->m_nRefCount) );
+ osl_atomic_increment(&(pPipe->m_nRefCount));
}
-void SAL_CALL osl_releasePipe( oslPipe pPipe )
+void SAL_CALL osl_releasePipe(oslPipe pPipe)
{
-
- if( pPipe == nullptr )
+ if(pPipe == nullptr)
return;
- if( osl_atomic_decrement( &(pPipe->m_nRefCount) ) == 0 )
+ if (osl_atomic_decrement(&(pPipe->m_nRefCount)) == 0)
{
- if( ! pPipe->m_bClosed )
- osl_closePipe( pPipe );
+ if (!pPipe->m_bClosed)
+ osl_closePipe(pPipe);
- destroyPipeImpl( pPipe );
+ destroyPipeImpl(pPipe);
}
}
-void SAL_CALL osl_closePipe( oslPipe pPipe )
+void SAL_CALL osl_closePipe(oslPipe pPipe)
{
int nRet;
int ConnFD;
- if( ! pPipe )
- {
+ if (!pPipe)
return;
- }
- if( pPipe->m_bClosed )
- {
+ if (pPipe->m_bClosed)
return;
- }
ConnFD = pPipe->m_Socket;
- /*
- Thread does not return from accept on linux, so
- connect to the accepting pipe
+ /* Thread does not return from accept on linux, so
+ connect to the accepting pipe
*/
#if defined(CLOSESOCKET_DOESNT_WAKE_UP_ACCEPT)
struct sockaddr_un addr;
- if ( pPipe->m_bIsAccepting )
+ if (pPipe->m_bIsAccepting)
{
pPipe->m_bIsInShutdown = true;
pPipe->m_Socket = -1;
+
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if ( fd < 0 )
+ if (fd < 0)
{
SAL_WARN("sal.osl.pipe", "socket() failed: " << strerror(errno));
return;
}
+
memset(&addr, 0, sizeof(addr));
SAL_INFO("sal.osl.pipe", "osl_destroyPipe : Pipe Name '" << pPipe->m_Name << "'");
@@ -378,44 +371,37 @@ void SAL_CALL osl_closePipe( oslPipe pPipe )
strncpy(addr.sun_path, pPipe->m_Name, sizeof(addr.sun_path) - 1);
size_t len = sizeof(addr);
- nRet = connect( fd, reinterpret_cast<sockaddr *>(&addr), len);
- if ( nRet < 0 )
- {
+ nRet = connect(fd, reinterpret_cast< sockaddr* >(&addr), len);
+ if (nRet < 0)
SAL_WARN("sal.osl.pipe", "connect() failed: " << strerror(errno));
- }
+
close(fd);
}
#endif /* CLOSESOCKET_DOESNT_WAKE_UP_ACCEPT */
nRet = shutdown(ConnFD, 2);
- if ( nRet < 0 )
- {
+ if (nRet < 0)
SAL_WARN("sal.osl.pipe", "shutdown() failed: " << strerror(errno));
- }
nRet = close(ConnFD);
- if ( nRet < 0 )
- {
+ if (nRet < 0)
SAL_WARN("sal.osl.pipe", "close() failed: " << strerror(errno));
- }
+
/* remove filesystem entry */
- if ( strlen(pPipe->m_Name) > 0 )
- {
+ if (strlen(pPipe->m_Name) > 0)
unlink(pPipe->m_Name);
- }
+
pPipe->m_bClosed = true;
}
oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
{
- int s;
+ int s;
oslPipe pAcceptedPipe;
OSL_ASSERT(pPipe);
- if ( pPipe == nullptr )
- {
+ if (pPipe == nullptr)
return nullptr;
- }
OSL_ASSERT(strlen(pPipe->m_Name) > 0);
@@ -436,7 +422,7 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
}
#if defined(CLOSESOCKET_DOESNT_WAKE_UP_ACCEPT)
- if ( pPipe->m_bIsInShutdown )
+ if (pPipe->m_bIsInShutdown)
{
close(s);
return nullptr;
@@ -459,9 +445,7 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
{
flags |= FD_CLOEXEC;
if (fcntl(s, F_SETFD, flags) < 0)
- {
SAL_WARN("sal.osl.pipe", "fcntl() failed: " << strerror(errno));
- }
}
pAcceptedPipe->m_Socket = s;
@@ -477,23 +461,19 @@ sal_Int32 SAL_CALL osl_receivePipe(oslPipe pPipe,
OSL_ASSERT(pPipe);
- if ( pPipe == nullptr )
+ if (pPipe == nullptr)
{
SAL_WARN("sal.osl.pipe", "osl_receivePipe: Invalid socket");
errno=EINVAL;
return -1;
}
- nRet = recv(pPipe->m_Socket,
- pBuffer,
- BytesToRead, 0);
+ nRet = recv(pPipe->m_Socket, pBuffer, BytesToRead, 0);
- if ( nRet < 0 )
- {
+ if (nRet < 0)
SAL_WARN("sal.osl.pipe", "recv() failed: " << strerror(errno));
- }
- return nRet;
+ return nRet;
}
sal_Int32 SAL_CALL osl_sendPipe(oslPipe pPipe,
@@ -504,21 +484,17 @@ sal_Int32 SAL_CALL osl_sendPipe(oslPipe pPipe,
OSL_ASSERT(pPipe);
- if ( pPipe == nullptr )
+ if (pPipe == nullptr)
{
SAL_WARN("sal.osl.pipe", "osl_sendPipe: Invalid socket");
errno=EINVAL;
return -1;
}
- nRet = send(pPipe->m_Socket,
- pBuffer,
- BytesToSend, 0);
+ nRet = send(pPipe->m_Socket, pBuffer, BytesToSend, 0);
- if ( nRet <= 0 )
- {
+ if (nRet <= 0)
SAL_WARN("sal.osl.pipe", "send() failed: " << strerror(errno));
- }
return nRet;
}
@@ -529,11 +505,11 @@ oslPipeError SAL_CALL osl_getLastPipeError(oslPipe pPipe)
return osl_PipeErrorFromNative(errno);
}
-sal_Int32 SAL_CALL osl_writePipe( oslPipe pPipe, const void *pBuffer , sal_Int32 n )
+sal_Int32 SAL_CALL osl_writePipe(oslPipe pPipe, const void *pBuffer, sal_Int32 n)
{
/* loop until all desired bytes were send or an error occurred */
- sal_Int32 BytesSend= 0;
- sal_Int32 BytesToSend= n;
+ sal_Int32 BytesSend = 0;
+ sal_Int32 BytesToSend = n;
OSL_ASSERT(pPipe);
while (BytesToSend > 0)
@@ -543,14 +519,12 @@ sal_Int32 SAL_CALL osl_writePipe( oslPipe pPipe, const void *pBuffer , sal_Int32
RetVal= osl_sendPipe(pPipe, pBuffer, BytesToSend);
/* error occurred? */
- if(RetVal <= 0)
- {
+ if (RetVal <= 0)
break;
- }
BytesToSend -= RetVal;
BytesSend += RetVal;
- pBuffer= static_cast<sal_Char const *>(pBuffer) + RetVal;
+ pBuffer= static_cast< sal_Char const* >(pBuffer) + RetVal;
}
return BytesSend;
@@ -559,25 +533,24 @@ sal_Int32 SAL_CALL osl_writePipe( oslPipe pPipe, const void *pBuffer , sal_Int32
sal_Int32 SAL_CALL osl_readPipe( oslPipe pPipe, void *pBuffer , sal_Int32 n )
{
/* loop until all desired bytes were read or an error occurred */
- sal_Int32 BytesRead= 0;
- sal_Int32 BytesToRead= n;
+ sal_Int32 BytesRead = 0;
+ sal_Int32 BytesToRead = n;
- OSL_ASSERT( pPipe );
+ OSL_ASSERT(pPipe);
while (BytesToRead > 0)
{
sal_Int32 RetVal;
RetVal= osl_receivePipe(pPipe, pBuffer, BytesToRead);
/* error occurred? */
- if(RetVal <= 0)
- {
+ if (RetVal <= 0)
break;
- }
BytesToRead -= RetVal;
BytesRead += RetVal;
- pBuffer= static_cast<sal_Char*>(pBuffer) + RetVal;
+ pBuffer= static_cast< sal_Char* >(pBuffer) + RetVal;
}
+
return BytesRead;
}
diff --git a/sal/osl/w32/pipe.cxx b/sal/osl/w32/pipe.cxx
index 73e26a9c76ed..b2e0547a35b6 100644
--- a/sal/osl/w32/pipe.cxx
+++ b/sal/osl/w32/pipe.cxx
@@ -32,14 +32,14 @@
#include <rtl/alloc.h>
#define PIPESYSTEM "\\\\.\\pipe\\"
-#define PIPEPREFIX "OSL_PIPE_"
+#define PIPEPREFIX "OSL_PIPE_"
typedef struct
{
- sal_uInt32 m_Size;
- sal_uInt32 m_ReadPos;
- sal_uInt32 m_WritePos;
- BYTE m_Data[1];
+ sal_uInt32 m_Size;
+ sal_uInt32 m_ReadPos;
+ sal_uInt32 m_WritePos;
+ BYTE m_Data[1];
} oslPipeBuffer;
@@ -47,7 +47,8 @@ typedef struct
/* oslPipeImpl */
/*****************************************************************************/
-struct oslPipeImpl {
+struct oslPipeImpl
+{
oslInterlockedCount m_Reference;
HANDLE m_File;
HANDLE m_NamedObject;
@@ -57,7 +58,7 @@ struct oslPipeImpl {
HANDLE m_AcceptEvent;
rtl_uString* m_Name;
oslPipeError m_Error;
- bool m_bClosed;
+ bool m_bClosed;
};
/*****************************************************************************/
@@ -68,7 +69,7 @@ oslPipe osl_createPipeImpl(void)
{
oslPipe pPipe;
- pPipe = static_cast<oslPipe>(rtl_allocateZeroMemory(sizeof(struct oslPipeImpl)));
+ pPipe = static_cast< oslPipe >(rtl_allocateZeroMemory(sizeof(struct oslPipeImpl)));
pPipe->m_bClosed = false;
pPipe->m_Reference = 0;
@@ -118,12 +119,12 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options
rtl_uString* temp = nullptr;
oslPipe pPipe;
- PSECURITY_ATTRIBUTES pSecAttr = nullptr;
+ PSECURITY_ATTRIBUTES pSecAttr = nullptr;
rtl_uString_newFromAscii(&path, PIPESYSTEM);
rtl_uString_newFromAscii(&name, PIPEPREFIX);
- if ( Security)
+ if (Security)
{
rtl_uString *Ident = nullptr;
rtl_uString *Delim = nullptr;
@@ -143,13 +144,13 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options
{
PSECURITY_DESCRIPTOR pSecDesc;
- pSecDesc = static_cast<PSECURITY_DESCRIPTOR>(rtl_allocateMemory(SECURITY_DESCRIPTOR_MIN_LENGTH));
+ pSecDesc = static_cast< PSECURITY_DESCRIPTOR >(rtl_allocateMemory(SECURITY_DESCRIPTOR_MIN_LENGTH));
/* add a NULL disc. ACL to the security descriptor */
OSL_VERIFY(InitializeSecurityDescriptor(pSecDesc, SECURITY_DESCRIPTOR_REVISION));
OSL_VERIFY(SetSecurityDescriptorDacl(pSecDesc, TRUE, nullptr, FALSE));
- pSecAttr = static_cast<PSECURITY_ATTRIBUTES>(rtl_allocateMemory(sizeof(SECURITY_ATTRIBUTES)));
+ pSecAttr = static_cast< PSECURITY_ATTRIBUTES >(rtl_allocateMemory(sizeof(SECURITY_ATTRIBUTES)));
pSecAttr->nLength = sizeof(SECURITY_ATTRIBUTES);
pSecAttr->lpSecurityDescriptor = pSecDesc;
pSecAttr->bInheritHandle = TRUE;
@@ -173,11 +174,11 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options
{
SetLastError( ERROR_SUCCESS );
- pPipe->m_NamedObject = CreateMutexW( nullptr, FALSE, SAL_W(name->buffer) );
+ pPipe->m_NamedObject = CreateMutexW(nullptr, FALSE, SAL_W(name->buffer));
- if ( pPipe->m_NamedObject != INVALID_HANDLE_VALUE && pPipe->m_NamedObject != nullptr )
+ if (pPipe->m_NamedObject != INVALID_HANDLE_VALUE && pPipe->m_NamedObject != nullptr)
{
- if ( GetLastError() != ERROR_ALREADY_EXISTS )
+ if (GetLastError() != ERROR_ALREADY_EXISTS)
{
pPipe->m_Security = pSecAttr;
rtl_uString_assign(&pPipe->m_Name, name);
@@ -202,7 +203,7 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options
}
else
{
- CloseHandle( pPipe->m_NamedObject );
+ CloseHandle(pPipe->m_NamedObject);
pPipe->m_NamedObject = INVALID_HANDLE_VALUE;
}
}
@@ -217,7 +218,7 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options
fPipeAvailable = WaitNamedPipeW(SAL_W(path->buffer), NMPWAIT_WAIT_FOREVER);
/* first try to open system pipe */
- if ( fPipeAvailable )
+ if (fPipeAvailable)
{
pPipe->m_File = CreateFileW(
SAL_W(path->buffer),
@@ -228,11 +229,11 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
nullptr);
- if ( pPipe->m_File != INVALID_HANDLE_VALUE )
+ if (pPipe->m_File != INVALID_HANDLE_VALUE)
{
// We got it !
- rtl_uString_release( name );
- rtl_uString_release( path );
+ rtl_uString_release(name);
+ rtl_uString_release(path);
return pPipe;
}
@@ -250,30 +251,30 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options
return nullptr;
}
-void SAL_CALL osl_acquirePipe( oslPipe pPipe )
+void SAL_CALL osl_acquirePipe(oslPipe pPipe)
{
- osl_atomic_increment( &(pPipe->m_Reference) );
+ osl_atomic_increment(&(pPipe->m_Reference));
}
-void SAL_CALL osl_releasePipe( oslPipe pPipe )
+void SAL_CALL osl_releasePipe(oslPipe pPipe)
{
// OSL_ASSERT( pPipe );
- if( nullptr == pPipe )
+ if (nullptr == pPipe)
return;
- if( 0 == osl_atomic_decrement( &(pPipe->m_Reference) ) )
+ if (0 == osl_atomic_decrement(&(pPipe->m_Reference)))
{
- if( ! pPipe->m_bClosed )
- osl_closePipe( pPipe );
+ if (!pPipe->m_bClosed)
+ osl_closePipe(pPipe);
- osl_destroyPipeImpl( pPipe );
+ osl_destroyPipeImpl(pPipe);
}
}
-void SAL_CALL osl_closePipe( oslPipe pPipe )
+void SAL_CALL osl_closePipe(oslPipe pPipe)
{
- if( pPipe && ! pPipe->m_bClosed )
+ if(pPipe && !pPipe->m_bClosed)
{
pPipe->m_bClosed = true;
/* if we have a system pipe close it */
@@ -291,9 +292,9 @@ void SAL_CALL osl_closePipe( oslPipe pPipe )
/*****************************************************************************/
oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
{
- oslPipe pAcceptedPipe = nullptr;
+ oslPipe pAcceptedPipe = nullptr;
- OVERLAPPED os;
+ OVERLAPPED os;
DWORD nBytesTransfered;
rtl_uString* path = nullptr;
@@ -306,9 +307,9 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
os.hEvent = pPipe->m_AcceptEvent;
ResetEvent(pPipe->m_AcceptEvent);
- if ( !ConnectNamedPipe(pPipe->m_File, &os))
+ if (!ConnectNamedPipe(pPipe->m_File, &os))
{
- switch ( GetLastError() )
+ switch (GetLastError())
{
case ERROR_PIPE_CONNECTED: // Client already connected to pipe
case ERROR_NO_DATA: // Client was connected but has already closed pipe end
@@ -319,12 +320,12 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
case ERROR_IO_PENDING: // This is normal if not client is connected yet
case ERROR_MORE_DATA: // Should not happen
// blocking call to accept
- if( !GetOverlappedResult( pPipe->m_File, &os, &nBytesTransfered, TRUE ) )
+ if( !GetOverlappedResult(pPipe->m_File, &os, &nBytesTransfered, TRUE))
{
// Possible error could be that between ConnectNamedPipe and GetOverlappedResult a connect
// took place.
- switch ( GetLastError() )
+ switch (GetLastError())
{
case ERROR_PIPE_CONNECTED: // Pipe was already connected
case ERROR_NO_DATA: // Pipe was connected but client has already closed -> ver fast client ;-)
@@ -360,7 +361,7 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
4096, 4096,
NMPWAIT_WAIT_FOREVER,
pAcceptedPipe->m_Security);
- rtl_uString_release( path );
+ rtl_uString_release(path);
return pAcceptedPipe;
}
@@ -373,7 +374,7 @@ sal_Int32 SAL_CALL osl_receivePipe(oslPipe pPipe,
sal_Int32 BytesToRead)
{
DWORD nBytes;
- OVERLAPPED os;
+ OVERLAPPED os;
OSL_ASSERT(pPipe);
@@ -382,9 +383,9 @@ sal_Int32 SAL_CALL osl_receivePipe(oslPipe pPipe,
ResetEvent(pPipe->m_ReadEvent);
- if (! ReadFile(pPipe->m_File, pBuffer, BytesToRead, &nBytes, &os) &&
+ if (!ReadFile(pPipe->m_File, pBuffer, BytesToRead, &nBytes, &os) &&
((GetLastError() != ERROR_IO_PENDING) ||
- ! GetOverlappedResult(pPipe->m_File, &os, &nBytes, TRUE)))
+ !GetOverlappedResult(pPipe->m_File, &os, &nBytes, TRUE)))
{
DWORD lastError = GetLastError();
@@ -412,7 +413,7 @@ sal_Int32 SAL_CALL osl_sendPipe(oslPipe pPipe,
sal_Int32 BytesToSend)
{
DWORD nBytes;
- OVERLAPPED os;
+ OVERLAPPED os;
OSL_ASSERT(pPipe);
@@ -420,7 +421,7 @@ sal_Int32 SAL_CALL osl_sendPipe(oslPipe pPipe,
os.hEvent = pPipe->m_WriteEvent;
ResetEvent(pPipe->m_WriteEvent);
- if (! WriteFile(pPipe->m_File, pBuffer, BytesToSend, &nBytes, &os) &&
+ if (!WriteFile(pPipe->m_File, pBuffer, BytesToSend, &nBytes, &os) &&
((GetLastError() != ERROR_IO_PENDING) ||
! GetOverlappedResult(pPipe->m_File, &os, &nBytes, TRUE)))
{
@@ -435,11 +436,11 @@ sal_Int32 SAL_CALL osl_sendPipe(oslPipe pPipe,
return nBytes;
}
-sal_Int32 SAL_CALL osl_writePipe( oslPipe pPipe, const void *pBuffer , sal_Int32 n )
+sal_Int32 SAL_CALL osl_writePipe(oslPipe pPipe, const void *pBuffer , sal_Int32 n)
{
/* loop until all desired bytes were send or an error occurred */
- sal_Int32 BytesSend= 0;
- sal_Int32 BytesToSend= n;
+ sal_Int32 BytesSend = 0;
+ sal_Int32 BytesToSend = n;
OSL_ASSERT(pPipe);
while (BytesToSend > 0)
@@ -449,26 +450,24 @@ sal_Int32 SAL_CALL osl_writePipe( oslPipe pPipe, const void *pBuffer , sal_Int32
RetVal= osl_sendPipe(pPipe, pBuffer, BytesToSend);
/* error occurred? */
- if(RetVal <= 0)
- {
+ if (RetVal <= 0)
break;
- }
BytesToSend -= RetVal;
BytesSend += RetVal;
- pBuffer= static_cast<sal_Char const *>(pBuffer) + RetVal;
+ pBuffer= static_cast< sal_Char const* >(pBuffer) + RetVal;
}
return BytesSend;
}
-sal_Int32 SAL_CALL osl_readPipe( oslPipe pPipe, void *pBuffer , sal_Int32 n )
+sal_Int32 SAL_CALL osl_readPipe(oslPipe pPipe, void *pBuffer, sal_Int32 n)
{
/* loop until all desired bytes were read or an error occurred */
- sal_Int32 BytesRead= 0;
- sal_Int32 BytesToRead= n;
+ sal_Int32 BytesRead = 0;
+ sal_Int32 BytesToRead = n;
- OSL_ASSERT( pPipe );
+ OSL_ASSERT(pPipe);
while (BytesToRead > 0)
{
sal_Int32 RetVal;
@@ -476,13 +475,11 @@ sal_Int32 SAL_CALL osl_readPipe( oslPipe pPipe, void *pBuffer , sal_Int32 n )
/* error occurred? */
if(RetVal <= 0)
- {
break;
- }
BytesToRead -= RetVal;
BytesRead += RetVal;
- pBuffer= static_cast<sal_Char*>(pBuffer) + RetVal;
+ pBuffer= static_cast< sal_Char* >(pBuffer) + RetVal;
}
return BytesRead;
}
@@ -500,7 +497,9 @@ oslPipeError SAL_CALL osl_getLastPipeError(oslPipe pPipe)
pPipe->m_Error = osl_Pipe_E_None;
}
else
+ {
Error = osl_Pipe_E_NotFound;
+ }
return Error;
}
More information about the Libreoffice-commits
mailing list