[xiph-cvs] cvs commit: icecast/src connection.c source.c util.c util.h
Michael Smith
msmith at xiph.org
Wed Jul 24 07:52:29 PDT 2002
msmith 02/07/24 07:52:29
Modified: src connection.c source.c util.c util.h
Log:
Allow either poll or select to be used (based on whether HAVE_POLL is defined.)
Still need to make autoconf define HAVE_POLL where relevent.
Revision Changes Path
1.12 +1 -9 icecast/src/connection.c
Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- connection.c 2002/07/24 13:55:12 1.11
+++ connection.c 2002/07/24 14:52:28 1.12
@@ -109,18 +109,10 @@
static connection_t *_accept_connection(void)
{
int sock;
- fd_set rfds;
connection_t *con;
- struct timeval tv;
char *ip;
- FD_ZERO(&rfds);
- FD_SET(global.serversock, &rfds);
-
- tv.tv_sec = 0;
- tv.tv_usec = 30000;
-
- if (select(global.serversock + 1, &rfds, NULL, NULL, &tv) <= 0) {
+ if (util_timed_wait_for_fd(global.serversock, 30) <= 0) {
return NULL;
}
<p><p>1.15 +7 -13 icecast/src/source.c
Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- source.c 2002/05/08 14:07:42 1.14
+++ source.c 2002/07/24 14:52:28 1.15
@@ -27,6 +27,7 @@
#include "log.h"
#include "logging.h"
#include "config.h"
+#include "util.h"
#include "source.h"
@@ -117,9 +118,6 @@
refbuf_t *refbuf, *abuf;
int data_done;
- fd_set rfds;
- struct timeval tv;
-
int listeners = 0;
timeout = config_get_config()->source_timeout;
@@ -147,7 +145,7 @@
stats_event(source->mount, "description", s);
while (global.running == ICE_RUNNING) {
- int ret = source->format->get_buffer(source->format, NULL, 0, &refbuf);
+ ret = source->format->get_buffer(source->format, NULL, 0, &refbuf);
if(ret < 0) {
WARN0("Bad data from source");
break;
@@ -155,20 +153,16 @@
while (refbuf == NULL) {
bytes = 0;
while (bytes <= 0) {
- FD_ZERO(&rfds);
- FD_SET(source->con->sock, &rfds);
-
- tv.tv_sec = timeout;
- tv.tv_usec = 0;
-
- ret = select(source->con->sock + 1, &rfds, NULL, NULL, &tv);
- if (ret == 0) { /* timeout expired */
+ ret = util_timed_wait_for_fd(source->con->sock, timeout*1000);
+
+ if (ret <= 0) { /* timeout expired */
bytes = 0;
break;
}
bytes = sock_read_bytes(source->con->sock, buffer, 4096);
- if (bytes == 0 || (bytes < 0 && !sock_recoverable(sock_error()))) break;
+ if (bytes == 0 || (bytes < 0 && !sock_recoverable(sock_error())))
+ break;
}
if (bytes <= 0) break;
ret = source->format->get_buffer(source->format, buffer, bytes, &refbuf);
<p><p>1.4 +37 -8 icecast/src/util.c
Index: util.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/util.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- util.c 2002/02/07 01:04:07 1.3
+++ util.c 2002/07/24 14:52:28 1.4
@@ -4,6 +4,9 @@
#include <sys/time.h>
#include <sys/socket.h>
#include <unistd.h>
+#ifdef HAVE_POLL
+#include <sys/poll.h>
+#endif
#else
#include <winsock2.h>
#include <windows.h>
@@ -14,13 +17,44 @@
#include "config.h"
#include "util.h"
+/* Abstract out an interface to use either poll or select depending on which
+ * is available (poll is preferred) to watch a single fd.
+ *
+ * timeout is in milliseconds.
+ *
+ * returns > 0 if activity on the fd occurs before the timeout.
+ * 0 if no activity occurs
+ * < 0 for error.
+ */
+int util_timed_wait_for_fd(int fd, int timeout)
+{
+#ifdef HAVE_POLL
+ struct pollfd ufds;
+
+ ufds.fd = fd;
+ ufds.events = POLLIN;
+ ufds.revents = 0;
+
+ return poll(&ufds, 1, timeout);
+#else
+ fd_set rfds;
+ struct timeval tv;
+
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+
+ tv.tv_sec = timeout/1000;
+ tv.tv_usec = (timeout - tv.tv_sec)*1000;
+
+ return select(fd+1, &rfds, NULL, NULL, &tv);
+#endif
+}
+
int util_read_header(int sock, char *buff, unsigned long len)
{
- fd_set rfds;
int read_bytes, ret;
unsigned long pos;
char c;
- struct timeval tv;
ice_config_t *config;
config = config_get_config();
@@ -31,14 +65,9 @@
while ((read_bytes == 1) && (pos < (len - 1))) {
read_bytes = 0;
-
- FD_ZERO(&rfds);
- FD_SET(sock, &rfds);
- tv.tv_sec = config->header_timeout;
- tv.tv_usec = 0;
+ if (util_timed_wait_for_fd(sock, config->header_timeout*1000) > 0) {
- if (select(sock + 1, &rfds, NULL, NULL, &tv) > 0) {
if ((read_bytes = recv(sock, &c, 1, 0))) {
if (c != '\r') buff[pos++] = c;
if ((pos > 1) && (buff[pos - 1] == '\n' && buff[pos - 2] == '\n')) {
<p><p>1.2 +1 -0 icecast/src/util.h
Index: util.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/util.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- util.h 2001/09/10 02:21:49 1.1
+++ util.h 2002/07/24 14:52:28 1.2
@@ -1,6 +1,7 @@
#ifndef __UTIL_H__
#define __UTIL_H__
+int util_timed_wait_for_fd(int fd, int timeout);
int util_read_header(int sock, char *buff, unsigned long len);
#endif /* __UTIL_H__ */
<p><p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list