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

@ -30,6 +30,9 @@ RsFdBinInterface::RsFdBinInterface(int file_descriptor)
mTotalInBufferBytes=0;
mTotalWrittenBytes=0;
mTotalOutBufferBytes=0;
if(file_descriptor!=0)
setSocket(file_descriptor);
}
void RsFdBinInterface::setSocket(int s)
@ -39,6 +42,11 @@ void RsFdBinInterface::setSocket(int s)
RsErr() << "Changing socket to active FsBioInterface! Canceling all pending R/W data." ;
close();
}
int flags = fcntl(s,F_GETFL);
if(!(flags & O_NONBLOCK))
throw std::runtime_error("Trying to use a blocking file descriptor in RsFdBinInterface. This is not going to work!");
mCLintConnt = s;
mIsActive = (s!=0);
}

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;