summaryrefslogtreecommitdiff
path: root/lirc.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2006-01-27 16:03:32 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2006-01-27 16:03:32 +0100
commitb0678c91abfe06f97c789b06f91a25a7bc29dd23 (patch)
tree973946c0fdfee875305e8b7fd1fc5e04806bcbc3 /lirc.c
parent7398125f317987197b653638517f98f877511513 (diff)
downloadvdr-b0678c91abfe06f97c789b06f91a25a7bc29dd23.tar.gz
vdr-b0678c91abfe06f97c789b06f91a25a7bc29dd23.tar.bz2
Now trying to reestablish the connection to the LIRC daemon in case it breaks
Diffstat (limited to 'lirc.c')
-rw-r--r--lirc.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/lirc.c b/lirc.c
index ac9de010..9bb83287 100644
--- a/lirc.c
+++ b/lirc.c
@@ -6,35 +6,28 @@
*
* LIRC support added by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16.
*
- * $Id: lirc.c 1.13 2005/09/02 12:51:35 kls Exp $
+ * $Id: lirc.c 1.14 2006/01/27 15:59:47 kls Exp $
*/
#include "lirc.h"
#include <netinet/in.h>
#include <sys/socket.h>
-#include <sys/un.h>
#define REPEATLIMIT 20 // ms
#define REPEATDELAY 350 // ms
#define KEYPRESSDELAY 150 // ms
+#define RECONNECTDELAY 3000 // ms
cLircRemote::cLircRemote(const char *DeviceName)
:cRemote("LIRC")
,cThread("LIRC remote control")
{
- struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, DeviceName);
- if ((f = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) {
- if (connect(f, (struct sockaddr *)&addr, sizeof(addr)) >= 0) {
- Start();
- return;
- }
- LOG_ERROR_STR(DeviceName);
- close(f);
+ if (Connect()) {
+ Start();
+ return;
}
- else
- LOG_ERROR_STR(DeviceName);
f = -1;
}
@@ -47,6 +40,20 @@ cLircRemote::~cLircRemote()
close(fh);
}
+bool cLircRemote::Connect(void)
+{
+ if ((f = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) {
+ if (connect(f, (struct sockaddr *)&addr, sizeof(addr)) >= 0)
+ return true;
+ LOG_ERROR_STR(addr.sun_path);
+ close(f);
+ f = -1;
+ }
+ else
+ LOG_ERROR_STR(addr.sun_path);
+ return false;
+}
+
bool cLircRemote::Ready(void)
{
return f >= 0;
@@ -67,10 +74,16 @@ void cLircRemote::Action(void)
int ret = ready ? safe_read(f, buf, sizeof(buf)) : -1;
if (ready && ret <= 0 ) {
- esyslog("ERROR: lircd connection lost");
+ esyslog("ERROR: lircd connection broken, trying to reconnect every %.1f seconds", float(RECONNECTDELAY) / 1000);
close(f);
f = -1;
- break;
+ while (Running() && f < 0) {
+ cCondWait::SleepMs(RECONNECTDELAY);
+ if (Connect()) {
+ isyslog("reconnected to lircd");
+ break;
+ }
+ }
}
if (ready && ret > 21) {