guint retransmits;
};
+#define FUZZY_CMD_FLAG_REPLIED (1 << 0)
+#define FUZZY_CMD_FLAG_SENT (1 << 1)
+
struct fuzzy_cmd_io {
guint32 tag;
- gboolean replied;
+ guint32 flags;
struct iovec io;
};
rspamd_cryptobox_hash_final (&st, cmd->digest);
io = rspamd_mempool_alloc (pool, sizeof (*io));
- io->replied = FALSE;
+ io->flags = 0;
io->tag = cmd->tag;
if (rule->peer_key) {
io = rspamd_mempool_alloc (pool, sizeof (*io));
io->tag = shcmd->basic.tag;
- io->replied = FALSE;
+ io->flags = 0;
if (rule->peer_key) {
g_assert (encshcmd != NULL);
rspamd_cryptobox_hash_final (&st, cmd->digest);
io = rspamd_mempool_alloc (pool, sizeof (*io));
- io->replied = FALSE;
+ io->flags = 0;
io->tag = cmd->tag;
if (rule->peer_key) {
fuzzy_cmd_vector_to_wire (gint fd, GPtrArray *v)
{
guint i;
+ gboolean all_sent = TRUE, all_replied = TRUE;
struct fuzzy_cmd_io *io;
gboolean processed = FALSE;
+ /* First try to resend unsent commands */
for (i = 0; i < v->len; i ++) {
io = g_ptr_array_index (v, i);
- if (!io->replied) {
+ if (io->flags & FUZZY_CMD_FLAG_REPLIED) {
+ continue;
+ }
+
+ all_replied = FALSE;
+
+ if (!(io->flags & FUZZY_CMD_FLAG_SENT)) {
if (!fuzzy_cmd_to_wire (fd, &io->io)) {
return FALSE;
}
processed = TRUE;
+ io->flags |= FUZZY_CMD_FLAG_SENT;
+ all_sent = FALSE;
}
}
+ if (all_sent && !all_replied) {
+ /* Now try to resend each command in the vector */
+ for (i = 0; i < v->len; i++) {
+ io = g_ptr_array_index (v, i);
+
+ if (!(io->flags & FUZZY_CMD_FLAG_REPLIED)) {
+ io->flags &= ~FUZZY_CMD_FLAG_SENT;
+ }
+ }
+
+ return fuzzy_cmd_vector_to_wire (fd, v);
+ }
+
return processed;
}
io = g_ptr_array_index (req, i);
if (io->tag == rep->tag) {
- if (!io->replied) {
- io->replied = TRUE;
+ if (!(io->flags & FUZZY_CMD_FLAG_REPLIED)) {
+ io->flags |= FUZZY_CMD_FLAG_REPLIED;
return rep;
}
for (i = 0; i < session->commands->len; i++) {
io = g_ptr_array_index (session->commands, i);
- if (io->replied) {
+ if (io->flags & FUZZY_CMD_FLAG_REPLIED) {
nreplied++;
}
}