Use FIFO pipes for input
This commit is contained in:
parent
c73dbe983a
commit
e1fdae99e4
29
src/main.c
29
src/main.c
|
@ -120,7 +120,27 @@ int main(int argc, char* argv[])
|
|||
/* Create server.port/global for FIFO */
|
||||
path[1] = category[CAT_GLOB];
|
||||
path[2] = NULL;
|
||||
if (mkdir_bottomup(path)) {}
|
||||
if (mkdir_bottomup(path)) {
|
||||
path[2] = "in";
|
||||
path[3] = NULL;
|
||||
char pbuf[PATH_MAX];
|
||||
int tmp;
|
||||
if (assemble_path(path, pbuf, sizeof(pbuf))) {
|
||||
if ((mkfifo(pbuf, S_IRUSR | S_IWUSR | S_IWGRP)) != 0 && errno != EEXIST)
|
||||
LOG_ERRNO(LOG_ERROR, "Couldn't create FIFO for input.", pbuf);
|
||||
else {
|
||||
LOG_CONN(LOG_INFO, "Created a FIFO pipe for input.", pbuf, &cons[t]);
|
||||
ssize_t fd;
|
||||
if ((fd = open(pbuf, O_RDONLY | O_NONBLOCK)) != -1)
|
||||
cons[t].fds[1] = fd;
|
||||
else {
|
||||
LOG_ERRNO(LOG_WARN, "Couldn't open FIFO pipe for reading.", pbuf);
|
||||
cons[t].fds[1] = -1;
|
||||
}
|
||||
}
|
||||
} else
|
||||
LOG(LOG_WARN, "Couldn't assemble path for FIFO!", NULL);
|
||||
}
|
||||
|
||||
if ((sendbuflen = Assm_mesg(sendbuf, Assm_cmd_NICK(cons[t].names.nick), sizeof(sendbuf))) > 0)
|
||||
flush_buffer(sendbuf, sendbuflen, &cons[t]);
|
||||
|
@ -214,6 +234,13 @@ int main(int argc, char* argv[])
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (cons[t].fds[1] != -1) {
|
||||
LOG(LOG_DEBUG, "About to attempt to read input on FIFO.", NULL);
|
||||
if ((sendbuflen = read(cons[t].fds[1], sendbuf, sizeof(sendbuf))) > 0)
|
||||
flush_buffer(sendbuf, sendbuflen, &cons[t]);
|
||||
else if (sendbuflen == -1 && errno != EAGAIN)
|
||||
LOG_ERRNO(LOG_WARN, "Couldn't read from input FIFO.", NULL);
|
||||
}
|
||||
}
|
||||
} while (actcon > 0);
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define UIRC_HELPERS
|
||||
#include "../lib/uIRC/include/uirc.h"
|
||||
|
||||
|
|
Reference in New Issue