1
0
Fork 0

- reduce timeout

- stop trying to connect after first failed attempt
This commit is contained in:
mfranz 2006-03-31 10:12:00 +00:00
parent 0abca6be34
commit c5c5411d07
2 changed files with 15 additions and 20 deletions

View file

@ -63,8 +63,12 @@ void FGVoiceMgr::init()
SGPropertyNode *base = fgGetNode(VOICE, true); SGPropertyNode *base = fgGetNode(VOICE, true);
vector<SGPropertyNode_ptr> voices = base->getChildren("voice"); vector<SGPropertyNode_ptr> voices = base->getChildren("voice");
for (unsigned int i = 0; i < voices.size(); i++) try {
_voices.push_back(new FGVoice(this, voices[i])); for (unsigned int i = 0; i < voices.size(); i++)
_voices.push_back(new FGVoice(this, voices[i]));
} catch (const string& s) {
SG_LOG(SG_IO, SG_ALERT, "VOICE: " << s);
}
#if defined(ENABLE_THREADS) #if defined(ENABLE_THREADS)
_thread->start(1); _thread->start(1);
@ -105,28 +109,20 @@ FGVoiceMgr::FGVoice::FGVoice(FGVoiceMgr *mgr, const SGPropertyNode_ptr node) :
const string &port = _mgr->_port; const string &port = _mgr->_port;
_sock = new SGSocket(host, port, "tcp"); _sock = new SGSocket(host, port, "tcp");
_sock->set_timeout(10000); _sock->set_timeout(6000);
_connected = _sock->open(SG_IO_OUT); if (!_sock->open(SG_IO_OUT))
if (!_connected) { throw string("no connection to `") + host + ':' + port + '\'';
SG_LOG(SG_IO, SG_ALERT, "VOICE: no connection to `"
<< host << ':' << port << '\'');
return;
}
if (_festival) { if (_festival) {
_sock->writestring("(SayText \"\")\015\012"); _sock->writestring("(SayText \"\")\015\012");
char buf[4]; char buf[4];
int len = _sock->read(buf, 3); int len = _sock->read(buf, 3);
if (len != 3 || buf[0] != 'L' || buf[1] != 'P') { if (len != 3 || buf[0] != 'L' || buf[1] != 'P')
SG_LOG(SG_IO, SG_ALERT, "VOICE: unexpected or no response from `" throw string("unexpected or no response from `") + host + ':' + port
<< host << ':' << port << "'. Either it's not " << endl + "'. Either it's not\n Festival listening,"
<< " Festival listening, or Festival couldn't open a " " or Festival couldn't open a sound device.";
"sound device.");
_connected = false;
return;
}
SG_LOG(SG_IO, SG_BULK, "VOICE: connection to Festival server on `" SG_LOG(SG_IO, SG_INFO, "VOICE: connection to Festival server on `"
<< host << ':' << port << "' established"); << host << ':' << port << "' established");
setVolume(_volume = _volumeNode->getDoubleValue()); setVolume(_volume = _volumeNode->getDoubleValue());
@ -175,7 +171,7 @@ bool FGVoiceMgr::FGVoice::speak(void)
void FGVoiceMgr::FGVoice::update(void) void FGVoiceMgr::FGVoice::update(void)
{ {
if (_connected && _festival) { if (_festival) {
double d; double d;
d = _volumeNode->getDoubleValue(); d = _volumeNode->getDoubleValue();
if (d != _volume) if (d != _volume)

View file

@ -104,7 +104,6 @@ public:
private: private:
class FGVoiceListener; class FGVoiceListener;
SGSocket *_sock; SGSocket *_sock;
bool _connected;
double _volume; double _volume;
double _pitch; double _pitch;
double _speed; double _speed;