summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/todo1
-rw-r--r--polyp/Makefile.am6
-rw-r--r--polyp/cmdline.c21
-rw-r--r--polyp/cmdline.h2
-rw-r--r--polyp/iochannel.c8
-rw-r--r--polyp/main.c20
-rw-r--r--polyp/mainloop.c20
-rw-r--r--polyp/memblockq.c7
-rw-r--r--polyp/memblockq.h3
-rw-r--r--polyp/module-alsa-sink.c2
-rw-r--r--polyp/module-alsa-source.c2
-rw-r--r--polyp/module-oss.c25
-rw-r--r--polyp/module-pipe-sink.c2
-rwxr-xr-xpolyp/polypaudio.pa19
-rw-r--r--polyp/polyplib-context.c4
-rw-r--r--polyp/polyplib-internal.h6
-rw-r--r--polyp/protocol-esound.c2
-rw-r--r--polyp/protocol-native.c8
-rw-r--r--polyp/pstream.c3
-rw-r--r--polyp/sink.c15
-rw-r--r--polyp/sink.h3
-rw-r--r--polyp/socket-util.c8
-rw-r--r--polyp/util.c40
-rw-r--r--polyp/util.h3
24 files changed, 181 insertions, 49 deletions
diff --git a/doc/todo b/doc/todo
index e7b91682..f8ebd9bb 100644
--- 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
diff --git a/polyp/Makefile.am b/polyp/Makefile.am
index 31bfbdee..73e80621 100644
--- a/polyp/Makefile.am
+++ b/polyp/Makefile.am
@@ -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 $<
diff --git a/polyp/cmdline.c b/polyp/cmdline.c
index 8acdde6f..9935e7b6 100644
--- a/polyp/cmdline.c
+++ b/polyp/cmdline.c
@@ -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;
}
diff --git a/polyp/cmdline.h b/polyp/cmdline.h
index 95ce91de..6a7f4dd7 100644
--- a/polyp/cmdline.h
+++ b/polyp/cmdline.h
@@ -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;
};
diff --git a/polyp/iochannel.c b/polyp/iochannel.c
index 813347d4..1aa70b93 100644
--- a/polyp/iochannel.c
+++ b/polyp/iochannel.c
@@ -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);
diff --git a/polyp/main.c b/polyp/main.c
index de02a110..526bf744 100644
--- a/polyp/main.c
+++ b/polyp/main.c
@@ -46,6 +46,14 @@
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;
diff --git a/polyp/mainloop.c b/polyp/mainloop.c
index 20d14e51..83f0b1e8 100644
--- a/polyp/mainloop.c
+++ b/polyp/mainloop.c
@@ -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);
diff --git a/polyp/memblockq.c b/polyp/memblockq.c
index b6dcca3f..7feb4685 100644
--- a/polyp/memblockq.c
+++ b/polyp/memblockq.c
@@ -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;
+}
diff --git a/polyp/memblockq.h b/polyp/memblockq.h
index 277beb55..16b51d7a 100644
--- a/polyp/memblockq.h
+++ b/polyp/memblockq.h
@@ -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
diff --git a/polyp/module-alsa-sink.c b/polyp/module-alsa-sink.c
index 06b07f33..0c9d77b8 100644
--- a/polyp/module-alsa-sink.c
+++ b/polyp/module-alsa-sink.c
@@ -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;
diff --git a/polyp/module-alsa-source.c b/polyp/module-alsa-source.c
index 9dc623d4..13df9f96 100644
--- a/polyp/module-alsa-source.c
+++ b/polyp/module-alsa-source.c
@@ -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;
diff --git a/polyp/module-oss.c b/polyp/module-oss.c
index 3fa3d1e3..403716fd 100644
--- a/polyp/module-oss.c
+++ b/polyp/module-oss.c
@@ -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;
diff --git a/polyp/module-pipe-sink.c b/polyp/module-pipe-sink.c
index 22d9f676..32a2c722 100644
--- a/polyp/module-pipe-sink.c
+++ b/polyp/module-pipe-sink.c
@@ -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;
}
diff --git a/polyp/polypaudio.pa b/polyp/polypaudio.pa
index 7c31634d..b683e627 100755
--- a/polyp/polypaudio.pa
+++ b/polyp/polypaudio.pa
@@ -1,4 +1,4 @@
-#!./polypaudio -F
+#!./polypaudio -rF
#
# This file is part of polypaudio.
@@ -24,22 +24,23 @@
#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
diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c
index 7542dd9b..2ead4004 100644
--- a/polyp/polyplib-context.c
+++ b/polyp/polyplib-context.c
@@ -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);
}
diff --git a/polyp/polyplib-internal.h b/polyp/polyplib-internal.h
index 8c5d3166..8f1a4942 100644
--- a/polyp/polyplib-internal.h
+++ b/polyp/polyplib-internal.h
@@ -34,10 +34,10 @@
#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)
diff --git a/polyp/protocol-esound.c b/polyp/protocol-esound.c
index 5102540b..2059dab8 100644
--- a/polyp/protocol-esound.c
+++ b/polyp/protocol-esound.c
@@ -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) {
diff --git a/polyp/protocol-native.c b/polyp/protocol-native.c
index 213568a0..9c6996be 100644
--- a/polyp/protocol-native.c
+++ b/polyp/protocol-native.c
@@ -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");*/
}
diff --git a/polyp/pstream.c b/polyp/pstream.c
index 81ee0b43..02dba72d 100644
--- a/polyp/pstream.c
+++ b/polyp/pstream.c
@@ -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;
}
diff --git a/polyp/sink.c b/polyp/sink.c
index b520dd8a..104248a9 100644
--- a/polyp/sink.c
+++ b/polyp/sink.c
@@ -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);
diff --git a/polyp/sink.h b/polyp/sink.h
index 9c91692e..940d1618 100644
--- a/polyp/sink.h
+++ b/polyp/sink.h
@@ -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);
diff --git a/polyp/socket-util.c b/polyp/socket-util.c
index 904381b7..f9d0febf 100644
--- a/polyp/socket-util.c
+++ b/polyp/socket-util.c
@@ -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;
}
diff --git a/polyp/util.c b/polyp/util.c
index 6c8febb6..0d930118 100644
--- a/polyp/util.c
+++ b/polyp/util.c
@@ -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);
+}
diff --git a/polyp/util.h b/polyp/util.h
index 9dab45d2..89505cde 100644
--- a/polyp/util.h
+++ b/polyp/util.h
@@ -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