mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-04 11:06:47 -04:00
fixed control port reading
This commit is contained in:
parent
1571446a2e
commit
1c576411fb
2 changed files with 14 additions and 1 deletions
|
@ -30,6 +30,9 @@ RsFdBinInterface::RsFdBinInterface(int file_descriptor)
|
||||||
mTotalInBufferBytes=0;
|
mTotalInBufferBytes=0;
|
||||||
mTotalWrittenBytes=0;
|
mTotalWrittenBytes=0;
|
||||||
mTotalOutBufferBytes=0;
|
mTotalOutBufferBytes=0;
|
||||||
|
|
||||||
|
if(file_descriptor!=0)
|
||||||
|
setSocket(file_descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsFdBinInterface::setSocket(int s)
|
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." ;
|
RsErr() << "Changing socket to active FsBioInterface! Canceling all pending R/W data." ;
|
||||||
close();
|
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;
|
mCLintConnt = s;
|
||||||
mIsActive = (s!=0);
|
mIsActive = (s!=0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,12 +413,14 @@ std::string TorProcess::controlPortFilePath() const
|
||||||
bool TorProcess::tryReadControlPort()
|
bool TorProcess::tryReadControlPort()
|
||||||
{
|
{
|
||||||
FILE *file = RsDirUtil::rs_fopen(controlPortFilePath().c_str(),"r");
|
FILE *file = RsDirUtil::rs_fopen(controlPortFilePath().c_str(),"r");
|
||||||
|
std::cerr << "Trying to read control port" << std::endl;
|
||||||
|
|
||||||
if(file)
|
if(file)
|
||||||
{
|
{
|
||||||
char *line = nullptr;
|
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();
|
ByteArray data = ByteArray((unsigned char*)line,size).trimmed();
|
||||||
free(line);
|
free(line);
|
||||||
|
|
||||||
|
@ -428,9 +430,12 @@ bool TorProcess::tryReadControlPort()
|
||||||
mControlPort = data.mid(p+1).toInt();
|
mControlPort = data.mid(p+1).toInt();
|
||||||
|
|
||||||
if (!mControlHost.empty() && mControlPort > 0)
|
if (!mControlHost.empty() && mControlPort > 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Read control port = " << mControlPort << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef TO_REMOVE
|
#ifdef TO_REMOVE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue