~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/pulsecore/socket-client.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2008-11-04 15:46:00 UTC
  • mfrom: (1.2.1 upstream) (1.1.6 lenny)
  • Revision ID: james.westby@ubuntu.com-20081104154600-hlzknpcazaam0nxm
Tags: 0.9.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Don't build against, and create jack package. Jack is not in main.
  - Remove --disable-per-user-esound-socket from configure flags, as we still
    want per user esound sockets.
  - Remove stop links from rc0 and rc6.
  - Change default resample algorithm and bubffer size.
  - Add alsa configuration files to route alsa applications via pulseaudio.
  - Move libasound2-plugins from Recommends to Depends.
* debian/pulseaudio.preinst: When upgrading from intrepid, remove
  /etc/X11/Xsession.d/70pulseaudio, as this was used to minimize a race
  condition when starting GNOME in intrepid. This race should not exist in
  jaunty once libcanberra is built to use pulseaudio as a backend.
* Do not spawn a pulseaudio server if clients fail to find a running server.
* Remove explicit version dependency for libspeex-dev to allow the package
  to be built for now.
* Regenerate autotools files to work with Ubuntu's newer libtool/libltdl.
* debian/control: libpulsecore5 -> libpulsecore8 to match the library
  soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: socket-client.c 1971 2007-10-28 19:13:50Z lennart $ */
