source: roaraudio/roard/network.c @ 5910:cb47378a0e0b

roaraudio init
Last change on this file since 5910:cb47378a0e0b was 0:2a41d2f42394, checked in by phi, 16 years ago

Initial revision

File size: 789 bytes
Line 
1//network.c:
2
3#include "roard.h"
4
5int net_check_listen  (void) {
6 int r;
7 fd_set sl;
8 struct timeval tv;
9
10 FD_ZERO(&sl);
11 FD_SET(g_listen_socket, &sl);
12
13 tv.tv_sec  = 0;
14 tv.tv_usec = 1;
15
16 if ((r = select(g_listen_socket + 1, &sl, NULL, NULL, &tv)) > 0) {
17  ROAR_DBG("net_check_listen(void): We have a connection!");
18  return net_get_new_client();
19 }
20
21 return r;
22}
23
24int net_get_new_client (void) {
25 int fh;
26 int client;
27
28 fh = accept(g_listen_socket, NULL, NULL);
29
30 ROAR_DBG("net_get_new_client(void): fh = %i", fh);
31
32 client = clients_new();
33
34 if ( clients_set_fh(client, fh) == -1 ) {
35  ROAR_ERR("net_get_new_client(void): Can not set client's fh");
36
37  clients_delete(client);
38  close(fh);
39
40  ROAR_DBG("net_get_new_client(void) = -1");
41  return -1;
42 }
43
44// close(fh);
45
46 return 0;
47}
48
49//ll
Note: See TracBrowser for help on using the repository browser.