From c90c389a8a8d9d8661e9772ec4144c5cf2039f23 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- libksirtet/lib/smanager.h | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 libksirtet/lib/smanager.h (limited to 'libksirtet/lib/smanager.h') diff --git a/libksirtet/lib/smanager.h b/libksirtet/lib/smanager.h new file mode 100644 index 00000000..a831b702 --- /dev/null +++ b/libksirtet/lib/smanager.h @@ -0,0 +1,88 @@ +#ifndef SMANAGER_H +#define SMANAGER_H + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#ifdef HAVE_SYS_SELECT_H +#include // Needed on some systems. +#endif + +#include + +#include "socket.h" + +/** + * The SocketManager class is useful to manage (rw, ro, wo) sockets. + * + * You must add the sockets you want to manage to this class before other + * operations. The sockets are stored in an array and other methods reference + * the sockets by their index in that array. + */ +class SocketManager +{ + public: + SocketManager(); + + /** Be aware that unremoved sockets will be closed there. */ + ~SocketManager(); + + /** Remove all sockets and close them. */ + void clean(); + + enum SocketProperty { ReadOnly, WriteOnly, ReadWrite }; + + /** @return the number of sockets. */ + uint size() const { return sockets.size(); } + + const Socket *operator[](uint i) const { return sockets[i]; } + Socket *operator [](uint i) { return sockets[i]; } + + /** @return the index of the socket (-1 if not present). */ + int find(int fd); + + /** + * Append a socket at the end of the array of sockets. + * @param sp determines if the socket will be used for ReadWrite, + * ReadOnly or WriteOnly operations. + * @return the index of the socket. + */ + uint append(Socket *, SocketProperty sp = ReadWrite); + + /** + * Remove the socket indexed i. Note that the following sockets in + * the array will have their index decremented by one. + * @param deleteSocket if true, the socket is deleted + */ + void remove(uint i, bool deleteSocket); + + /** @return TRUE if it is possible to write to all the writeable sockets. */ + bool canWriteAll(uint sec = 0, uint usec = 0); + + /** @return TRUE if it is possible to write to the specified socket. */ + bool canWrite(uint i, uint sec = 0, uint usec = 0); + + Stream &commonWritingStream() { return writing; } + bool writeCommon(uint i); // do not clear stream + + /** + * Check if there are pending data on at least one of the readeable + * socket. + */ + bool checkPendingData(uint sec = 0, uint usec = 0); + + bool dataPending(uint i); + + private: + QMemArray sockets; + + fd_set read_set, write_set, read_tmp, write_tmp; + struct timeval tv; + int max_fd; + uint nbWriteable; + + WritingStream writing; +}; + +#endif // SMANAGER_H -- cgit v1.2.1