Mail Archives: cygwin/2020/03/31/01:40:34
X-Recipient: | archive-cygwin AT delorie DOT com
|
X-Original-To: | cygwin AT cygwin DOT com
|
Delivered-To: | cygwin AT cygwin DOT com
|
DMARC-Filter: | OpenDMARC Filter v1.3.2 sourceware.org 18ABF385B835
|
Authentication-Results: | sourceware.org;
|
| dmarc=none (p=none dis=none) header.from=dillinger.biz
|
Authentication-Results: | sourceware.org;
|
| spf=pass smtp.mailfrom=Raimund DOT Paulus AT dillinger DOT biz
|
From: | "PAULUS, Raimund, TI-ABN" <Raimund DOT Paulus AT dillinger DOT biz>
|
To: | "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
|
Subject: | Re: Problems using Qt5 and Apache Thrift
|
Thread-Topic: | Problems using Qt5 and Apache Thrift
|
Thread-Index: | AdYHHlmeqoZEjLByQX2+3fmfWANEuw==
|
Date: | Tue, 31 Mar 2020 05:39:41 +0000
|
Message-ID: | <0211a4f2fd564f41a5722b33586e8c02@resw122.resdom01.local>
|
Accept-Language: | en-US
|
X-MS-Has-Attach: | |
X-MS-TNEF-Correlator: | |
x-ms-exchange-transport-fromentityheader: | Hosted
|
x-originating-ip: | [172.18.22.70]
|
MIME-Version: | 1.0
|
X-Virus-Scanned: | clamav-milter 0.99.3 at mailrelay.dillinger.de
|
X-Virus-Status: | Clean
|
X-Spam-Status: | No, score=-6.7 required=5.0 tests=BAYES_00, GIT_PATCH_2,
|
| KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_NONE,
|
| SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2
|
X-Spam-Checker-Version: | SpamAssassin 3.4.2 (2018-09-13) on
|
| server2.sourceware.org
|
X-BeenThere: | cygwin AT cygwin DOT com
|
X-Mailman-Version: | 2.1.29
|
List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com>
|
List-Archive: | <http://cygwin.com/pipermail/cygwin/>
|
List-Post: | <mailto:cygwin AT cygwin DOT com>
|
List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help>
|
List-Subscribe: | <http://cygwin.com/mailman/listinfo/cygwin>,
|
| <mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
|
Sender: | "Cygwin" <cygwin-bounces AT cygwin DOT com>
|
X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id 02V5eCLP019702
|
In the meantime i tested using a thread for the Thrift-connection to my service.
If the thread is started, messages are sent in a loop to the service and a sleep() is included so that i have enough time to check the connection via netstat command.
The result is the same as in my first attempt. The network connection is broken after line 27 (create the QPushButton) in main.cpp. The thread prints the error message:
"Thrift: Mon Mar 30 18:45:27 2020 TSocket::write_partial() send() <Host: 192.168.178.200 Port: 9090>Broken pipe"
Here are the sources:
main.cpp:
1 #include <stdio.h>
2
3 #include <QApplication>
4 #include <QWidget>
5 #include <QPushButton>
6 #include <QThread>
7
8 #include "thrift_clnt.hpp"
9
10 int main(int argc, char **argv) {
11
12 printf("Stop 1; Press <Enter> to continue"); getchar();
13
14 QApplication app(argc, argv);
15
16 QThread* thread = new QThread();
17 ThriftClnt* thrift_cl = new ThriftClnt;
18 thrift_cl->moveToThread(thread);
19 QObject::connect(thread, SIGNAL(started()), thrift_cl, SLOT (process()));
20 QObject::connect(thrift_cl, SIGNAL (finished()), thread, SLOT (quit()));
21 QObject::connect(thrift_cl, SIGNAL (finished()), thrift_cl, SLOT (deleteLater()));
22 QObject::connect(thread, SIGNAL (finished()), thread, SLOT (deleteLater()));
23 thread->start();
24
25 printf("Stop 2; Press <Enter> to continue"); getchar();
26
27 QPushButton *b_end = new QPushButton("End");
28
29 printf("Stop 3; Press <Enter> to continue"); getchar();
30
31 QObject::connect(b_end, SIGNAL(clicked()), &app, SLOT(quit()));
32
33 printf("Stop 4; Press <Enter> to continue"); getchar();
34
35 b_end->show();
36
37 printf("Stop 6; Press <Enter> to continue"); getchar();
38
39 app.exec();
40
41 thread->wait(); // do not exit before the thread is completed!
42
43 }
thrift_clnt.hpp:
1 #ifndef __THRIFT_CLNT_HPP
2 #define __THRIFT_CLNT_HPP
3
4 #include <QObject>
5
6 class ThriftClnt : public QObject
7 {
8 Q_OBJECT
9
10 public:
11 ThriftClnt();
12 ~ThriftClnt();
13
14 public slots:
15 void process();
16
17 signals:
18 void finished();
19 void error(QString err);
20
21 private:
22 // add your variables here
23 };
24
25 #endif // __THRIFT_CLNT_HPP
thrift_clnt.cpp:
1 #include "thrift_clnt.hpp"
2
3 #include <thrift/protocol/TBinaryProtocol.h>
4 #include <thrift/transport/TSocket.h>
5 #include <thrift/transport/TTransportUtils.h>
6 #include <thrift/stdcxx.h>
7
8 #include "../gen-cpp/Calculator.h"
9
10 using namespace std;
11 using namespace apache::thrift;
12 using namespace apache::thrift::protocol;
13 using namespace apache::thrift::transport;
14
15 using namespace tutorial;
16 using namespace shared;
17
18 ThriftClnt::ThriftClnt() {
19 }
20
21 ThriftClnt::~ThriftClnt() {
22 }
23
24 void ThriftClnt::process()
25 {
26
27 stdcxx::shared_ptr<TTransport> socket(new TSocket("192.168.178.200", 9090));
28 // stdcxx::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
29
30 stdcxx::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
31 stdcxx::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
32
33 CalculatorClient client(protocol);
34
35 try {
36 transport->open();
37
38 char txt[128];
39 for(int i=1; 1<20; i++)
40 {
41 sprintf(txt, "%d + %d = %d", i, i, client.add(i, i));
42 sleep(5);
43 }
44
45 } catch (TException& tx) {
46 printf("ERROR: %s\n", tx.what());
47 }
48
49 emit finished();
50 }
51
QT-Thrift.pro:
1 ######################################################################
2 # Automatically generated by qmake (3.0) Mo. März 23 15:29:31 2020
3 ######################################################################
4
5 QT += core gui widgets
6
7 TEMPLATE = app
8 TARGET = QtClient
9 INCLUDEPATH += .
10 INCLUDEPATH += ../gen-cpp
11
12 linux: {
13 TOOLS_DIR = /software/tools
14 }
15
16 cygwin: {
17 TOOLS_DIR = /cygdrive/e/Software/Cygwin/2_5_2-tools
18 }
19
20 # directories for thrift
21 TOOLS_INCL = $${TOOLS_DIR}/include
22 TOOLS_LIB = $${TOOLS_DIR}/lib
23
24 INCLUDEPATH += $${TOOLS_INCL}
25
26 LIBS += -L $${TOOLS_LIB} -lthrift
27
28 # Input
29 HEADERS += thrift_clnt.hpp ../gen-cpp/Calculator.h
30
31 SOURCES += main.cpp thrift_clnt.cpp \
32 ../gen-cpp/Calculator.cpp \
33 ../gen-cpp/SharedService.cpp \
34 ../gen-cpp/shared_constants.cpp \
35 ../gen-cpp/shared_types.cpp \
36 ../gen-cpp/tutorial_constants.cpp \
37 ../gen-cpp/tutorial_types.cpp \
The modules in directory gen-cpp are built with the Thrift compiler in Linux. The Thrift libs are built in Cygwin after unpacking the tar ball thrift-0.11.0.tar.gz
with the commands:
>./bootstrap.sh
>export CXXFLAGS="-D_HAVE_SYS_TIME_H -DPTHREAD_MUTEX_RECURSIVE_NP=PTHREAD_MUTEX_RECURSIVE -O2 -std=gnu++11 -D_GNU_SOURCE"
>./configure --with-qt4=no --with-qt5=no --with-csharp=no --with-java=no \
--with-erlang=no --with-nodejs=no --with-lua=no --with-python=no --with-perl=no \
--with-php=no --with-php_extension=no --with-dart=no --with-ruby=no --with-haskell=no \
--with-go=no --with-rs=no --with-cl=no --with-haxe=no --with-dotnetcore=no --with-d=no \
--disable-tests --prefix=/cygdrive/e/Software/Cygwin/2_5_2-tools
> make
> make install
Greetings
Raimund Paulus
> -----Ursprüngliche Nachricht-----
> Von: Cygwin [mailto:cygwin-bounces AT cygwin DOT com] Im Auftrag von PAULUS,
> Raimund, TI-ABN
> Gesendet: Donnerstag, 26. März 2020 07:59
> An: 'cygwin AT cygwin DOT com'
> Betreff: Re: Problems using Qt5 and Apache Thrift
>
> Hello Andrey Repin
>
> The sources and the documentation are her:
>
> https://thrift.apache.org/tutorial/cpp
>
> You must have libthrift installed.
>
> Maybe using threads is a better programming style, but i don't know, if it solves the
> problem. I use connecting and disconnecting to the service like braces around the
> rest of the application. At some points the application transfers data to the service
> and expects an answer. It is a synchronous communication and i use it like RPC
> (remote procedure call). The client sends a request and the service has to respond.
> Without the response the client cannot continue. Every client has its own service.
>
> Greetings
>
> Ramund Paulus
>
> > -----Ursprüngliche Nachricht-----
> > Von: Andrey Repin [mailto:anrdaemon AT yandex DOT ru]
> > Gesendet: Mittwoch, 25. März 2020 12:13
> > An: PAULUS, Raimund, TI-ABN; cygwin AT cygwin DOT com
> > Betreff: Re: Problems using Qt5 and Apache Thrift
> >
> > Greetings, PAULUS, Raimund, TI-ABN!
> >
> > > Problems using Qt5 and Apache Thrift
> >
> > ...snip...
> >
> > > Now i want to implement the interface parts with Qt 5. Here is the new program
> > sequence:
> >
> > > //------------------------------------------------------------------------------
> > > program starts
> > > step 1: make the connection to the Linux server (Apache Thrift)
> > > step 2: initialize Qt interface (create widgets, buttons, ...)
> > > step 3: user interface (Qt)
> > > step 4: data transfer PC <-> Linux-Host (Apache Thrift)
> > > step 5: user interface (Qt)
> > > step 6: data transfer PC <-> Linux-Host (Apache Thrift)
> > > ...
> > > ...
> > > ...
> > > step n-1: end Qt app
> > > step n: close the connection to the host (Apache Thrift)
> > > program ends
> > > //------------------------------------------------------------------------------
> >
> > > During step 2 the connection to the linux server is broken. You can see it
> > > with the netstat command. First error message arises in step 4:
> >
> > > "TSocket::write_partial() send() <Host: my_host Port: 9090>Broken pipe"
> >
> > I strongly suggest placing communication service in its own thread.
> > Then you could manage connection without having to worry about blocking
> > timeouts caused by GUI operations.
> > They will run asynchronously.
> >
> > > On a Linux box the client program runs perfectly.
> >
> > Only by coincidence, I suppose.
> >
> > > On the windows box the program works, if i initalize Qt before the
> > > connection to the server is made (step 2 before step 1). But that is not
> > > acceptable for me, because afterwards other widgets and buttons are created
> > > and i can not close and create the connection at each point.
> >
> > I suppose, the server dropping connection by timeout. But I'd urge you to
> > investigate this further.
> >
> > > For the tests I used the examples from the Apache Thrift Tutorial.
> >
> > Please include examples as text/plain attachments, if they are longer than a
> > few lines.
> >
> >
> > --
> > With best regards,
> > Andrey Repin
> > Wednesday, March 25, 2020 14:08:25
> >
> > Sorry for my terrible english...
>
> --
> Problem reports: https://cygwin.com/problems.html
> FAQ: https://cygwin.com/faq/
> Documentation: https://cygwin.com/docs.html
> Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
>
--
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
- Raw text -