11 SocketList::SocketList(QObject *parent) : QObject(parent) {
13 m_parentThread = QThread::currentThread();
17 SocketList *SocketList::socketList(QObject *parent) {
18 if (m_socketList == NULL) {
26 if (m_line_socket.contains(line)) {
30 m_line_hostname[line] = hostname;
31 m_line_port [line] = port;
32 m_line_socket [line] = NULL;
38 qDebug() <<
"SocketList::open()" << line;
40 if (m_parentThread != QThread::currentThread()) {
41 qFatal(
"Parent's thread not equals to currentThread in SocketList::open");
44 if (!m_line_socket.contains(line)) {
45 qFatal(
"SocketList::open(line) line does not exist");
48 if (m_line_socket[line] != NULL) {
49 QTcpSocket *
socket = m_line_socket[line];
51 socket->deleteLater();
52 qDebug() <<
"SocketList::open() delete socket" <<
socket;
55 QTcpSocket *
socket =
new QTcpSocket(
this);
56 socket->connectToHost( m_line_hostname[line], m_line_port[line]);
57 if (!socket->waitForConnected()) {
58 qDebug() <<
"SocketList::open() could not open to host" << m_line_hostname[line] << m_line_port[line] <<
socket;
59 socket->deleteLater();
60 throw tr(
"Could not connect to %1:%2").arg(m_line_hostname[line]).arg(m_line_port[line]);
63 m_line_socket[line] =
socket;
68 if (m_parentThread != QThread::currentThread()) {
69 qFatal(
"Parent's thread not equals to currentThread in SocketList::open");
72 if (!m_line_socket.contains(line)) {
73 throw tr(
"Socket for line %1 does not exists").arg(line);
76 QTcpSocket *
socket = m_line_socket[line];
79 socket = m_line_socket[line];
void addLine(int line, const QString &hostname, int port)
Adds new line to list.
QTcpSocket * socket(int line)
Returns socket associated with line.
void open(int line)
Opens socket for line.