From aabb2027b03611226b5b54e8242802ac35de1c8d Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Wed, 11 Sep 2013 16:38:59 +0200 Subject: [PATCH] Add timeout to raise exception when Modem#wait is stuck --- lib/biju/modem.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/biju/modem.rb b/lib/biju/modem.rb index 7726622..a209cae 100644 --- a/lib/biju/modem.rb +++ b/lib/biju/modem.rb @@ -1,5 +1,6 @@ require 'serialport' require 'forwardable' +require 'timeout' module Biju class Modem @@ -23,8 +24,10 @@ module Biju def wait(length: 0) buffer = '' - while IO.select([connection], [], [], 0.50) || buffer.length < length - buffer << connection.getc.chr + Timeout.timeout(10) do + while IO.select([connection], [], [], 0.50) || buffer.length < length + buffer << connection.getc.chr + end end buffer