2
 
 
3
1
/***
4
2
    This file is part of PulseAudio.
5
3
 
61
59
#include <pulsecore/core-error.h>
62
60
#include <pulsecore/socket-util.h>
63
61
#include <pulsecore/core-util.h>
 
62
#include <pulsecore/socket-util.h>
64
63
#include <pulsecore/log.h>
65
64
#include <pulsecore/parseaddr.h>
66
65
#include <pulsecore/macro.h>
77
76
    pa_io_event *io_event;
78
77
    pa_time_event *timeout_event;
79
78
    pa_defer_event *defer_event;
80
 
    void (*callback)(pa_socket_client*c, pa_iochannel *io, void *userdata);
 
79
    pa_socket_client_cb_t callback;
81
80
    void *userdata;
82
 
    int local;
 
81
    pa_bool_t local;
83
82
#ifdef HAVE_LIBASYNCNS
84
83
    asyncns_t *asyncns;
85
84
    asyncns_query_t * asyncns_query;
87
86
#endif
88
87
};
89
88
 
90
 
static pa_socket_client*pa_socket_client_new(pa_mainloop_api *m) {
 
89
static pa_socket_client* socket_client_new(pa_mainloop_api *m) {
91
90
    pa_socket_client *c;
92
91
    pa_assert(m);
93
92
 
96
95
    c->mainloop = m;
97
96
    c->fd = -1;
98
97
    c->io_event = NULL;
 
98
    c->timeout_event = NULL;
99
99
    c->defer_event = NULL;
100
 
    c->timeout_event = NULL;
101
100
    c->callback = NULL;
102
101
    c->userdata = NULL;
103
 
    c->local = 0;
 
102
    c->local = FALSE;
104
103
 
105
104
#ifdef HAVE_LIBASYNCNS
106
105
    c->asyncns = NULL;
119
118
        c->io_event = NULL;
120
119
    }
121
120
 
 
121
    if (c->timeout_event) {
 
122
        c->mainloop->time_free(c->timeout_event);
 
123
        c->timeout_event = NULL;
 
124
    }
 
125
 
122
126
    if (c->defer_event) {
123
127
        c->mainloop->defer_free(c->defer_event);
124
128
        c->defer_event = NULL;
125
129
    }
126
 
 
127
 
    if (c->timeout_event) {
128
 
        c->mainloop->time_free(c->timeout_event);
129
 
        c->timeout_event = NULL;
130
 
    }
131
130
}
132
131
 
133
132
static void do_call(pa_socket_client *c) {
177
176
    pa_socket_client_unref(c);
178
177
}
179
178
 
180
 
static void connect_fixed_cb(pa_mainloop_api *m, pa_defer_event *e, void *userdata) {
 
179
static void connect_defer_cb(pa_mainloop_api *m, pa_defer_event *e, void *userdata) {
181
180
    pa_socket_client *c = userdata;
182
181
 
183
182
    pa_assert(m);
188
187
    do_call(c);
189
188
}
190
189
 
191
 
static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
 
190
static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
192
191
    pa_socket_client *c = userdata;
193
192
 
194
193
    pa_assert(m);
223
222
 
224
223
        pa_assert_se(c->io_event = c->mainloop->io_new(c->mainloop, c->fd, PA_IO_EVENT_OUTPUT, connect_io_cb, c));
225
224
    } else
226
 
        pa_assert_se(c->defer_event = c->mainloop->defer_new(c->mainloop, connect_fixed_cb, c));
 
225
        pa_assert_se(c->defer_event = c->mainloop->defer_new(c->mainloop, connect_defer_cb, c));
227
226
 
228
227
    return 0;
229
228
}
252
251
 
253
252
    memset(&sa, 0, sizeof(sa));
254
253
    sa.sun_family = AF_UNIX;
255
 
    strncpy(sa.sun_path, filename, sizeof(sa.sun_path)-1);
256
 
    sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
 
254
    pa_strlcpy(sa.sun_path, filename, sizeof(sa.sun_path));
257
255
 
258
256
    return pa_socket_client_new_sockaddr(m, (struct sockaddr*) &sa, sizeof(sa));
259
257
}
271
269
    pa_assert(sa);
272
270
    pa_assert(salen);
273
271
 
274
 
    switch (sa->sa_family) {
275
 
        case AF_UNIX:
276
 
            c->local = 1;
277
 
            break;
278
 
 
279
 
        case AF_INET:
280
 
            c->local = ((const struct sockaddr_in*) sa)->sin_addr.s_addr == INADDR_LOOPBACK;
281
 
            break;
282
 
 
283
 
        case AF_INET6:
284
 
            c->local = memcmp(&((const struct sockaddr_in6*) sa)->sin6_addr, &in6addr_loopback, sizeof(struct in6_addr)) == 0;
285
 
            break;
286
 
 
287
 
        default:
288
 
            c->local = 0;
289
 
    }
 
272
    c->local = pa_socket_address_is_local(sa);
290
273
 
291
274
    if ((c->fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
292
275
        pa_log("socket(): %s", pa_cstrerror(errno));
294
277
    }
295
278
 
296
279
    pa_make_fd_cloexec(c->fd);
 
280
 
297
281
    if (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)
298
282
        pa_make_tcp_socket_low_delay(c->fd);
299
283
    else
300
284
        pa_make_socket_low_delay(c->fd);
301
285
 
302
 
    if (do_connect(c, sa, salen) < 0)
 
286
    if (do_connect(c, sa, (socklen_t) salen) < 0)
303
287
        return -1;
304
288
 
305
289
    return 0;
312
296
    pa_assert(sa);
313
297
    pa_assert(salen > 0);
314
298
 
315
 
    pa_assert_se(c = pa_socket_client_new(m));
 
299
    pa_assert_se(c = socket_client_new(m));
316
300
 
317
301
    if (sockaddr_prepare(c, sa, salen) < 0)
318
302
        goto fail;
361
345
    return c;
362
346
}
363
347
 
364
 
void pa_socket_client_set_callback(pa_socket_client *c, void (*on_connection)(pa_socket_client *c, pa_iochannel*io, void *userdata), void *userdata) {
 
348
void pa_socket_client_set_callback(pa_socket_client *c, pa_socket_client_cb_t on_connection, void *userdata) {
365
349
    pa_assert(c);
366
350
    pa_assert(PA_REFCNT_VALUE(c) >= 1);
367
351
 
386
370
 
387
371
#ifdef HAVE_LIBASYNCNS
388
372
 
389
 
static void asyncns_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
 
373
static void asyncns_cb(pa_mainloop_api*m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
390
374
    pa_socket_client *c = userdata;
391
375
    struct addrinfo *res = NULL;
392
376
    int ret;
453
437
    pa_assert(!c->timeout_event);
454
438
 
455
439
    pa_gettimeofday(&tv);
456
 
    pa_timeval_add(&tv, CONNECT_TIMEOUT * 1000000);
 
440
    pa_timeval_add(&tv, CONNECT_TIMEOUT * PA_USEC_PER_SEC);
457
441
    c->timeout_event = c->mainloop->time_new(c->mainloop, &tv, timeout_cb, c);
458
442
}
459
443
 
489
473
            hints.ai_family = a.type == PA_PARSED_ADDRESS_TCP4 ? PF_INET : (a.type == PA_PARSED_ADDRESS_TCP6 ? PF_INET6 : PF_UNSPEC);
490
474
            hints.ai_socktype = SOCK_STREAM;
491
475
 
492
 
#ifdef HAVE_LIBASYNCNS
 
476
#if defined(HAVE_LIBASYNCNS)
493
477
            {
494
478
                asyncns_t *asyncns;
495
479
 
496
480
                if (!(asyncns = asyncns_new(1)))
497
481
                    goto finish;
498
482
 
499
 
                c = pa_socket_client_new(m);
 
483
                pa_assert_se(c = socket_client_new(m));
500
484
                c->asyncns = asyncns;
501
485
                c->asyncns_io_event = m->io_new(m, asyncns_fd(c->asyncns), PA_IO_EVENT_INPUT, asyncns_cb, c);
502
486
                c->asyncns_query = asyncns_getaddrinfo(c->asyncns, a.path_or_host, port, &hints);
503
487
                pa_assert(c->asyncns_query);
504
488
                start_timeout(c);
505
489
            }
506
 
#else /* HAVE_LIBASYNCNS */
 
490
#elif defined(HAVE_GETADDRINFO)
507
491
            {
508
 
#ifdef HAVE_GETADDRINFO
509
492
                int ret;
510
493
                struct addrinfo *res = NULL;
511
494
 
520
503
                }
521
504
 
522
505
                freeaddrinfo(res);
523
 
#else /* HAVE_GETADDRINFO */
 
506
            }
 
507
#else
 
508
            {
524
509
                struct hostent *host = NULL;
525
510
                struct sockaddr_in s;
526
511
 
546
531
 
547
532
                if ((c = pa_socket_client_new_sockaddr(m, (struct sockaddr*)&s, sizeof(s))))
548
533
                    start_timeout(c);
549
 
#endif /* HAVE_GETADDRINFO */
550
534
            }
551
535
#endif /* HAVE_LIBASYNCNS */
552
536
        }
561
545
/* Return non-zero when the target sockaddr is considered
562
546
   local. "local" means UNIX socket or TCP socket on localhost. Other
563
547
   local IP addresses are not considered local. */
564
 
int pa_socket_client_is_local(pa_socket_client *c) {
 
548
pa_bool_t pa_socket_client_is_local(pa_socket_client *c) {
565
549
    pa_assert(c);
566
550
    pa_assert(PA_REFCNT_VALUE(c) >= 1);
567
551