source: roaraudio/libroaryiff/connection.c @ 5961:06e7fd9e4c25

Last change on this file since 5961:06e7fd9e4c25 was 5961:06e7fd9e4c25, checked in by phi, 10 years ago

Updates of copyright and license headers

File size: 3.0 KB
Line 
1//connection.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2014
5 *
6 *  The code (may) include prototypes and comments (and maybe
7 *  other code fragements) from the yiff sound system.
8 *  According to the debian/copyright file upstream author is
9 *  Tara Milana <learfox@twu.net>. Also copyright is listed as:
10 *  Copyright (C)  1997-2003 WolfPack Entertainment
11 *
12 *  This file is part of libroaryiff a part of RoarAudio,
13 *  a cross-platform sound system for both, home and professional use.
14 *  See README for details.
15 *
16 *  This file is free software; you can redistribute it and/or modify
17 *  it under the terms of the GNU General Public License version 3
18 *  as published by the Free Software Foundation.
19 *
20 *  libroaryiff is distributed in the hope that it will be useful,
21 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 *  GNU General Public License for more details.
24 *
25 *  You should have received a copy of the GNU General Public License
26 *  along with this software; see the file COPYING.  If not, write to
27 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
28 *  Boston, MA 02110-1301, USA.
29 *
30 * NOTE: code fragments (like prototypes) taken from the yiff package
31 *       are 'GPLv2 or later' and are upgraded to GPLv3 by being used
32 *       within this document.
33 *
34 */
35
36#include <libroaryiff.h>
37
38YConnection *YOpenConnection (const char *start_arg, const char *con_arg) {
39 YConnection * ycon = roar_mm_malloc(sizeof(YConnection));
40 struct roar_connection con;
41 const char * server = (char *)con_arg;
42 const char * name   = "libroaryiff client";
43
44 memset(ycon, 0, sizeof(YConnection));
45
46 // there is no symbolic value for default con_arg
47 // in the heder files. So we use a hard coded value from the docs
48
49 if ( server != NULL ) {
50  if ( strcmp(server, "127.0.0.1:9433") == 0 ||
51       strcmp(server, "127.0.0.1")      == 0 ||   // \\                                         //
52       strcmp(server, "localhost")      == 0 ||   //   => Don't know if this is valid for libY  //
53       strcmp(server, "localhost:9433") == 0 ) {  // //   but we support it.                    //
54
55   server = NULL; // try default locations
56  }
57 }
58
59 if (roar_simple_connect(&con, server, name) == -1) {
60  // Handle start_arg here!
61  roar_mm_free(ycon);
62  return NULL;
63 }
64
65 if ( (ycon->fd = roar_get_connection_fh(&con)) == -1 ) {
66  roar_disconnect(&con);
67  roar_mm_free(ycon);
68  return NULL;
69 }
70
71 return ycon;
72}
73
74void YCloseConnection (YConnection *connection, Boolean no_shutdown) {
75 struct roar_vio_calls vio;
76
77 // in case we started the server by using +fork we can not keep it running
78 // as it will terminate anyway. If there are any other clients (I guess
79 // this is what this option is about) it will keep running.
80 (void)no_shutdown;
81
82 if ( connection == NULL )
83  return;
84
85 // roard will clean up all other sockets if the close the main one.
86
87 if ( roar_vio_open_fh_socket(&vio, connection->fd) != -1 ) {
88  roar_vio_close(&vio);
89 }
90
91 roar_mm_free(connection);
92}
93
94//ll
Note: See TracBrowser for help on using the repository browser.