Re: Seg fault reading data from IOChannel




Sorry,

char data; is actually char ID;

I added char data; by hand after copy-pasting the code snippet in the mail. Application code is correct.



Víctor M. Palacio Tárrega escribió:
You are absolutely right. buff remains from another workaround and should be eliminated.

About data, should be defined as char foo[<data_lenght>]; where I use only 1 or 4 as data_lenght.
Below are included the calls to read_data() function I'm using.

I'm doing something nasty with data conversion, or is just fine for you?

Thanks a lot,

Code:
   int value;
   char data;
   //.........................................
   ioc_unix.read_data(&ID,1);
   std::cout<<"command received: " << (int)ID << std::endl;
   //Get value
   switch(ID)
   {
   case 0: //speed
//..........................
   break;
   case 1: //RPM
       if(ioc_unix.read_data((char*)value,4) !=-1){
//......................................

klaus triendl escribió:
Víctor M. Palacio Tárrega schrieb:
Code:
int NetworkCommandManager::read_data(char* data, int len)
{
   if (len>256){
       std::cerr << "Cannot read more than 256 bytes" << std::endl;
       return -1;
   }
   gsize n;
   char buff[256];
   std::cout<< "to read "<< len << " bytes" << std::endl;

   n = ::read(read_fd,data,len);           //workaround

   //ioc_net->read(data,(gsize)len,n); //seg faulting call

   std::cout<< "readed "<< n << " bytes" << std::endl;
   if (n == len)
       return 0;
   else
       return -1;  }

You reserve a static buffer 'buff' that you never use. Instead, you pass
'data' to the read() function. How big is 'data' passed to read_data()?

Klaus






--

//*Víctor M. Palacio Tárrega*//



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]