loolwsd/Util.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ loolwsd/Util.hpp | 6 ++++ 2 files changed, 73 insertions(+)
New commits: commit 0e6367c1692b992d7c97eb343fbfcd29eb4185da Author: Henry Castro <hcas...@collabora.com> Date: Sun Sep 27 12:27:40 2015 -0400 loolwsd: add FIFO write, read utilities diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index 85bae00..20229da 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <sys/poll.h> + #include <cstdlib> #include <cstring> #include <string> @@ -165,6 +167,71 @@ namespace Util return std::to_string(signo); } } + + ssize_t writeFIFO(int nPipe, const char* pBuffer, ssize_t nSize) + { + ssize_t nBytes = -1; + ssize_t nCount = 0; + + while(true) + { + nBytes = write(nPipe, pBuffer + nCount, nSize - nCount); + if (nBytes < 0) + { + if (errno == EINTR || errno == EAGAIN) + continue; + + nCount = -1; + break; + } + else if ( nCount + nBytes < nSize ) + { + nCount += nBytes; + } + else + { + nCount = nBytes; + break; + } + } + + return nCount; + } + + ssize_t readFIFO(int nPipe, char* pBuffer, ssize_t nSize) + { + ssize_t nBytes; + do + { + nBytes = read(nPipe, pBuffer, nSize); + } + while ( nBytes < 0 && errno == EINTR ); + + return nBytes; + } + + ssize_t readMessage(int nPipe, char* pBuffer, ssize_t nSize) + { + ssize_t nBytes = -1; + struct pollfd aPoll; + + aPoll.fd = nPipe; + aPoll.events = POLLIN; + aPoll.revents = 0; + + int nPoll = poll(&aPoll, 1, 3000); + if ( nPoll < 0 ) + goto ErrorPoll; + + if ( nPoll == 0 ) + errno = ETIME; + + if( (aPoll.revents & POLLIN) != 0 ) + nBytes = readFIFO(nPipe, pBuffer, nSize); + + ErrorPoll: + return nBytes; + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index 64e48d0..3893011 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -28,6 +28,12 @@ namespace Util void shutdownWebSocket(Poco::Net::WebSocket& ws); std::string signalName(int signo); + + ssize_t writeFIFO(int nPipe, const char* pBuffer, ssize_t nSize); + + ssize_t readFIFO(int nPipe, char* pBuffer, ssize_t nSize); + + ssize_t readMessage(int nPipe, char* pBuffer, ssize_t nSize); }; #endif _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits