| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2006-2008 fullmetalcoder <[email protected]> |
| 4 | ** |
| 5 | ** This file is part of the Edyuk project <http://edyuk.org> |
| 6 | ** |
| 7 | ** This file may be used under the terms of the GNU General Public License |
| 8 | ** version 2 as published by the Free Software Foundation and appearing in the |
| 9 | ** file GPL.txt included in the packaging of this file. |
| 10 | ** |
| 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
| 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | ** |
| 14 | ****************************************************************************/ |
| 15 | |
| 16 | #include "qmanagedsocket.h" |
| 17 | |
| 18 | /*! |
| 19 | \file qmanagedsocket.cpp |
| 20 | |
| 21 | \brief Implementation of the QManagedSocket class. |
| 22 | */ |
| 23 | |
| 24 | #include <QTcpSocket> |
| 25 | |
| 26 | QManagedSocket::QManagedSocket(QTcpSocket *s, QObject *p) |
| 27 | : QObject(p), pSocket(s) { |
| 28 | if (!s) qFatal("QManagedSocket fed with invalid socket descriptor..."); |
| 29 | |
| 30 | connect(s, SIGNAL(readyRead()), this, SLOT(readyRead())); |
| 31 | |
| 32 | connect(s, SIGNAL(disconnected()), this, SLOT(deleteLater())); |
| 33 | } |
| 34 | |
| 35 | QManagedSocket::~QManagedSocket() {} |
| 36 | |
| 37 | void QManagedSocket::send(const QByteArray &msg) { pSocket->write(msg); } |
| 38 | |
| 39 | void QManagedSocket::readyRead() { |
| 40 | if (pSocket) { |
| 41 | QString msg = QString::fromUtf8(pSocket->readAll()); |
| 42 | |
| 43 | emit message(msg); |
| 44 | emit message(msg, this); |
| 45 | } |
| 46 | } |