source: roaraudio/libroaryiff/connection.c @ 3832:25e79a40b829

Last change on this file since 3832:25e79a40b829 was 3832:25e79a40b829, checked in by phi, 14 years ago

use NULL, roar_mm_*()

File size: 2.2 KB
Line 
1//connection.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
5 *
6 *  This file is part of libroaryiff 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 *  libroaryiff 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
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <libroaryiff.h>
27
28YConnection *YOpenConnection (const char *start_arg, const char *con_arg) {
29 YConnection * ycon = roar_mm_malloc(sizeof(YConnection));
30 struct roar_connection con;
31 char * server = (char *)con_arg;
32 char * name   = "libroaryiff client";
33
34 memset(ycon, 0, sizeof(YConnection));
35
36 // there is no symbolic value for default con_arg
37 // in the heder files. So we use a hard coded value from the docs
38
39 if ( server != NULL ) {
40  if ( strcmp(server, "127.0.0.1:9433") == 0 ||
41       strcmp(server, "127.0.0.1")      == 0 ||   // \\                                         //
42       strcmp(server, "localhost")      == 0 ||   //   => Don't know if this is valid for libY  //
43       strcmp(server, "localhost:9433") == 0 ) {  // //   but we support it.                    //
44
45   server = NULL; // try default locations
46  }
47 }
48
49 if (roar_simple_connect(&con, server, name) == -1) {
50  // Handle start_arg here!
51  roar_mm_free(ycon);
52  return NULL;
53 }
54
55 if ( (ycon->fd = roar_get_connection_fh(&con)) == -1 ) {
56  roar_disconnect(&con);
57  roar_mm_free(ycon);
58  return NULL;
59 }
60
61 return ycon;
62}
63
64void YCloseConnection (YConnection *connection, Boolean no_shutdown) {
65 if ( connection == NULL )
66  return;
67
68 roar_simple_close(connection->fd);  // roard will clean up all other sockets if the close the main one.
69
70
71 roar_mm_free(connection);
72}
73
74//ll
Note: See TracBrowser for help on using the repository browser.