Re: Seg fault reading data from IOChannel



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


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