]> code.delx.au - pulseaudio/commitdiff
add support for SCHED_FIFO
authorLennart Poettering <lennart@poettering.net>
Wed, 1 Sep 2004 00:23:51 +0000 (00:23 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Sep 2004 00:23:51 +0000 (00:23 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@163 fefdeb5f-60dc-0310-8127-8f9354f1896f

24 files changed:
doc/todo
polyp/Makefile.am
polyp/cmdline.c
polyp/cmdline.h
polyp/iochannel.c
polyp/main.c
polyp/mainloop.c
polyp/memblockq.c
polyp/memblockq.h
polyp/module-alsa-sink.c
polyp/module-alsa-source.c
polyp/module-oss.c
polyp/module-pipe-sink.c
polyp/polypaudio.pa
polyp/polyplib-context.c
polyp/polyplib-internal.h
polyp/protocol-esound.c
polyp/protocol-native.c
polyp/pstream.c
polyp/sink.c
polyp/sink.h
polyp/socket-util.c
polyp/util.c
polyp/util.h

index e7b916827cd7779dfe381e5b8a851f83e63606e6..f8ebd9bbee1ad9fe140a8c0464ffa4f5d8c11713 100644 (file)
--- a/doc/todo
+++ b/doc/todo
@@ -13,6 +13,7 @@
 - cleanup tagstruct (add s32, pa_volume_t, pa_usec_t)
 - xmlrpc
 - remove all gcc warnings
+- esd compatible startup script or personality
 
 ** later ***
 - slp/rendezvous
index 31bfbdeeda347b0e01f75ca50d9c09a1bcac0ec4..73e80621efceedabf8e88d95d40b8debf5d2e3ff 100644 (file)
@@ -18,7 +18,7 @@
 # USA.
 
 AM_CFLAGS=-D_GNU_SOURCE -I$(top_srcdir) $(PTHREAD_CFLAGS)
-AM_CFLAGS+= -DDLSEARCHDIR=\"$(pkglibdir)\" 
+#AM_CFLAGS+= -DDLSEARCHDIR=\"$(pkglibdir)\" 
 AM_LDADD=$(PTHREAD_LIBS)
 AM_LIBADD=$(PTHREAD_LIBS)
 
@@ -437,3 +437,7 @@ libpolypcore_la_SOURCES = idxset.c idxset.h \
 
 endif
 
+
+suid: polypaudio
+       chown root:root $<
+       chmod u+s $<
index 8acdde6fbb3b8540d310f3d7c8fd37961ee32e4e..9935e7b66de3a84a20f41e6136274790648b1f26 100644 (file)
@@ -43,13 +43,16 @@ void pa_cmdline_help(const char *argv0) {
         e = argv0;
     
     printf("%s [options]\n"
+           "  -r         Try to set high process priority (only available as root)\n"
+           "  -R         Don't drop root if SETUID root\n"
            "  -L MODULE  Load the specified plugin module with the specified argument\n"
            "  -F FILE    Run the specified script\n"
            "  -C         Open a command line on the running TTY\n"
            "  -D         Daemonize after loading the modules\n"
            "  -f         Dont quit when the startup fails\n"
            "  -v         Verbose startup\n"
-           "  -h         Show this help\n", e);
+           "  -h         Show this help\n"
+           "  -V         Show version\n", e);
 }
 
 struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
@@ -59,13 +62,13 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
     assert(argc && argv);
 
     cmdline = pa_xmalloc(sizeof(struct pa_cmdline));
-    cmdline->daemonize = cmdline->help = cmdline->verbose = 0;
+    cmdline->daemonize = cmdline->help = cmdline->verbose = cmdline->high_priority = cmdline->stay_root = cmdline->version = 0;
     cmdline->fail = 1;
 
     buf = pa_strbuf_new();
     assert(buf);
     
-    while ((c = getopt(argc, argv, "L:F:CDhfv")) != -1) {
+    while ((c = getopt(argc, argv, "L:F:CDhfvrRV")) != -1) {
         switch (c) {
             case 'L':
                 pa_strbuf_printf(buf, "load %s\n", optarg);
@@ -86,8 +89,18 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
                 cmdline->fail = 0;
                 break;
             case 'v':
-                cmdline->verbose = 0;
+                cmdline->verbose = 1;
                 break;
+            case 'r':
+                cmdline->high_priority = 1;
+                break;
+            case 'R':
+                cmdline->stay_root = 1;
+                break;
+            case 'V':
+                cmdline->version = 1;
+                break;
+                
             default:
                 goto fail;
         }
index 95ce91decb8d47d2bc79954edb7c5ed5164172eb..6a7f4dd7dc8d587eae7ff52c78263930cb14665a 100644 (file)
@@ -24,7 +24,7 @@
 
 
 struct pa_cmdline {
-    int daemonize, help, fail, verbose;
+    int daemonize, help, fail, verbose, high_priority, stay_root, version;
     char *cli_commands;
 };
 
index 813347d421b76c74b888c93a8e20c9f201252fe6..1aa70b935d383421a7ce8c29343957dac17154fe 100644 (file)
@@ -173,8 +173,16 @@ int pa_iochannel_is_hungup(struct pa_iochannel*io) {
 
 ssize_t pa_iochannel_write(struct pa_iochannel*io, const void*data, size_t l) {
     ssize_t r;
+    assert(io);
+    assert(data);
+    assert(l);
+    assert(io->ofd >= 0);
+
+    
     assert(io && data && l && io->ofd >= 0);
 
+
+    
     if ((r = write(io->ofd, data, l)) >= 0) {
         io->writable = 0;
         enable_mainloop_sources(io);
index de02a110f66d3f12f4cf939701a8939cc9dfbfc9..526bf74492ca82b656d2b4326d27b51dea88016c 100644 (file)
 
 static struct pa_mainloop *mainloop;
 
+static void drop_root(void) {
+    if (getuid() != 0 && geteuid() == 0) {
+        fprintf(stderr, __FILE__": started SUID root, dropping root rights.\n");
+        setuid(getuid());
+        seteuid(getuid());
+    }
+}
+
 static void exit_signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
     m->quit(m, 1);
     fprintf(stderr, __FILE__": got signal.\n");
@@ -84,6 +92,18 @@ int main(int argc, char *argv[]) {
         goto finish;
     }
 
+    if (cmdline->version) {
+        printf(PACKAGE_NAME" "PACKAGE_VERSION"\n");
+        retval = 0;
+        goto finish;
+    }
+
+    if (cmdline->high_priority)
+        pa_raise_priority();
+    
+    if (!cmdline->stay_root)
+        drop_root();
+
     if (cmdline->daemonize) {
         pid_t child;
 
index 20d14e517bfcf3a7910a15a6bec2f6965ba08616..83f0b1e828cf7a013a2a8a5d0749db206adaf069 100644 (file)
@@ -332,6 +332,7 @@ void pa_mainloop_free(struct pa_mainloop* m) {
 static void scan_dead(struct pa_mainloop *m) {
     int all = 0;
     assert(m);
+
     if (m->io_events_scan_dead)
         pa_idxset_foreach(m->io_events, io_foreach, &all);
     if (m->time_events_scan_dead)
@@ -402,7 +403,7 @@ static void dispatch_defer(struct pa_mainloop *m) {
     for (e = pa_idxset_first(m->defer_events, &index); e; e = pa_idxset_next(m->defer_events, &index)) {
         if (e->dead || !e->enabled)
             continue;
-
         assert(e->callback);
         e->callback(&m->api, e, e->userdata);
     }
@@ -413,18 +414,23 @@ static int calc_next_timeout(struct pa_mainloop *m) {
     struct pa_time_event *e;
     struct timeval now;
     int t = -1;
+    int got_time = 0;
 
     if (pa_idxset_isempty(m->time_events))
         return -1;
 
-    gettimeofday(&now, NULL);
-    
     for (e = pa_idxset_first(m->time_events, &index); e; e = pa_idxset_next(m->time_events, &index)) {
         int tmp;
         
         if (e->dead || !e->enabled)
             continue;
 
+        /* Let's save a system call */
+        if (!got_time) {
+            gettimeofday(&now, NULL);
+            got_time = 1;
+        }
+
         if (e->timeval.tv_sec < now.tv_sec || (e->timeval.tv_sec == now.tv_sec && e->timeval.tv_usec <= now.tv_usec)) 
             return 0;
 
@@ -448,17 +454,23 @@ static void dispatch_timeout(struct pa_mainloop *m) {
     uint32_t index;
     struct pa_time_event *e;
     struct timeval now;
+    int got_time = 0;
     assert(m);
 
     if (pa_idxset_isempty(m->time_events))
         return;
 
-    gettimeofday(&now, NULL);
     for (e = pa_idxset_first(m->time_events, &index); e; e = pa_idxset_next(m->time_events, &index)) {
         
         if (e->dead || !e->enabled)
             continue;
 
+        /* Let's save a system call */
+        if (!got_time) {
+            gettimeofday(&now, NULL);
+            got_time = 1;
+        }
+        
         if (e->timeval.tv_sec < now.tv_sec || (e->timeval.tv_sec == now.tv_sec && e->timeval.tv_usec <= now.tv_usec)) {
             assert(e->callback);
 
index b6dcca3f546617e956db77bb9beab55acaa6593e..7feb4685f985d2b7022cfb29bab0132cdc09e5ed 100644 (file)
@@ -56,7 +56,7 @@ struct pa_memblockq* pa_memblockq_new(size_t maxlength, size_t tlength, size_t b
 
     bq->current_length = 0;
 
-    fprintf(stderr, "memblockq requested: maxlength=%u, tlength=%u, base=%u, prebuf=%u, minreq=%u\n", maxlength, tlength, base, prebuf, minreq);
+    /*fprintf(stderr, "memblockq requested: maxlength=%u, tlength=%u, base=%u, prebuf=%u, minreq=%u\n", maxlength, tlength, base, prebuf, minreq);*/
     
     bq->base = base;
 
@@ -324,3 +324,8 @@ void pa_memblockq_flush(struct pa_memblockq *bq) {
     bq->n_blocks = 0;
     bq->current_length = 0;
 }
+
+uint32_t pa_memblockq_get_tlength(struct pa_memblockq *bq) {
+    assert(bq);
+    return bq->tlength;
+}
index 277beb55f7b5f980c56579c849815312d16646aa..16b51d7a8a0e348389afca46ef3a5083a2e61207 100644 (file)
@@ -89,4 +89,7 @@ void pa_memblockq_seek(struct pa_memblockq *bq, size_t delta);
 /* Flush the queue */
 void pa_memblockq_flush(struct pa_memblockq *bq);
 
+/* Get Target length */
+uint32_t pa_memblockq_get_tlength(struct pa_memblockq *bq);
+
 #endif
index 06b07f3370e68cacc511b63120d928ab3057dd69..0c9d77b809358444347e19d53e329e29d02c0503 100644 (file)
@@ -99,7 +99,7 @@ static void do_write(struct userdata *u) {
             
         assert(memchunk->memblock && memchunk->memblock->data && memchunk->length && memchunk->memblock->length && (memchunk->length % u->frame_size) == 0);
 
-        if ((frames = snd_pcm_writei(u->pcm_handle, memchunk->memblock->data + memchunk->index, memchunk->length / u->frame_size)) < 0) {
+        if ((frames = snd_pcm_writei(u->pcm_handle, (uint8_t*) memchunk->memblock->data + memchunk->index, memchunk->length / u->frame_size)) < 0) {
             if (frames == -EAGAIN)
                 return;
 
index 9dc623d4dffd2dfe69ff1efccb4736a717017d94..13df9f9608ea513166c5278a69838d5055f81922 100644 (file)
@@ -95,7 +95,7 @@ static void do_read(struct userdata *u) {
             
         assert(u->memchunk.memblock && u->memchunk.memblock->data && u->memchunk.length && u->memchunk.memblock->length && (u->memchunk.length % u->frame_size) == 0);
 
-        if ((frames = snd_pcm_readi(u->pcm_handle, u->memchunk.memblock->data + u->memchunk.index, u->memchunk.length / u->frame_size)) < 0) {
+        if ((frames = snd_pcm_readi(u->pcm_handle, (uint8_t*) u->memchunk.memblock->data + u->memchunk.index, u->memchunk.length / u->frame_size)) < 0) {
             if (frames == -EAGAIN)
                 return;
             
index 3fa3d1e35d973c0b77366c4d2bf1571f3dd4856d..403716fd8aa5429cc84cc4fd38bae03f959b3045 100644 (file)
@@ -93,21 +93,22 @@ static void do_write(struct userdata *u) {
         return;
 
     update_usage(u);
-     
-    if (!u->memchunk.length) {
-        if (pa_sink_render(u->sink, u->out_fragment_size, &u->memchunk) < 0)
-            memchunk = &u->silence;
-        else
-            memchunk = &u->memchunk;
-    }
 
-    assert(memchunk->memblock && memchunk->length);
+    memchunk = &u->memchunk;
+    
+    if (!memchunk->length)
+        if (pa_sink_render(u->sink, u->out_fragment_size, memchunk) < 0)
+            memchunk = &u->silence;
     
-    if ((r = pa_iochannel_write(u->io, memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
+    assert(memchunk->memblock);
+    assert(memchunk->memblock->data);
+    assert(memchunk->length);
+    
+    if ((r = pa_iochannel_write(u->io, (uint8_t*) memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
         fprintf(stderr, "write() failed: %s\n", strerror(errno));
         return;
     }
-
+        
     if (memchunk == &u->silence)
         assert(r % u->sample_size == 0);
     else {
@@ -215,8 +216,8 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
 
     fprintf(stderr, "module-oss: device opened in %s mode.\n", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
 
-    if (pa_oss_set_fragments(fd, nfrags, frag_size) < 0)
-        goto fail;
+    if (pa_oss_set_fragments(fd, nfrags, frag_size) < 0)   
+        goto fail;   
 
     if (pa_oss_auto_format(fd, &ss) < 0)
         goto fail;
index 22d9f67680ea9198c8b4a982d0bc2503d45a4879..32a2c722b982c90f27ba763f0865067ee4589361 100644 (file)
@@ -82,7 +82,7 @@ static void do_write(struct userdata *u) {
 
     assert(u->memchunk.memblock && u->memchunk.length);
     
-    if ((r = pa_iochannel_write(u->io, u->memchunk.memblock->data + u->memchunk.index, u->memchunk.length)) < 0) {
+    if ((r = pa_iochannel_write(u->io, (uint8_t*) u->memchunk.memblock->data + u->memchunk.index, u->memchunk.length)) < 0) {
         fprintf(stderr, "write() failed: %s\n", strerror(errno));
         return;
     }
index 7c31634dd84c072f0dd9a910b1406863b37101e4..b683e627bf3987f9ff2ff94114edbc16e618da64 100755 (executable)
@@ -1,4 +1,4 @@
-#!./polypaudio -F
+#!./polypaudio -rF 
 
 #
 # This file is part of polypaudio.
 #load module-alsa-source device=plughw:1,0
 #load module-oss device="/dev/dsp" sink_name=output source_name=input
 #load module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
-load module-pipe-sink
+#load module-pipe-sink
 
 # Load audio drivers automatically on access
 
-#autoload_sink_add output module-oss device="/dev/dsp" sink_name=output source_name=input
-#autoload_source_add input module-oss device="/dev/dsp" sink_name=output source_name=input
+autoload_sink_add output module-oss device="/dev/adsp" sink_name=output source_name=input
+autoload_source_add input module-oss device="/dev/adsp" sink_name=output source_name=input
 #autoload_sink_add output module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
 #autoload_source_add input module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
-autoload_sink_add output module-alsa-sink sink_name=output
-autoload_source_add input module-alsa-source source_name=input
+#autoload_sink_add output module-alsa-sink sink_name=output
+#autoload_source_add input module-alsa-source source_name=input
 
 # Load several protocols
-load module-esound-protocol-tcp
-load module-simple-protocol-tcp
+#load module-esound-protocol-tcp
+#load module-simple-protocol-tcp
 load module-native-protocol-unix
-load module-cli-protocol-unix
+#load module-cli-protocol-unix
+load module-esound-protocol-unix
 
 # Load the CLI module
 load module-cli
index 7542dd9bb089a8cf48ac1abdd5edfe2e41d64cb8..2ead400410998d4c4f7f50348703a1cf74841730 100644 (file)
@@ -202,7 +202,7 @@ static void pstream_memblock_callback(struct pa_pstream *p, uint32_t channel, ui
     
     if ((s = pa_dynarray_get(c->record_streams, channel))) {
         if (s->read_callback)
-            s->read_callback(s, chunk->memblock->data + chunk->index, chunk->length, s->read_userdata);
+            s->read_callback(s, (uint8_t*) chunk->memblock->data + chunk->index, chunk->length, s->read_userdata);
     }
 
     pa_context_unref(c);
@@ -451,7 +451,7 @@ static void set_dispatch_callbacks(struct pa_operation *o) {
     else {
         if (o->callback) {
             void (*cb)(struct pa_context *c, void *userdata);
-            cb = (void*) o->callback;
+            cb = (void (*)(struct pa_context*, void*)) o->callback;
             cb(o->context, o->userdata);
         }
         
index 8c5d3166a8c457063523bffd720e571021d2be3b..8f1a4942698b87e9770c2241538f8ed7d2cbac41 100644 (file)
 #include "llist.h"
 #include "native-common.h"
 
-#define DEFAULT_TLENGTH (10240*2)
-#define DEFAULT_MAXLENGTH (DEFAULT_TLENGTH*2)
+#define DEFAULT_TLENGTH (10240*4)
+#define DEFAULT_MAXLENGTH ((DEFAULT_TLENGTH*3)/2)
 #define DEFAULT_PREBUF DEFAULT_TLENGTH
-#define DEFAULT_MINREQ 1024
+#define DEFAULT_MINREQ 512
 #define DEFAULT_FRAGSIZE 1024
 
 #define DEFAULT_TIMEOUT (5*60)
index 5102540b2ae8ac1c4bbafadf39f65139fe74de62..2059dab83394206e28eb3646dc1bc8870dea5bbe 100644 (file)
@@ -903,6 +903,8 @@ static void sink_input_drop_cb(struct pa_sink_input *i, const struct pa_memchunk
     /* do something */
     assert(c->protocol && c->protocol->core && c->protocol->core->mainloop && c->protocol->core->mainloop->defer_enable);
     c->protocol->core->mainloop->defer_enable(c->defer_event, 1);
+
+    assert(pa_memblockq_get_length(c->input_memblockq) > 2048);
 }
 
 static void sink_input_kill_cb(struct pa_sink_input *i) {
index 213568a0570c249bae065bec407465a0cde8608b..9c6996be6b33ce1832c9e19e703b4435f7ca4401 100644 (file)
@@ -421,6 +421,8 @@ static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk
     assert(i && i->userdata && chunk);
     s = i->userdata;
 
+    /*fprintf(stderr, "%3.0f      \r", (double) pa_memblockq_get_length(s->memblockq)/pa_memblockq_get_tlength(s->memblockq)*100);*/
+    
     if (pa_memblockq_peek(s->memblockq, chunk) < 0)
         return -1;
 
@@ -1360,6 +1362,7 @@ static void command_flush_or_trigger_playback_stream(struct pa_pdispatch *pd, ui
     else {
         assert(command == PA_COMMAND_FLUSH_PLAYBACK_STREAM);
         pa_memblockq_flush(s->memblockq);
+        /*fprintf(stderr, "flush: %u\n", pa_memblockq_get_length(s->memblockq));*/
     }
 
     pa_sink_notify(s->sink_input->sink);
@@ -1427,7 +1430,8 @@ static void pstream_memblock_callback(struct pa_pstream *p, uint32_t channel, ui
             l = chunk->length;
 
         if (l > 0) {
-            memcpy(u->memchunk.memblock->data + u->memchunk.index + u->memchunk.length, chunk->memblock->data+chunk->index, l);
+            memcpy((uint8_t*) u->memchunk.memblock->data + u->memchunk.index + u->memchunk.length,
+                   (uint8_t*) chunk->memblock->data+chunk->index, l);
             u->memchunk.length += l;
             u->length -= l;
         }
@@ -1439,7 +1443,7 @@ static void pstream_die_callback(struct pa_pstream *p, void *userdata) {
     assert(p && c);
     connection_free(c);
 
-    fprintf(stderr, "protocol-native: connection died.\n");
+/*    fprintf(stderr, "protocol-native: connection died.\n");*/
 }
 
 
index 81ee0b439b65ab5a81d7377cad78a4dbb8522649..02dba72d34045698861fa4623772c09dca196044 100644 (file)
@@ -169,6 +169,9 @@ struct pa_pstream *pa_pstream_new(struct pa_mainloop_api *m, struct pa_iochannel
 
     p->memblock_stat = s;
 
+    pa_iochannel_socket_set_rcvbuf(io, 1024*8); 
+    pa_iochannel_socket_set_sndbuf(io, 1024*8); 
+
     return p;
 }
 
index b520dd8aa4d1081573123a904a2be50d979040d7..104248a9b8fb6124b2f3b71ffbeb3fc77661e0aa 100644 (file)
@@ -220,7 +220,7 @@ int pa_sink_render_into(struct pa_sink*s, struct pa_memchunk *target) {
         if (l > info[0].chunk.length)
             l = info[0].chunk.length;
         
-        memcpy(target->memblock->data+target->index, info[0].chunk.memblock->data + info[0].chunk.index, l);
+        memcpy((uint8_t*) target->memblock->data+target->index, (uint8_t*) info[0].chunk.memblock->data + info[0].chunk.index, l);
         target->length = l;
 
         if (s->volume != PA_VOLUME_NORM || info[0].volume != PA_VOLUME_NORM)
@@ -229,7 +229,7 @@ int pa_sink_render_into(struct pa_sink*s, struct pa_memchunk *target) {
         if (volume != PA_VOLUME_NORM)
             pa_volume_memchunk(target, &s->sample_spec, volume);
     } else
-        target->length = l = pa_mix(info, n, target->memblock->data+target->index, target->length, &s->sample_spec, s->volume);
+        target->length = l = pa_mix(info, n, (uint8_t*) target->memblock->data+target->index, target->length, &s->sample_spec, s->volume);
     
     assert(l);
     inputs_drop(s, info, n, l);
@@ -267,6 +267,17 @@ void pa_sink_render_into_full(struct pa_sink *s, struct pa_memchunk *target) {
     }
 }
 
+void pa_sink_render_full(struct pa_sink *s, size_t length, struct pa_memchunk *result) {
+    assert(s && length && result);
+
+    /*** This needs optimization ***/
+    
+    result->memblock = pa_memblock_new(result->length = length, s->core->memblock_stat);
+    result->index = 0;
+
+    pa_sink_render_into_full(s, result);
+}
+
 pa_usec_t pa_sink_get_latency(struct pa_sink *s) {
     assert(s);
 
index 9c91692e16bf34ede608d144fe9afd18a8ec5a6a..940d16184f61f87243d378071277f3b12b59712f 100644 (file)
@@ -53,9 +53,10 @@ struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, co
 void pa_sink_free(struct pa_sink* s);
 
 int pa_sink_render(struct pa_sink*s, size_t length, struct pa_memchunk *result);
+void pa_sink_render_full(struct pa_sink *s, size_t length, struct pa_memchunk *result);
 int pa_sink_render_into(struct pa_sink*s, struct pa_memchunk *target);
 void pa_sink_render_into_full(struct pa_sink *s, struct pa_memchunk *target);
-
+    
 pa_usec_t pa_sink_get_latency(struct pa_sink *s);
 
 void pa_sink_notify(struct pa_sink*s);
index 904381b7e6f5c5e5beca4c38120b4176001c60b5..f9d0febfa2d1979475ddb8c2190bc8b167132a11 100644 (file)
@@ -121,8 +121,10 @@ int pa_socket_tcp_low_delay(int fd) {
 int pa_socket_set_rcvbuf(int fd, size_t l) {
     assert(fd >= 0);
 
-    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &l, sizeof(l)) < 0)
+    if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &l, sizeof(l)) < 0) {
+        fprintf(stderr, "SO_RCVBUF: %s\n", strerror(errno));
         return -1;
+    }
 
     return 0;
 }
@@ -130,8 +132,10 @@ int pa_socket_set_rcvbuf(int fd, size_t l) {
 int pa_socket_set_sndbuf(int fd, size_t l) {
     assert(fd >= 0);
 
-    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &l, sizeof(l)) < 0)
+    if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &l, sizeof(l)) < 0) {
+        fprintf(stderr, "SO_SNDBUF: %s\n", strerror(errno));
         return -1;
+    }
 
     return 0;
 }
index 6c8febb62494cbf634d365d1c39b2576398f4c1e..0d930118b5ddfdf318612cd5d9933f04afe20b2d 100644 (file)
@@ -37,6 +37,8 @@
 #include <signal.h>
 #include <pthread.h>
 #include <sys/time.h>
+#include <sched.h>
+#include <sys/resource.h>
 
 #include "util.h"
 #include "xmalloc.h"
@@ -83,7 +85,7 @@ ssize_t pa_loop_read(int fd, void*data, size_t size) {
             break;
         
         ret += r;
-        data += r;
+        data = (uint8_t*) data + r;
         size -= r;
     }
 
@@ -104,7 +106,7 @@ ssize_t pa_loop_write(int fd, const void*data, size_t size) {
             break;
         
         ret += r;
-        data += r;
+        data = (uint8_t*) data + r;
         size -= r;
     }
 
@@ -213,3 +215,37 @@ uint32_t pa_age(struct timeval *tv) {
 
     return r;
 }
+
+#define NICE_LEVEL (-15)
+
+void pa_raise_priority(void) {
+    if (setpriority(PRIO_PROCESS, 0, NICE_LEVEL) < 0)
+        fprintf(stderr, __FILE__": setpriority() failed: %s\n", strerror(errno));
+    else
+        fprintf(stderr, __FILE__": Successfully gained nice level %i.\n", NICE_LEVEL);
+    
+#ifdef _POSIX_PRIORITY_SCHEDULING
+    {
+        struct sched_param sp;
+        sched_getparam(0, &sp);
+        sp.sched_priority = 1;
+        if (sched_setscheduler(0, SCHED_FIFO, &sp) < 0)
+            fprintf(stderr, __FILE__": sched_setscheduler() failed: %s\n", strerror(errno));
+        else
+            fprintf(stderr, __FILE__": Successfully gained SCHED_FIFO scheduling.\n");
+    }
+#endif
+}
+
+void pa_reset_priority(void) {
+#ifdef _POSIX_PRIORITY_SCHEDULING
+    {
+        struct sched_param sp;
+        sched_getparam(0, &sp);
+        sp.sched_priority = 0;
+        sched_setscheduler(0, SCHED_OTHER, &sp);
+    }
+#endif
+
+    setpriority(PRIO_PROCESS, 0, 0);
+}
index 9dab45d24fbbae772a97cc2998321afc2187e17a..89505cde234d2aeed2b4a450aabcc6f323af7321 100644 (file)
@@ -41,4 +41,7 @@ char *pa_get_host_name(char *s, size_t l);
 
 uint32_t pa_age(struct timeval *tv);
 
+void pa_raise_priority(void);
+void pa_reset_priority(void);
+
 #endif