Frank Mehnert wrote:
On Wednesday 16 March 2005 14:41, Tiago Jorge wrote:
01d00244 add $0xc,%esp 01d00247 push $0x0 01d00249 push $0x2 01d0024b push $0x2 01d0024d call 0x1d01300 <socket> 01d00252 add $0x10,%esp 01d00255 test %eax,%eax 01d00257 mov %eax,(%ebx) <--- ERROR HERE!!!!!! 01d00259 js 0x1d00344 /home/tiago/l4/pkg/failuredetector/server/src/FailureDetector.cc:38
That means that the return value of the socket() call is stored somewhere (in sock_fd). What ist sock_fd -- an object variable, a local variable or a global variable?
thats true. sock_fd is an object variable. the definition of the class is the following:
Where is the related object initialized? Add a printf()-statement to the constructor of FailureDetector and see if the output of that statement occurs _before_ the error.
Frank
ok... i've added some debug and you are right. the error is on the call of the socket function. the constructor is right. here is the code of the constructor:
FailureDetector::FailureDetector(int new_eid, int new_sleep_time, vector<int> *new_group, //pthread_mutex_t *new_group_lock){
l4lock_t *new_group_lock){ eid = new_eid; sleep_time = new_sleep_time; group = new_group; group_lock = new_group_lock; trueFlag_fd = 0x1; stop_flag = false; sock_fd=0;
LOG("Before start thread\n"); fdect = l4thread_create(helper_failure_detector, NULL, L4THREAD_CREATE_ASYNC); LOG("After start thread\n"); }
it passes ok...
then he executes this code:
void FailureDetector::failureDetector(){ heartbeat hb; bool recvfrom_error = false; map<int,heartbeat> received; map<int,heartbeat> pre_suspicious;
/*initialization procedures*/ //pthread_mutex_init(&lock_suspected, NULL); //pthread_mutex_init(&lock_stop, NULL); LOG("before initialize_comm_fd()\n"); initialize_comm_fd();
[...]
and the initialize_comm_fd bugs out. here is the code:
void FailureDetector::initialize_comm_fd(){ int flags=0, s=0;
LOG("before socket\n"); /* Create socket from which to send */ if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { <--- ERROR!!!!! LOG("socket error\n"); } LOG("after socket\n"); [...]
you can see there the s variable. if i use s, it works out fine because its a local variable, but breaks in the next line. sock_fd and the variable in the next line are private attributes of the class, as you can see here:
[...]
extern "C"{ #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <fcntl.h> #include <netdb.h> #include <l4/lock/lock.h> #include <l4/names/libnames.h> #include <l4/log/l4log.h> }
#define PORTNUMBER 45555
#define NULL 0
using namespace std;
struct heartbeat{ int eid; };
class FailureDetector{
private: int sock_fd; <--- here it is... socklen_t addrLength_fd; struct sockaddr_in destinationAddr_fd; struct sockaddr_in myAddr_fd; struct sockaddr_in responseAddr_fd; int trueFlag_fd; map<int,heartbeat> suspected; [...]
so... whats wrong :) ???
thanks
Tiago