mirror of
https://github.com/rofafor/vdr-plugin-iptv.git
synced 2023-10-10 13:37:03 +02:00
Refactor usages of select() to common code.
This commit is contained in:
parent
742e059dd3
commit
cf6195bb8a
25
common.c
25
common.c
@ -3,7 +3,7 @@
|
||||
*
|
||||
* See the README file for copyright information and how to reach the author.
|
||||
*
|
||||
* $Id: common.c,v 1.3 2007/10/10 19:41:10 rahrenbe Exp $
|
||||
* $Id: common.c,v 1.4 2007/10/20 20:27:58 ajhseppa Exp $
|
||||
*/
|
||||
|
||||
#include <vdr/i18n.h>
|
||||
@ -39,6 +39,29 @@ const char *id_pid(const u_short Pid)
|
||||
return "---";
|
||||
}
|
||||
|
||||
int selectSingleDesc(int descriptor, const int usecs, const bool selectWrite)
|
||||
{
|
||||
// Wait for data
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = usecs;
|
||||
// Use select
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(descriptor, &fds);
|
||||
int retval = 0;
|
||||
if (selectWrite)
|
||||
retval = select(descriptor + 1, NULL, &fds, NULL, &tv);
|
||||
else
|
||||
retval = select(descriptor + 1, &fds, NULL, NULL, &tv);
|
||||
// Check if error
|
||||
if (retval < 0) {
|
||||
char tmp[64];
|
||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
const section_filter_table_type section_filter_table[SECTION_FILTER_TABLE_SIZE] =
|
||||
{
|
||||
/* description tag pid tid mask */
|
||||
|
3
common.h
3
common.h
@ -3,7 +3,7 @@
|
||||
*
|
||||
* See the README file for copyright information and how to reach the author.
|
||||
*
|
||||
* $Id: common.h,v 1.9 2007/10/10 19:41:10 rahrenbe Exp $
|
||||
* $Id: common.h,v 1.10 2007/10/20 20:27:59 ajhseppa Exp $
|
||||
*/
|
||||
|
||||
#ifndef __IPTV_COMMON_H
|
||||
@ -32,6 +32,7 @@
|
||||
uint16_t ts_pid(const uint8_t *buf);
|
||||
uint8_t payload(const uint8_t *tsp);
|
||||
const char *id_pid(const u_short Pid);
|
||||
int selectSingleDesc(int descriptor, const int usecs, const bool selectWrite);
|
||||
|
||||
struct section_filter_table_type {
|
||||
const char *description;
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* See the README file for copyright information and how to reach the author.
|
||||
*
|
||||
* $Id: protocolext.c,v 1.12 2007/10/20 17:26:46 rahrenbe Exp $
|
||||
* $Id: protocolext.c,v 1.13 2007/10/20 20:27:59 ajhseppa Exp $
|
||||
*/
|
||||
|
||||
#include <sys/wait.h>
|
||||
@ -196,20 +196,10 @@ int cIptvProtocolExt::Read(unsigned char* *BufferAddr)
|
||||
// Set argument point to read buffer
|
||||
*BufferAddr = readBuffer;
|
||||
// Wait for data
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500000;
|
||||
// Use select
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(socketDesc, &rfds);
|
||||
int retval = select(socketDesc + 1, &rfds, NULL, NULL, &tv);
|
||||
int retval = selectSingleDesc(socketDesc, 500000, false);
|
||||
// Check if error
|
||||
if (retval < 0) {
|
||||
char tmp[64];
|
||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
}
|
||||
// Check if data available
|
||||
else if (retval) {
|
||||
// Read data from socket
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* See the README file for copyright information and how to reach the author.
|
||||
*
|
||||
* $Id: protocolhttp.c,v 1.13 2007/10/20 11:36:21 ajhseppa Exp $
|
||||
* $Id: protocolhttp.c,v 1.14 2007/10/20 20:27:59 ajhseppa Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -141,21 +141,10 @@ bool cIptvProtocolHttp::Connect(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select on the socket completion
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
// Use select to check socket writability
|
||||
fd_set wfds;
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(socketDesc, &wfds);
|
||||
int retval = select(socketDesc + 1, NULL, &wfds, NULL, &tv);
|
||||
// Check if error
|
||||
if (retval < 0) {
|
||||
char tmp[64];
|
||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||
return -1;
|
||||
}
|
||||
// Select on the socket completion, check if it is writable
|
||||
int retval = selectSingleDesc(socketDesc, 800000, true);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
||||
// Select has returned. Get socket errors if there are any
|
||||
int socketStatus = 0;
|
||||
@ -229,22 +218,11 @@ bool cIptvProtocolHttp::GetHeaderLine(char* dest, unsigned int destLen,
|
||||
|
||||
while (!newline || !linefeed) {
|
||||
socklen_t addrlen = sizeof(sockAddr);
|
||||
// Set argument point to read buffer
|
||||
// Wait for data
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500000;
|
||||
// Use select
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(socketDesc, &rfds);
|
||||
int retval = select(socketDesc + 1, &rfds, NULL, NULL, &tv);
|
||||
int retval = selectSingleDesc(socketDesc, 500000, false);
|
||||
// Check if error
|
||||
if (retval < 0) {
|
||||
char tmp[64];
|
||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||
if (retval < 0)
|
||||
return false;
|
||||
}
|
||||
// Check if data available
|
||||
else if (retval) {
|
||||
int retval = recvfrom(socketDesc, bufptr, 1, MSG_DONTWAIT,
|
||||
@ -316,20 +294,10 @@ int cIptvProtocolHttp::Read(unsigned char* *BufferAddr)
|
||||
// Set argument point to read buffer
|
||||
*BufferAddr = readBuffer;
|
||||
// Wait for data
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500000;
|
||||
// Use select
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(socketDesc, &rfds);
|
||||
int retval = select(socketDesc + 1, &rfds, NULL, NULL, &tv);
|
||||
int retval = selectSingleDesc(socketDesc, 500000, false);
|
||||
// Check if error
|
||||
if (retval < 0) {
|
||||
char tmp[64];
|
||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
}
|
||||
// Check if data available
|
||||
else if (retval) {
|
||||
// Read data from socket
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* See the README file for copyright information and how to reach the author.
|
||||
*
|
||||
* $Id: protocoludp.c,v 1.14 2007/10/20 11:36:21 ajhseppa Exp $
|
||||
* $Id: protocoludp.c,v 1.15 2007/10/20 20:27:59 ajhseppa Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -164,20 +164,10 @@ int cIptvProtocolUdp::Read(unsigned char* *BufferAddr)
|
||||
// Set argument point to read buffer
|
||||
*BufferAddr = readBuffer;
|
||||
// Wait for data
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500000;
|
||||
// Use select
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(socketDesc, &rfds);
|
||||
int retval = select(socketDesc + 1, &rfds, NULL, NULL, &tv);
|
||||
int retval = selectSingleDesc(socketDesc, 500000, false);
|
||||
// Check if error
|
||||
if (retval < 0) {
|
||||
char tmp[64];
|
||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
}
|
||||
// Check if data available
|
||||
else if (retval) {
|
||||
int len = 0;
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* See the README file for copyright information and how to reach the author.
|
||||
*
|
||||
* $Id: sectionfilter.c,v 1.11 2007/10/08 16:24:48 rahrenbe Exp $
|
||||
* $Id: sectionfilter.c,v 1.12 2007/10/20 20:27:59 ajhseppa Exp $
|
||||
*/
|
||||
|
||||
#include "sectionfilter.h"
|
||||
@ -97,21 +97,10 @@ int cIptvSectionFilter::dmxdev_section_callback(const uint8_t *buffer1, size_t b
|
||||
const uint8_t *buffer2, size_t buffer2_len,
|
||||
enum dmx_success success)
|
||||
{
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(fifoDescriptor, &rfds);
|
||||
int retval = select(fifoDescriptor + 1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
// Check if error
|
||||
if (retval < 0) {
|
||||
char tmp[64];
|
||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||
}
|
||||
// See if there is data in the fifo
|
||||
int retval = selectSingleDesc(fifoDescriptor, 0, false);
|
||||
// There is no data in the fifo, more can be written
|
||||
else if (!retval) {
|
||||
if (!retval) {
|
||||
#ifdef DEBUG_PRINTF
|
||||
printf("id = %d, pid %d would now write %d data to buffer\n", id, pid, buffer1_len);
|
||||
for (unsigned int i = 0; i < buffer1_len; ++i)
|
||||
|
Loading…
Reference in New Issue
Block a user