Commit b0843c16 authored by Federico Vaga's avatar Federico Vaga

wrtd:lib: log_read can be block

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>


NOTE
This commit has been created by `git subtree` on the Mock Turtle repository
on tag mock-turtle-2.0

This commit will not compile
parent 918f2a0c
......@@ -34,8 +34,6 @@ struct wrtd_desc {
*/
void unbag_ts(uint32_t *buf, int offset, struct wr_timestamp *ts);
int wrtd_validate_acknowledge(struct wrnc_msg *msg);
int wrtd_log_read(struct wrnc_hmq *hmq_log, struct wrtd_log_entry *log,
int count);
int wrtd_trig_id_cmp(struct wrtd_trig_id *id1, struct wrtd_trig_id *id2);
extern int wrtd_trivial_request(struct wrtd_node *dev,
struct wrnc_msg *request_msg,
......
......@@ -8,6 +8,7 @@
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <poll.h>
#include <libwrnc.h>
#include <libwrtd-internal.h>
#include <wrtd-serializers.h>
......@@ -149,24 +150,33 @@ out_close:
* @param[in] hmq_log logging HMQ.
* @param[out] log log message
* @param[in] count number of messages to read
* @param[in] poll_timeout poll(2) timeout argument. Negative means infinite.
* @return number of read messages on success (check errno if it returns less
* messages than expected), -1 on error and errno is set appropriately
*/
int wrtd_log_read(struct wrnc_hmq *hmq_log, struct wrtd_log_entry *log,
int count)
int count, int poll_timeout)
{
struct wrtd_log_entry *cur = log;
struct wrnc_msg *msg;
struct pollfd p;
int remaining = count;
int n_read = 0;
int n_read = 0, ret;
uint32_t id = 0, seq = 0;
p.fd = hmq_log->fd;
p.events = POLLIN;
/* Clean up errno to be able to distinguish between error cases and
normal behaviour when the function return less messages
than expected */
errno = 0;
while (remaining) {
struct wrtd_trigger_entry ent;
ret = poll(&p, 1, poll_timeout);
if (ret <= 0 || !(p.revents & POLLIN))
break;
msg = wrnc_hmq_receive(hmq_log);
if (!msg)
break;
......
......@@ -192,7 +192,7 @@ extern const char *wrtd_strlogging(enum wrtd_log_level lvl);
enum wrtd_log_level wrtd_strlogging_to_level(char *log);
extern void wrtd_strlogging_full(char *buf, uint32_t log_level);
extern int wrtd_log_read(struct wrnc_hmq *hmq_log, struct wrtd_log_entry *log,
int count);
int count, int poll_timeout);
extern void wrtd_log_close(struct wrnc_hmq *hmq);
extern struct wrnc_hmq *wrtd_in_log_open(struct wrtd_node *dev, int input);
extern int wrtd_in_log_level_set(struct wrtd_node *dev, unsigned int input,
......
......@@ -30,7 +30,7 @@ static int print_message(struct wrnc_hmq *hmq)
struct wrtd_log_entry log;
int count;
count = wrtd_log_read(hmq, &log, 1);
count = wrtd_log_read(hmq, &log, 1, 0);
if (count <= 0)
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment