Hi,
My name is Daniel and I'm spanish, so I'm sorry if you can't undertand something becouse of my low-level english.
Something stranger is happening to me with socket++ library and I don't know how to work on it.
I has a library called commands.so and the sslclient is and object of that library. sslclient creates an iosockinet object. Just when it creates that object, the program exits with a Segmentation fault error.
I compiled socket++ and my program with debug flag and all I see (and all gdb tells me) is that program recives a SIGSERV when it calls iosockinet constructor.
If I do the same on a separated file (main.cpp) that sslclient does, it works. But the most heavy is that my program runs under valgrind. I'm not an expert valgrind user so I don't know if it's normal (I don't think so).
I'm paranoid about the cause... I think it could happend becouse of the command.so library. If it heps, the iosockinet is created after sslclient object is created.
I'm working under gentoo and I tried the same come in 2 completly different gentoo with the same result, so I figure it's my fault. Once compute information is:
Linux servidor-dissmar 2.6.28-gentoo-r5 #1 SMP Tue Jul 21 12:01:33 CEST 2009 i686 Intel(R) Xeon(R) CPU E5310 @ 1.60GHz GenuineIntel GNU/Linux
g++ (GCC) 4.1.2 (Gentoo 4.1.2 p1.0.2)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gdb output:
Breakpoint 1, sslclient::execute (this=0x805ec90) at network/sslclient.cpp:68
68 iosockinet sock;
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
0xb7bca40e in ?? () from /lib/libc.so.6
valgrid output (just the point before and after, without any errors):
Proceed command execution...
connect...
sslclient.cpp:
#include <iostream>
#include "sslclient.h"
using namespace std;
//sockbuf *sslclient::sock;
extern "C" command *r_done() {
cout << "No message concordances... null command will be returned." << endl;
return NULL;
}
extern "C" command *sslclient() {
/*cout << "On extern method from sslclient.cpp. Setting observers. Wrong point which would do invoker subtype (like player_control or, in this case, network_control)." << endl;
sslclient::sslclient client = new sslclient::sslclient;
observer o;
client->add_observer(o);
return client;/
cout << "Creating sslclient command..." << endl;
return new sslclient::sslclient;
}
sslclient::sslclient() {
/if (sock == NULL) {
int s = socket(AF_INET, SOCK_STREAM,0);
cout << "created socket: " << s << endl;
sock = new sockbuf(s);
//sock = new sockbuf((const sockbuf::sockdesc)sockbuf::sockdesc(socket(AF_INET, SOCK_STREAM,0)));
sockbuf::sockdesc sd(fd);
sock = new sockbuf(sd);
}/
// sockbuf::sockdesc sd(socket(AF_INET, SOCK_STREAM,0));
// sock = new sockbuf(sd);
}
void sslclient::send_data(iosockinet *sock) {
cout << "send(): sending command content " << command << endl;
while(sock->write(command, strlen(command)) == 0)
cout << "Communication problem... retrying to send command \"" << command << "\"." << endl;
cout << "send(): data sent." << endl;
}
int sslclient::recive_data(iosockinet *sock) {
cout << "recv(): reciveing data content." << endl;
if (data != NULL)
delete [] data;
data = new char[10000];
//int len = sock.read(data, 10000);
int len;sock->read(data, 10000);
if (data != NULL && strcmp(data, "") != 0) {
char *buff = new char[len+2];
strcpy(buff,"r_");
strcpy((char *)buff+2, data);
//delete [] data; //Si el matem peta... pero qui el peta?
data = buff;
buff = NULL;
new_data = true;
cout << "recv(): stored data content " << data << endl;
}
}
void sslclient::execute() {
iosockinet sock; //here <--------------------------------------------------------------------------------
cout << "connect..." << endl;
sock->connect("dissmar.es",4444);
while (sock->is_writeready(-1,0) == 0)
cout << "Internet connection lost or server not respondig. Check hardware and software connections and if problem persists call your admin." << endl;
cout << "Connection stabilished." << endl;
cout << "Starting data transmission..." << endl;
send_data(&sock);
recive_data(&sock);
cout << "Data transmission finished..." << endl;
cout << "disconnect..." << endl;
if \(new_data\) \{
cout << "Notifying command observers..." << endl;
notify_observers\(\);
new_data = false;
\}
}
sslclient::~sslclient() {
// delete sock;
}
Thank you in advance,
Daniel.
Edit: code add, sorry. Includes are in sslclient.h.