diff --git a/src/libYARP_OS/include/yarp/os/impl/NameserCarrier.h b/src/libYARP_OS/include/yarp/os/impl/NameserCarrier.h index 9775a7b538f..62a7933e3b5 100644 --- a/src/libYARP_OS/include/yarp/os/impl/NameserCarrier.h +++ b/src/libYARP_OS/include/yarp/os/impl/NameserCarrier.h @@ -47,6 +47,8 @@ class yarp::os::impl::NameserTwoWayStream : public TwoWayStream, InputStream virtual void beginPacket() override; virtual void endPacket() override; + virtual bool setReadTimeout(double timeout) override; + using yarp::os::InputStream::read; virtual YARP_SSIZE_T read(const yarp::os::Bytes& b) override; }; diff --git a/src/libYARP_OS/src/NameserCarrier.cpp b/src/libYARP_OS/src/NameserCarrier.cpp index abcb0aac3d0..d229df22665 100644 --- a/src/libYARP_OS/src/NameserCarrier.cpp +++ b/src/libYARP_OS/src/NameserCarrier.cpp @@ -64,6 +64,11 @@ void yarp::os::impl::NameserTwoWayStream::endPacket() { delegate->endPacket(); } +bool yarp::os::impl::NameserTwoWayStream::setReadTimeout(double timeout) +{ + return delegate->getInputStream().setReadTimeout(timeout); +} + YARP_SSIZE_T yarp::os::impl::NameserTwoWayStream::read(const Bytes& b) { // assume it is ok for name_ser to go byte-by-byte // since this protocol will be phased out diff --git a/src/libYARP_OS/src/StreamConnectionReader.cpp b/src/libYARP_OS/src/StreamConnectionReader.cpp index 3e3b2e7a11e..8231169b77c 100644 --- a/src/libYARP_OS/src/StreamConnectionReader.cpp +++ b/src/libYARP_OS/src/StreamConnectionReader.cpp @@ -247,7 +247,9 @@ yarp::os::ConstString StreamConnectionReader::expectText(int terminatingChar) } yAssert(in!=nullptr); bool lsuccess = false; + in->setReadTimeout(2.0); ConstString result = in->readLine(terminatingChar, &lsuccess); + in->setReadTimeout(0.0); if (lsuccess) { messageLen -= result.length()+1; }