pkgsrc/multimedia/minidlna/patches/patch-upnphttp
drochner 3c84e9b1aa import the FreeBSD port of minidlna, with minor adaptions to make it
build and start up on NetBSD
not tested with a real media renderer yet
2012-10-15 22:48:01 +00:00

105 lines
2.7 KiB
Text

$NetBSD: patch-upnphttp,v 1.1 2012/10/15 22:48:02 drochner Exp $
--- upnphttp.c.orig 2012-06-30 00:31:43.000000000 +0000
+++ upnphttp.c
@@ -58,7 +58,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
-#include <sys/sendfile.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/resource.h>
@@ -80,12 +79,18 @@
#include "tivo_utils.h"
#include "tivo_commands.h"
#endif
+#if defined(__linux__) || defined(__NetBSD__)
//#define MAX_BUFFER_SIZE 4194304 // 4MB -- Too much?
#define MAX_BUFFER_SIZE 2147483647 // 2GB -- Too much?
#define MIN_BUFFER_SIZE 65536
+#endif
#include "icons.c"
+#ifndef MSG_MORE /* A Linux-only flag for send(2) */
+# define MSG_MORE 0
+#endif
+
enum event_type {
E_INVALID,
E_SUBSCRIBE,
@@ -1283,7 +1288,7 @@ SendResp_upnphttp(struct upnphttp * h)
}
}
-int
+static int
send_data(struct upnphttp * h, char * header, size_t size, int flags)
{
int n;
@@ -1306,9 +1311,10 @@ send_data(struct upnphttp * h, char * he
return 1;
}
-void
+static void
send_file(struct upnphttp * h, int sendfd, off_t offset, off_t end_offset)
{
+#if defined(__linux__) || defined(__NetBSD__)
off_t send_size;
off_t ret;
char *buf = NULL;
@@ -1316,6 +1322,7 @@ send_file(struct upnphttp * h, int sendf
while( offset < end_offset )
{
+#if defined(__linux__)
if( try_sendfile )
{
send_size = ( ((end_offset - offset) < MAX_BUFFER_SIZE) ? (end_offset - offset + 1) : MAX_BUFFER_SIZE);
@@ -1335,6 +1342,7 @@ send_file(struct upnphttp * h, int sendf
continue;
}
}
+#endif
/* Fall back to regular I/O */
if( !buf )
buf = malloc(MIN_BUFFER_SIZE);
@@ -1356,6 +1364,27 @@ send_file(struct upnphttp * h, int sendf
}
free(buf);
}
+#elif defined(__FreeBSD__) || \
+ defined(__OpenBSD__) || defined(__DragonFlyBSD__)
+{
+
+ off_t sent;
+
+ while (offset < end_offset)
+ {
+ if (sendfile(sendfd, h->socket, offset,
+ end_offset - offset + 1, NULL, &sent, SF_MNOWAIT) == -1) {
+ DPRINTF(E_ERROR, L_HTTP,
+ "sendfile error :: error no. %d [%s]\n",
+ errno, strerror(errno));
+ if (errno != EAGAIN)
+ break;
+ }
+ offset += sent;
+
+ }
+}
+#endif
void
SendResp_icon(struct upnphttp * h, char * icon)
@@ -1853,7 +1882,7 @@ SendResp_dlnafile(struct upnphttp * h, c
char path[PATH_MAX];
char mime[32];
char dlna[96];
- } last_file = { 0, 0 };
+ } last_file = { 0, 0, { '\0' }, { '\0' }, { '\0' } };
#if USE_FORK
pid_t newpid = 0;
#endif