summaryrefslogtreecommitdiffstats
path: root/libksirtet/lib/socket.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /libksirtet/lib/socket.cpp
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
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
Diffstat (limited to 'libksirtet/lib/socket.cpp')
-rw-r--r--libksirtet/lib/socket.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/libksirtet/lib/socket.cpp b/libksirtet/lib/socket.cpp
new file mode 100644
index 00000000..9ef3ba3c
--- /dev/null
+++ b/libksirtet/lib/socket.cpp
@@ -0,0 +1,80 @@
+#include "socket.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+#include <ctype.h>
+#include <netdb.h>
+#include <sys/utsname.h>
+#include <stdlib.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h> // for FIONREAD
+#endif
+
+Socket::Socket(KExtendedSocket *s, bool createNotifier,
+ QObject *parent, const char *name)
+: _socket(s), _notifier(0)
+{
+ Q_ASSERT(s);
+ if (createNotifier) {
+ _notifier = new QSocketNotifier(s->fd(), QSocketNotifier::Read,
+ parent, name);
+ _notifier->setEnabled(FALSE);
+ }
+}
+
+Socket::~Socket()
+{
+ delete _notifier;
+ delete _socket;
+}
+
+bool Socket::write(const QByteArray &a)
+{
+ return ( _socket->writeBlock(a.data(), a.size())==(int)a.size() );
+}
+
+bool Socket::write()
+{
+ bool res = write(writing.buffer());
+ writing.clear();
+ return res;
+}
+
+int Socket::pendingData() const
+{
+ int size = 0;
+ if ( ioctl(_socket->fd(), FIONREAD, (char *)&size)<0 ) return -1;
+ return size;
+}
+
+int Socket::read()
+{
+ reading.clearRead();
+
+ int size = pendingData();
+ if ( size==-1 ) return -1;
+
+ reading.device()->close();
+ int dec = reading.size();
+ reading.buffer().resize(dec + size);
+ size = _socket->readBlock(reading.buffer().data() + dec, size);
+ if ( size==-1 ) reading.buffer().resize(dec);
+ reading.device()->open(IO_ReadOnly);
+
+ return size;
+}
+
+int Socket::accept(KExtendedSocket *&s)
+{
+ return _socket->accept(s);
+}