PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lirc_util.c

http://bdremote-ng.googlecode.com/
C | 116 lines | 64 code | 21 blank | 31 comment | 3 complexity | 4e7f552abd9278908917ff8037cf4552 MD5 | raw file
  1/*
  2 *  bdremoteng - helper daemon for Sony(R) BD Remote Control
  3 *  Based on bdremoted, written by Anton Starikov <antst@mail.ru>.
  4 *
  5 *  Copyright (C) 2009  Michael Wojciechowski <wojci@wojci.dk>
  6 *
  7 *
  8 *  This program is free software; you can redistribute it and/or modify
  9 *  it under the terms of the GNU General Public License as published by
 10 *  the Free Software Foundation; either version 2 of the License, or
 11 *  (at your option) any later version.
 12 *
 13 *  This program is distributed in the hope that it will be useful,
 14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 *  GNU General Public License for more details.
 17 *
 18 *  You should have received a copy of the GNU General Public License
 19 *  along with this program; if not, write to the Free Software
 20 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 21 *
 22 */
 23
 24/** \ingroup LIRC */
 25/*@{*/
 26
 27/*! \file lirc_util.c
 28  \brief LIRC, utility functions.
 29
 30  Implements a few utility functions used by the LIRC server.
 31
 32*/
 33
 34#include "lirc_srv.h"
 35
 36#include <globaldefs.h>
 37
 38#define _GNU_SOURCE
 39#include <stdio.h>
 40#include <errno.h>
 41#include <fcntl.h>
 42#include <unistd.h>
 43#include <stdlib.h>
 44#include <string.h>
 45#include <syslog.h>
 46#include <signal.h>
 47#include <getopt.h>
 48#include <sys/poll.h>
 49#include <sys/ioctl.h>
 50#include <sys/socket.h>
 51#include <poll.h>
 52#include <netinet/in.h>
 53#include <assert.h>
 54
 55void initTime(keyState* _ks)
 56{
 57  _ks->cl0.tv_sec  = 0;
 58  _ks->cl0.tv_usec = 0;
 59  _ks->cl1.tv_sec  = 0;
 60  _ks->cl1.tv_usec = 0;
 61
 62  gettimeofday(&_ks->cl0, NULL);
 63  _ks->cl1     = _ks->cl0;
 64  _ks->elapsed = 0;
 65}
 66
 67void updateTime(keyState* _ks)
 68{
 69  time_t usec    = 0;
 70  time_t elapsed = 0;
 71
 72  gettimeofday(&_ks->cl1, NULL);
 73
 74  assert(_ks->cl1.tv_sec >= _ks->cl0.tv_sec);
 75
 76  usec = _ks->cl1.tv_usec - _ks->cl0.tv_usec;
 77
 78  if (usec > 0)
 79    {
 80      elapsed += (usec / 1000);
 81    }
 82
 83  _ks->elapsed += elapsed;
 84
 85  _ks->cl0 = _ks->cl1;
 86}
 87
 88int write_socket(int _fd, const char* _buf, int _len)
 89{
 90  int done = 0;
 91  int todo = _len;
 92
 93  while (todo)
 94    {
 95      done = write(_fd, _buf, todo);
 96
 97      if (done<=0)
 98        {
 99          return done;
100        }
101      _buf  += done;
102      todo  -= done;
103    }
104
105  return _len;
106}
107
108void nolinger(int _sock)
109{
110  static struct linger  linger = {0, 0};
111  int lsize  = sizeof(struct linger);
112  setsockopt(_sock, SOL_SOCKET, SO_LINGER, (void *)&linger, lsize);
113}
114
115/*@}*/
116