home
/
code
/
khatus.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4bfac48
)
Fix character filling for ok, error and expiry reads
author
Siraaj Khandkar
<siraaj@khandkar.net>
Thu, 26 Mar 2020 20:34:31 +0000
(16:34 -0400)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Thu, 26 Mar 2020 20:34:31 +0000
(16:34 -0400)
x5/khatus.c
patch
|
blob
|
blame
|
history
diff --git
a/x5/khatus.c
b/x5/khatus.c
index
5caae33
..
35509d4
100644
(file)
--- a/
x5/khatus.c
+++ b/
x5/khatus.c
@@
-121,25
+121,25
@@
slot_expire(Slot *s, struct timespec t, char *buf)
timespecsub(&t, &(s->in_last_read), &td);
if (timespeccmp(&td, &(s->out_ttl), >=)) {
/* TODO: Maybe configurable expiry character. */
timespecsub(&t, &(s->in_last_read), &td);
if (timespeccmp(&td, &(s->out_ttl), >=)) {
/* TODO: Maybe configurable expiry character. */
- memset(buf + s->out_pos_lo, '_', s->out_
pos_hi - s->out_pos_lo
);
+ memset(buf + s->out_pos_lo, '_', s->out_
width
);
khlib_warn("Slot expired: \"%s\"\n", s->in_fifo);
}
}
void
khlib_warn("Slot expired: \"%s\"\n", s->in_fifo);
}
}
void
-slot_
read
_error(Slot *s, char *buf)
+slot_
set
_error(Slot *s, char *buf)
{
char *b;
int i;
{
char *b;
int i;
+ s->in_fd = -1;
b = buf + s->out_pos_lo;
/* Copy as much of the error message as possible.
* EXCLUDING the terminating \0. */
for (i = 0; i < errlen && i < s->out_width; i++)
b[i] = errmsg[i];
/* Any remaining positions: */
b = buf + s->out_pos_lo;
/* Copy as much of the error message as possible.
* EXCLUDING the terminating \0. */
for (i = 0; i < errlen && i < s->out_width; i++)
b[i] = errmsg[i];
/* Any remaining positions: */
- for (; i < s->out_width; i++)
- b[i] = '_';
+ memset(b + i, '_', s->out_width - i);
}
enum read_status
}
enum read_status
@@
-171,7
+171,7
@@
slot_read(Slot *s, struct timespec t, char *buf)
case 1:
/* TODO: Consider making msg term char a CLI option */
if (c == '\n' || c == '\0') {
case 1:
/* TODO: Consider making msg term char a CLI option */
if (c == '\n' || c == '\0') {
- r =
s->out_pos_hi - s->out_pos_cur
;
+ r =
(s->out_pos_hi - s->out_pos_cur) + 1
;
if (r > 0)
memset(buf + s->out_pos_cur, ' ', r);
s->out_pos_cur = s->out_pos_lo;
if (r > 0)
memset(buf + s->out_pos_cur, ' ', r);
s->out_pos_cur = s->out_pos_lo;
@@
-213,12
+213,12
@@
slots_read(Config *cfg, struct timespec *ti, char *buf)
s->in_fifo,
strerror(errno)
);
s->in_fifo,
strerror(errno)
);
- slot_
read
_error(s, buf);
+ slot_
set
_error(s, buf);
continue;
}
if (!(st.st_mode & S_IFIFO)) {
khlib_error("\"%s\" is not a FIFO\n", s->in_fifo);
continue;
}
if (!(st.st_mode & S_IFIFO)) {
khlib_error("\"%s\" is not a FIFO\n", s->in_fifo);
- slot_
read
_error(s, buf);
+ slot_
set
_error(s, buf);
continue;
}
if (s->in_fd < 0) {
continue;
}
if (s->in_fd < 0) {
@@
-238,7
+238,7
@@
slots_read(Config *cfg, struct timespec *ti, char *buf)
if (s->in_fd == -1) {
/* TODO Consider backing off retries for failed slots */
khlib_error("Failed to open \"%s\"\n", s->in_fifo);
if (s->in_fd == -1) {
/* TODO Consider backing off retries for failed slots */
khlib_error("Failed to open \"%s\"\n", s->in_fifo);
- slot_
read
_error(s, buf);
+ slot_
set
_error(s, buf);
continue;
}
khlib_debug("%s: open. in_fd: %d\n", s->in_fifo, s->in_fd);
continue;
}
khlib_debug("%s: open. in_fd: %d\n", s->in_fifo, s->in_fd);
@@
-273,6
+273,8
@@
slots_read(Config *cfg, struct timespec *ti, char *buf)
/* At-least-once ensures that expiries are still checked on timeouts. */
do {
for (s = cfg->slots; s; s = s->next) {
/* At-least-once ensures that expiries are still checked on timeouts. */
do {
for (s = cfg->slots; s; s = s->next) {
+ if (s->in_fd < 0)
+ continue;
if (FD_ISSET(s->in_fd, &fds)) {
khlib_debug("reading: %s\n", s->in_fifo);
switch (slot_read(s, t, buf)) {
if (FD_ISSET(s->in_fd, &fds)) {
khlib_debug("reading: %s\n", s->in_fifo);
switch (slot_read(s, t, buf)) {
This page took
0.02791 seconds
and
4
git commands to generate.