source: roaraudio/libroar/vio_ops.c @ 5223:3326fb359ffe

Last change on this file since 5223:3326fb359ffe was 5223:3326fb359ffe, checked in by phi, 12 years ago

Removed roar_file_send_raw() and roarcatsendfile.

File size: 3.4 KB
RevLine 
[1276]1//vio_ops.c:
2
3/*
[4708]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
[1276]5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[1276]23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
[1277]38#define ROAR_VIO_COPY_BUFSIZE 1024
39
[5223]40#define BUFMAX     65536
41
42#ifdef ROAR_HAVE_IO_POSIX
43#define _CAN_OPERATE
44#endif
45
46#ifdef _CAN_OPERATE
47static inline ssize_t _send_file_raw (int out, int in) {
48 ssize_t r = 0;
49#ifdef ROAR_HAVE_LINUX_SENDFILE
50 ssize_t ret;
51#endif
52#if defined(__linux__) && defined(ROAR_HAVE_IPV4)
53 int cork_new = 1, cork_old;
54 socklen_t cork_len = sizeof(int);
55
56 if ( getsockopt(out, IPPROTO_TCP, TCP_CORK, &cork_old, &cork_len) == -1 ) {
57  cork_old = -1;
58 } else {
59  setsockopt(out, IPPROTO_TCP, TCP_CORK, &cork_new, sizeof(int));
60 }
61#endif
62
63 roar_debug_warn_obsolete("roar_file_send_raw", "roar_vio_copy_data", NULL);
64
65#ifdef ROAR_HAVE_LINUX_SENDFILE
66 while ((ret = sendfile(out, in, NULL, BUFMAX)) > 0)
67  r += ret;
68#endif
69
70 // TODO: try mmap here!
71
72#if defined(__linux__) && defined(ROAR_HAVE_IPV4)
73 if ( cork_old != -1 )
74  setsockopt(out, IPPROTO_TCP, TCP_CORK, &cork_old, cork_len);
75#endif
76 return r;
77}
78#endif
79
80
[1277]81ssize_t roar_vio_copy_data   (struct roar_vio_calls * out, struct roar_vio_calls * in) {
82 char    buf[ROAR_VIO_COPY_BUFSIZE];
83 ssize_t len;
84 ssize_t done = 0;
[5223]85#ifdef _CAN_OPERATE
86 int in_fh, out_fh;
87#endif
[1277]88
[2643]89 ROAR_DBG("roar_vio_copy_data(out=%p, in=%p) = ?", out, in);
90
[4876]91 if ( out == NULL || in == NULL ) {
92  roar_err_set(ROAR_ERROR_FAULT);
[1277]93  return -1;
[4876]94 }
95
[5223]96#ifdef _CAN_OPERATE
97 if ( roar_vio_ctl(in, ROAR_VIO_CTL_GET_READ_FH, &in_fh) == 0 )
98  if ( roar_vio_ctl(out, ROAR_VIO_CTL_GET_WRITE_FH, &out_fh) == 0 )
99   _send_file_raw(out_fh, in_fh);
100#endif
101
[4876]102 roar_err_clear_all();
[1277]103
104 while ((len = roar_vio_read(in, buf, ROAR_VIO_COPY_BUFSIZE)) > 0) {
105  if ( roar_vio_write(out, buf, len) != len )
106   return -1;
107
108  done += len;
[2643]109  ROAR_DBG("roar_vio_copy_data(out=%p, in=%p): len=%li, done=%li", out, in, (long int)len, (long int)done);
[1277]110 }
111
[2643]112 ROAR_DBG("roar_vio_copy_data(out=%p, in=%p): len=%li, done=%li", out, in, (long int)len, (long int)done);
113
[4876]114 roar_err_clear_all();
115
[2643]116 ROAR_DBG("roar_vio_copy_data(out=%p, in=%p) = %li", out, in, (long int)done);
[1277]117 return done;
118}
119
[1276]120//ll
Note: See TracBrowser for help on using the repository browser.