fixed control port reading

This commit is contained in:
csoler 2021-12-10 18:01:21 +01:00
parent 1571446a2e
commit 1c576411fb
2 changed files with 14 additions and 1 deletions

View file

@ -413,12 +413,14 @@ std::string TorProcess::controlPortFilePath() const
bool TorProcess::tryReadControlPort()
{
FILE *file = RsDirUtil::rs_fopen(controlPortFilePath().c_str(),"r");
std::cerr << "Trying to read control port" << std::endl;
if(file)
{
char *line = nullptr;
size_t tmp_buffsize = 0;
size_t size = getline(&line,0,file);
size_t size = getline(&line,&tmp_buffsize,file);
ByteArray data = ByteArray((unsigned char*)line,size).trimmed();
free(line);
@ -428,7 +430,10 @@ bool TorProcess::tryReadControlPort()
mControlPort = data.mid(p+1).toInt();
if (!mControlHost.empty() && mControlPort > 0)
{
std::cerr << "Read control port = " << mControlPort << std::endl;
return true;
}
}
}
return false;