[Libreoffice-commits] online.git: Branch 'private/hcvcastro/forking' - loolwsd/Util.cpp loolwsd/Util.hpp
Henry Castro
hcastro at collabora.com
Sun Sep 27 09:27:55 PDT 2015
loolwsd/Util.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
loolwsd/Util.hpp | 6 ++++
2 files changed, 73 insertions(+)
New commits:
commit 0e6367c1692b992d7c97eb343fbfcd29eb4185da
Author: Henry Castro <hcastro at 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
More information about the Libreoffice-commits
mailing list