source: roaraudio/roard/network.c @ 2529:eba7f2ff0163

Last change on this file since 2529:eba7f2ff0163 was 2529:eba7f2ff0163, checked in by phi, 15 years ago

got basic streaming working

File size: 2.8 KB
Line 
1//network.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard 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 *  RoarAudio 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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27#ifdef ROAR_SUPPORT_LISTEN
28
29#ifdef ROAR_BROKEN_PEERCRED
30#undef SO_PEERCRED
31#endif
32
33#ifdef ROAR_HAVE_SELECT
34#define _CAN_OPERATE
35#endif
36
37int net_check_listen  (void) {
38#ifdef _CAN_OPERATE
39 int r;
40 fd_set sl;
41 struct timeval tv;
42
43 FD_ZERO(&sl);
44 FD_SET(g_listen_socket, &sl);
45
46 tv.tv_sec  = 0;
47 tv.tv_usec = 1;
48
49 if ((r = select(g_listen_socket + 1, &sl, NULL, NULL, &tv)) > 0) {
50  ROAR_DBG("net_check_listen(void): We have a connection!");
51  return net_get_new_client();
52 }
53
54 return r;
55#else
56 return -1;
57#endif
58}
59
60#ifdef _CAN_OPERATE
61int net_get_new_client (void) {
62 int fh;
63 int client;
64#if defined(SO_PEERCRED) || defined(ROAR_HAVE_GETPEEREID)
65 struct roar_client * c;
66#endif
67#ifdef SO_PEERCRED
68 struct ucred cred;
69 socklen_t cred_len = sizeof(cred);
70#endif
71 struct roar_vio_calls vio;
72
73 fh = accept(g_listen_socket, NULL, NULL);
74
75 ROAR_DBG("net_get_new_client(void): fh = %i", fh);
76
77 client = clients_new();
78
79 if ( clients_set_fh(client, fh) == -1 ) {
80  ROAR_ERR("net_get_new_client(void): Can not set client's fh");
81
82  clients_delete(client);
83  close(fh);
84
85  ROAR_DBG("net_get_new_client(void) = -1");
86  return -1;
87 }
88
89#ifdef SO_PEERCRED
90 if ( clients_get(client, &c) != -1 ) {
91  if (getsockopt(fh, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len) != -1) {
92   if ( cred.pid != 0 ) {
93    c->pid = cred.pid;
94    c->uid = cred.uid;
95    c->gid = cred.gid;
96   }
97  } else {
98   ROAR_DBG("req_on_identify(): Can't get creds via SO_PEERCRED: %s", strerror(errno));
99  }
100 }
101#elif defined(ROAR_HAVE_GETPEEREID)
102 if ( clients_get(client, &c) != -1 ) {
103  if (getpeereid(fh, &(c->uid), &(c->gid)) == -1) {
104   ROAR_DBG("req_on_identify(): Can't get creds via getpeereid(): %s", strerror(errno));
105  }
106 }
107#endif
108
109 if ( clients_set_proto(client, ROAR_PROTO_ESOUND) == -1 )
110  return -1;
111
112 if ( roar_vio_open_fh(&vio, fh) == -1 )
113  return -1;
114
115 if ( emul_esd_exec_command(client, ESD_PROTO_CONNECT, &vio) == -1 )
116  return -1;
117
118// close(fh);
119
120 return 0;
121}
122#endif
123
124#endif
125
126//ll
Note: See TracBrowser for help on using the repository browser.