From 3093438e1db96dd2075af28b154518f9aadd1c83 Mon Sep 17 00:00:00 2001 From: Mario Sergio Fujikawa Ferreira Date: Sat, 26 May 2007 11:58:32 +0000 Subject: o Improve error handling when processing files o Add OPTIONS SO_KEEPALIVE and TCP_NODELAY o Uphold hier(7) and install ccxstream under sbin/ instead of bin/ o Bump PORTREVISION --- net/ccxstream/Makefile | 40 +++++++++++++-------- net/ccxstream/files/ccxstream.in | 52 +++++++++++++++++++++++++++ net/ccxstream/files/ccxstream.sh.sample | 52 --------------------------- net/ccxstream/files/patch-ccxclientconn.c | 14 ++++++++ net/ccxstream/files/patch-ccxstream.c | 59 +++++++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 67 deletions(-) create mode 100644 net/ccxstream/files/ccxstream.in delete mode 100644 net/ccxstream/files/ccxstream.sh.sample create mode 100644 net/ccxstream/files/patch-ccxclientconn.c create mode 100644 net/ccxstream/files/patch-ccxstream.c (limited to 'net') diff --git a/net/ccxstream/Makefile b/net/ccxstream/Makefile index f89f06d2338a..18352063085c 100644 --- a/net/ccxstream/Makefile +++ b/net/ccxstream/Makefile @@ -7,6 +7,7 @@ PORTNAME= ccxstream PORTVERSION= 1.0.15 +PORTREVISION= 1 CATEGORIES= net MASTER_SITES= ${MASTER_SITE_SOURCEFORGE} MASTER_SITE_SUBDIR= xbplayer @@ -14,28 +15,25 @@ MASTER_SITE_SUBDIR= xbplayer MAINTAINER= ports@FreeBSD.org COMMENT= Stream media files to XBox Media Center via XBMSP -USE_GMAKE= yes +OPTIONS= SO_KEEPALIVE "Build with SO_KEEPALIVE" ON \ + TCP_NODELAY "Build with TCP_NODELAY" OFF -USE_RC_SUBR= yes -RC_SCRIPTS_SUB= PREFIX=${PREFIX} RC_SUBR=${RC_SUBR} -SAMPLERC= ${PORTNAME}.sh.sample -REALRC= ${SAMPLERC:S/.sample//} +USE_GMAKE= yes +MAKE_ENV= CC="${CC}" +USE_RC_SUBR= ccxstream -PLIST_FILES= bin/ccxstream bin/ccxtest etc/rc.d/${REALRC} +PLIST_FILES= \ + bin/ccxtest \ + sbin/ccxstream .if !defined(NOPORTDOCS) PORTDOCS= README ChangeLog TODO xbmsp-xml.txt xbmsp.txt .endif -post-build: - @${SED} ${RC_SCRIPTS_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \ - ${FILESDIR}/${SAMPLERC} > ${WRKDIR}/${SAMPLERC} - do-install: - @${MKDIR} ${PREFIX}/bin - @${INSTALL_PROGRAM} ${WRKSRC}/ccxstream ${PREFIX}/bin + @${MKDIR} ${PREFIX}/sbin + @${INSTALL_PROGRAM} ${WRKSRC}/ccxstream ${PREFIX}/sbin @${INSTALL_PROGRAM} ${WRKSRC}/ccxtest ${PREFIX}/bin - @${INSTALL_SCRIPT} ${WRKDIR}/${SAMPLERC} ${PREFIX}/etc/rc.d/${REALRC} .if !defined(NOPORTDOCS) @${MKDIR} ${DOCSDIR} .for i in ${PORTDOCS} @@ -44,6 +42,18 @@ do-install: .endif post-install: - @${CAT} pkg-message + @${CAT} ${PKGMESSAGE} + +.include + +# enable SO_KEEPALIVE +.if defined(WITH_SO_KEEPALIVE) +CFLAGS+= -DSO_KEEPALIVE +.endif + +# enable TCP_NODELAY +.if defined(WITH_TCP_NODELAY) +CFLAGS+= -DTCP_NODELAY +.endif -.include +.include diff --git a/net/ccxstream/files/ccxstream.in b/net/ccxstream/files/ccxstream.in new file mode 100644 index 000000000000..7b68000d3e3b --- /dev/null +++ b/net/ccxstream/files/ccxstream.in @@ -0,0 +1,52 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: ccxstream +# REQUIRE: DAEMON + +# Define these ccxstream_* variables in one of these files: +# /etc/rc.conf +# /etc/rc.conf.local +# /etc/rc.conf.d/ccxstream +# +# DO NOT CHANGE THESE DEFAULT VALUES HERE! +# +# The port will refuse to start unless ccxstream_flags is initalized, +# in addition to ccxstream_enable. For information on the arguments +# to ccxstream, look at %%PREFIX%%/share/doc/ccxstream/README (if you +# installed the port documentation by not specifying NOPORTDOCS) or the +# output of "ccxstream -h". At bare minimum, you'll want to add the +# "-u " argument to specify the userid the server will run under +# (unless you WANT to run this code as root), and the "-r " +# argument to configure the directory root that the server will share +# from. +# +# Don't worry about the "-f" (background) and "-F " arguments; +# this script takes care of them for you. + +. %%RC_SUBR%% + +name="ccxstream" +rcvar=`set_rcvar` + +command="%%PREFIX%%/sbin/ccxstream" + +load_rc_config "$name" +: ${ccxstream_enable="NO"} +: ${ccxstream_flags="DEFAULT"} + +pidfile=${ccxstream_pidfile="/var/run/${name}.pid"} + +command_args="-f -F ${pidfile}" + +ccxstream_precmd () { + if [ x"${ccxstream_flags}" = xDEFAULT ]; then + warn must set ccxstream_flags first, no acceptable defaults + return 1 + fi + return 0 +} + +run_rc_command "$1" diff --git a/net/ccxstream/files/ccxstream.sh.sample b/net/ccxstream/files/ccxstream.sh.sample deleted file mode 100644 index 0782f1c0e740..000000000000 --- a/net/ccxstream/files/ccxstream.sh.sample +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh -# -# $FreeBSD$ -# - -# PROVIDE: ccxstream -# REQUIRE: DAEMON - -# Define these ccxstream_* variables in one of these files: -# /etc/rc.conf -# /etc/rc.conf.local -# /etc/rc.conf.d/ccxstream -# -# DO NOT CHANGE THESE DEFAULT VALUES HERE! -# -# The port will refuse to start unless ccxstream_flags is initalized, -# in addition to ccxstream_enable. For information on the arguments -# to ccxstream, look at %%PREFIX%%/share/doc/ccxstream/README (if you -# installed the port documentation by not specifying NOPORTDOCS) or the -# output of "ccxstream -h". At bare minimum, you'll want to add the -# "-u " argument to specify the userid the server will run under -# (unless you WANT to run this code as root), and the "-r " -# argument to configure the directory root that the server will share -# from. -# -# Don't worry about the "-f" (background) and "-F " arguments; -# this script takes care of them for you. - -. %%RC_SUBR%% - -name="ccxstream" -rcvar=`set_rcvar` - -command="%%PREFIX%%/bin/ccxstream" - -load_rc_config "$name" -: ${ccxstream_enable="NO"} -: ${ccxstream_flags="DEFAULT"} - -pidfile=${ccxstream_pidfile="/var/run/${name}.pid"} - -command_args="-f -F ${pidfile}" - -ccxstream_precmd () { - if [ x"${ccxstream_flags}" = xDEFAULT ]; then - warn must set ccxstream_flags first, no acceptable defaults - return 1 - fi - return 0 -} - -run_rc_command "$1" diff --git a/net/ccxstream/files/patch-ccxclientconn.c b/net/ccxstream/files/patch-ccxclientconn.c new file mode 100644 index 000000000000..11e1ccb1f423 --- /dev/null +++ b/net/ccxstream/files/patch-ccxclientconn.c @@ -0,0 +1,14 @@ +--- ccxclientconn.c.orig Mon Mar 17 11:29:15 2003 ++++ ccxclientconn.c Tue May 15 14:58:52 2007 +@@ -51,6 +51,11 @@ + i = 1; + setsockopt(sock, IPPROTO_TCP,TCP_NODELAY, &i, sizeof (i)); + #endif /* TCP_NODELAY */ ++ ++#ifdef SO_KEEPALIVE ++ i = 1; ++ setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &i, sizeof (i)); ++#endif /* SO_KEEPALIVE */ + } + + CcXstreamClientError cc_xstream_client_connect(const char *host, diff --git a/net/ccxstream/files/patch-ccxstream.c b/net/ccxstream/files/patch-ccxstream.c new file mode 100644 index 000000000000..4af51400cc14 --- /dev/null +++ b/net/ccxstream/files/patch-ccxstream.c @@ -0,0 +1,59 @@ +--- ccxstream.c.orig Mon Mar 17 11:29:15 2003 ++++ ccxstream.c Tue May 15 15:02:31 2007 +@@ -1004,7 +1004,7 @@ + for (fh = 0; fh < CC_XSTREAM_MAX_OPEN_FILES; fh++) + if (conn->open_file_handle[fh] == handle) + break; +- if (fh >= CC_XSTREAM_MAX_OPEN_FILES) ++ if ( (fh >= CC_XSTREAM_MAX_OPEN_FILES) || (conn->open_file_handle[fh] <= 0) ) + { + cc_xstream_send_error(conn, id, CC_XSTREAM_XBMSP_ERROR_INVALID_HANDLE, "Invalid file handle."); + return 1; +@@ -1016,10 +1016,19 @@ + } + hlp = cc_xmalloc(rlen); + sz = fread(hlp, 1, rlen, conn->f[fh]); ++ if ( (sz < rlen) && ( (ferror(conn->f[fh]) != 0) || (feof(conn->f[fh]) == 0) ) ) ++ { ++ fclose(conn->f[fh]); ++ conn->f[fh] = NULL; ++ cc_xstream_send_error(conn, id, CC_XSTREAM_XBMSP_ERROR_ILLEGAL_SEEK, "File read failed."); ++ } ++ else ++ { + cc_xstream_write_int(conn, 1 + 4 + 4 + sz); + cc_xstream_write_byte(conn, (int)CC_XSTREAM_XBMSP_PACKET_FILE_CONTENTS); + cc_xstream_write_int(conn, id); + cc_xstream_write_data_string(conn, (unsigned char *)hlp, sz); ++ } + cc_xfree(hlp); + return 1; + } +@@ -1661,6 +1670,16 @@ + setsockopt(prog->s, SOL_SOCKET, SO_REUSEPORT, (char *)&c, sizeof (c)); + #endif /* SO_REUSEPORT */ + ++#ifdef TCP_NODELAY ++ c = 1; ++ setsockopt(prog->s, IPPROTO_TCP, TCP_NODELAY, (char *)&c, sizeof (c)); ++#endif /* TCP_NODELAY */ ++ ++#ifdef SO_KEEPALIVE ++ c = 1; ++ setsockopt(prog->s, SOL_SOCKET, SO_KEEPALIVE, (char *)&c, sizeof (c)); ++#endif /* SO_KEEPALIVE */ ++ + memset(&sa, 0, sizeof (sa)); + sa.sin_family = AF_INET; + sa.sin_addr = la; +@@ -1693,6 +1712,10 @@ + c = 1; + setsockopt(prog->bs, SOL_SOCKET, SO_BROADCAST, (char *)&c, sizeof (c)); + #endif /* SO_BROADCAST */ ++#ifdef SO_KEEPALIVE ++ c = 1; ++ setsockopt(prog->bs, SOL_SOCKET, SO_KEEPALIVE, (char *)&c, sizeof (c)); ++#endif /* SO_KEEPALIVE */ + + memset(&sa, 0, sizeof (sa)); + sa.sin_family = AF_INET; -- cgit v1.2.3