summary refs log tree commit diff
path: root/ring.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-27 22:42:33 -0400
committerJune McEnroe <june@causal.agency>2019-10-27 22:42:33 -0400
commit766210d614f249cf04b84b691351d03047f36754 (patch)
treedc21d9ae2c851ff54be19da4c6b8bd4fa3451939 /ring.c
parentSet SO_REUSEADDR on binds (diff)
downloadpounce-766210d614f249cf04b84b691351d03047f36754.tar.gz
pounce-766210d614f249cf04b84b691351d03047f36754.zip
Only increment consumer after successful send
Diffstat (limited to '')
-rw-r--r--ring.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ring.c b/ring.c
index 912d0d3..409fcd4 100644
--- a/ring.c
+++ b/ring.c
@@ -70,17 +70,23 @@ size_t ringDiff(size_t consumer) {
 	return ring.write - read.ptrs[consumer];
 }
 
-const char *ringConsume(time_t *time, size_t consumer) {
+const char *ringPeek(time_t *time, size_t consumer) {
 	assert(consumer < read.len);
 	if (!ringDiff(consumer)) return NULL;
 	if (ringDiff(consumer) > RingLen) {
 		read.ptrs[consumer] = ring.write - RingLen;
 	}
-	size_t i = read.ptrs[consumer]++ % RingLen;
+	size_t i = read.ptrs[consumer] % RingLen;
 	if (time) *time = ring.times[i];
 	return ring.lines[i];
 }
 
+const char *ringConsume(time_t *time, size_t consumer) {
+	const char *line = ringPeek(time, consumer);
+	read.ptrs[consumer]++;
+	return line;
+}
+
 void ringInfo(void) {
 	fprintf(stderr, "producer: %zu\n", ring.write);
 	for (size_t i = 0; i < read.len; ++i) {
-0400'>2018-08-06Fix allocation size in vaswprintfJune McEnroe This is so embarrassing. It only started crashing once it had strings that were long enough, and then it took me so long to notice this mistake. I was worried I was still doing va_list wrong somehow. 2018-08-06Implement word wrappingJune McEnroe 2018-08-06Use wchar_t strings for all of UIJune McEnroe vaswprintf is a nightmare. 2018-08-06Rename line editing functionsJune McEnroe 2018-08-05Initialize all possible color pairsJune McEnroe This is actually possible with use_default_colors! 2018-08-05Refactor color initializationJune McEnroe 2018-08-05Add ^L redrawJune McEnroe 2018-08-05Use 16 colors if availableJune McEnroe Fall back to using bold if there are only 8 colors. This also allowed bright background colors in 16-color terminals. I must port this system to torus. I'll be able to remove the awful termcap patch hack. 2018-08-05Limit parsed colors to number of mIRC colorsJune McEnroe Oh boy that's embarrassing. 2018-08-04Show source link on exitJune McEnroe 2018-08-04Implement line editing, scrollingJune McEnroe Don't really have a way to implement the M-* keys, and currently missing C-w. 2018-08-04Handle /topicJune McEnroe