[Libreoffice-commits] online.git: loolwsd/Util.cpp loolwsd/Util.hpp
Henry Castro
hcastro at collabora.com
Wed Dec 23 09:07:14 PST 2015
loolwsd/Util.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
loolwsd/Util.hpp | 6 ++++
2 files changed, 73 insertions(+)
New commits:
commit 961f853d6d19021075c5afdd5289e2e50def9f79
Author: Henry Castro <hcastro at collabora.com>
Date: Sun Dec 13 12:04:45 2015 -0500
loolwsd: Added FIFO utils.
Change-Id: Ifc4e3dafce669c615d5f0d156227f31fcf959936
Reviewed-on: https://gerrit.libreoffice.org/20896
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Henry Castro <hcastro at collabora.com>
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 02a2c2f..9d74278 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 <iomanip>
@@ -193,6 +195,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 02a21d6..7a82fa4 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -31,6 +31,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
More information about the Libreoffice-commits
mailing list