gianks

Hi All,

the problem is non existent!

I didn't know i have to read all data on the socket every time the notifier send the signal, to avoid signal emission in every event loop cicle.

Regards

gianks Newbie Poster

Hi all,

i'm writing a Qt SIGNAL/SLOT capable class in order to be able to work with raw socket in a Qt application.

To achieve this, i'm using a QSocketNotifier to monitor socket incoming data event in a S/S way.

Now the problem: entering the event loop, causes the process CPU utilization to raise to 100%, locking every event.and the QSocketNotifier signal activated(int socket) is never triggered. Removing the QSocketNotifier declaration, the loop works normally.

Here i've made a reduced compilable code set to better show the unwanted behavior:
(The program create a ICMP raw socket: to create ICMP traffic, just ping yourself at 127.0.0.1)

NOTE: raw socket requires root privileges: run the test program in root mode.

[CODE]
/*

  • File: main.cpp
  • Author: root
  • Created on 29 agosto 2011, 17.28
    */
include
include
include <sys/socket.h>
include <netinet/in.h>
include
include

int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);

int sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if(sock == -1){
    qDebug("Socket Creation Failure");
    return -10;
}
//ALSO TRYED IN NON BLOCKING MODE; SAME RESULTS
//fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK);

//THESE LINES ALLOW THE PROGRAM TO STOP FOR THE FIRST AVAILABLE ICMP PACKET
//COMMENT THEM IF YOU WISH NOT TO WAIT FOR THE FIRST PCK OUTSIDE EVENT LOOP.
unsigned char buff[1024];
int length = recv(sock, buff, 1024, 0);
qDebug(("Received: " + QString::number(length)).toStdString().c_str());

//THE GUILTY LINE: COMMENT THIS TO SEE A NORMAL CALM EMPTY EVENT LOOP
QSocketNotifier notifier(sock, QSocketNotifier::Read);

return app.exec();

}

[/CODE]

I've monitored ...

gianks

Hi All,

I've solved the magic issue... nothing magic, just my fault ( as expected :D ).

Reading on a tutorial, i was using MSG_OOB flag for send().

That caused the problem: setting the flag just to 0, the programs are now running since 1 hour without any problem!

Sorry guys for my mistake!

Thanks for you support!

Bye

gianks Newbie Poster

Hi All,

i'm here due to an unexplainable winsock problem.

I've wrote a simple TcpSocket class to wrap in an object oriented way, the winsock functions.

For testing purposes i've written two applications too, a client and a server, wich just send/receive 10 bytes in a giant loop.

Now the problem:
On my machine, with Windows Xp SP3, the two programs run normally until cicle 65535 (integer?): at that point, on server side, a WSAECONNABORTED (10053) happens, causing the socket closure, while, on the server a WSAECONNRESET (10054) is returned. :-/

Running on a Windows 7 machines the same couple of applications, the failure happpens at the cicle 16 :-O

According to microsoft and other sources, WSAECONNABORTED is related to network problems and rarely to software issues: now the funny question... how can a network problem happens on a localhost connection?

I've also tried running the app over the two machines (Xp/win7) alternated to sniff with wireshark the network traffic ( Windows doesn't provide a way to capture the loopback ): the client sends a RESET packet to the server without any reason.

I've attached a screenshot of the two CMD line windows.

If you wish i may post the TcpSocket Class too.

Please, help my find out what's happening here!!!
Thanks guys.

Gianluca

REMARK
In the server i'm not missing to bind to the listen address: the Listen function binds to the listening address before calling listen.

This is the server code:
[CODE]

include "stdafx.h"
include "TcpSocket.h"
define listenPort ...

gianks Newbie Poster

Hi all,
i've to make an introduction of what am i doing before start making questions.

The goal of my work is to create an application quite like an IDE, for specific program development ( always in C++ ) and testing.

Since the need of execute these programs under the main IDE process for monitoring and logging purposes, my solution is to compile them as shared library and load them dynamically from the IDE. (Any suggestion about other strategies is welcome!)

The application is to be considered a 24h server, so can't be subject to problems like memory leaks or segmentation faults, neither be respawned by an external process.
As far as i know, segfaults may be handled intercepting the SIGSEGV signal, but this produces an undefined behavior.

So let's go with fun:
Question one: if the segfault is caused by a function in the shared library, loaded and executed in a separate thread, is possible to preserve the integrity of the running main process and handle the event without surprises?

Question two: since the thread share it's memory, how can i prevent memory leaks caused by the libraries after their unload?

I hope I explained well my need.

Thanks for the help!

Regards
Gianks