Unsolved Linux embedded device Qt5.3/5.6 QTcpServer does not emit the newConnection() signal,accept() returns UnsupportedSocketOperationError or UnknownSocketError.
-
Qt example code on Linux embedded device as server(my own code is the same).Network assist tool on PC as client.I tried running two versions of the Server(Example code),both of them didn't worked.
note:
1.My own application and official example can run on the local environment,but not on Linux Embedded device.
2.by using netstat -an show that the connect is ESTABLISHED,i tried every possible way to fix it(change port,different version Qt,check Firewall,event loop and so on),but all didn't work.
3.I implemented by Posix C,it worked.I have no ideas about it,has anyone encountered the same problem,help me plz!!!
more info:
Do netstat -an after client has successfully connected on QTcpServer.The connection is 'ESTABLISHED' but connect(tcpServer, &QTcpServer::acceptError,this,&Server::myError) return QAbstractSocket::UnknownSocketError.So Qt dont emit QTcpServer::newConnection in this case(i had read the Qt source code).[root]# ./QtNetworkTest &
[root]# debug mode
[root]# myError: QAbstractSocket::UnknownSocketError
[root]# netstat -na
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN
tcp 1 0 192.168.20.62:8001 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:37 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:7 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:13 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 192.168.20.62:8001 192.168.20.171:24489 ESTABLISHED
udp 0 0 0.0.0.0:7 0.0.0.0:*
udp 0 0 0.0.0.0:13 0.0.0.0:*
udp 0 0 0.0.0.0:37 0.0.0.0:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
STREAM CONNECTED 1731
STREAM CONNECTED 1730 -
Hi @lanlan and welcome
I'm afraid you would need to share some of your code otherwise all anyone can do is take a guess.
And that's what I will do now.
90% off the time the reason for "Signal XY is not emitted/slot yz is not called" is due to QThread::sleep calls.Do you do that?
-
@J-Hilk
Thx for reply very much.
Never called QThread::sleep().I ran Qt example code in main thread,and it worked on local system,the same as my own code.So I think the reason is not related to code implementation.Maybe it caused by Embedded system configuration or Qt cross-compilation error,but i can not find the point. -
Hi,
Are you trying to connect two applications built with different versions of Qt ?
-
@SGaist Hi,thank you for the help.
Qt example code on Linux embedded device as server(my own code is the same).Network assist tool on PC as client.At first,I thought there was something wrong with my implementation,so I tried official example code.Then i tried running two versions Qt of the Server(Example code),both of them didn't work.
I also used QT_DEBUG_PLUGINS=1,the result is here:
Found metadata in lib /opt/5.6armQt/plugins/bearer/libqnmbearer.so, metadata=
{
"IID": "org.qt-project.Qt.QBearerEngineFactoryInterface",
"MetaData": {
"Keys": [
"networkmanager"
]
},
"className": "QNetworkManagerEnginePlugin",
"debug": true,
"version": 329219
}It seems to be correct.
-
Can you run the server on your desktop and the client on your device ? Does it work ?
-
@SGaist
I get your point,but I am sure the program is ok.Because it can run on other devices.Maybe the problem caused by linux kernel version,i will deep into Qt source code.I debugged source code,log is here:
QTcpServer::QTcpServer(0xbe9d1b04)
QTcpServer::listen(8001, "192.168.20.62") == true (listening on port 8001)
pendingConnections.count(): 0
maxConnections: 30
QNativeSocketEngine::accept() in !
Unix QNativeSocketEnginePrivate::nativeAccept()!
QT_THREADSAFE_CLOEXEC!
do accept4 fd:-1!
acceptedDescriptor: -1
errno: 94
descriptor: -1
myError: QAbstractSocket::UnknownSocketErrorI wonder why it uses accept4() instead of accept().Amazing....
So,let me find the point....
-
I used accpet() instead.
I dont know the root cause the problem.
And I can't predict what the consequences of this modification will be.But the code works fine.
So I keep the question and wait for the big one to solve.
-
What kernel version are you running ?
Any parameter specific to that board ? -
@SGaist
Hi,
kernel 3.2.0,using the vendor's kernel image.So i dont know the details.Only know,when using accept(), must specify the length of the third parameter,can not be null or 0(Qt source is 0).Otherwise, it also doesnt work.
Source code is here(qnativesocketengine_unix.cpp +561):
int acceptedDescriptor = qt_safe_accept(socketDescriptor, 0, 0);I almost learned every post related to the issue on the forum, and there is no solution.So i think maybe its a bug of kernel or Qt.It may also be that my ability is not good enough to find the point.
Whatever,i have no time to continue it,So the problem is "solved", and waiting for the big one.
Btw,if you have the ability to send questions to the Qt Group, it may help more guys.
:) -
You can ask the question yourself directly, it's not a closed group ;-)
That said, where exactly did you saw that issue with the size in Qt's code ?
Did you check whether more recent versions of Qt are still affected ? -
Hi,
Yes,I modified the Qt's code(qnativesocketengine_unix.cpp +561).
And my code just ran on version 5.3/5.6.Thanks for the reply.
-
In what way did you modify the code ?