aboutsummaryrefslogtreecommitdiffstats
path: root/man/psmq_ioctl_reply_timeout.3
blob: cda8ec74b954ff6d325c3d707fc77187aef98ef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
.TH "psmq_ioctl_reply_timeout" "3" "19 May 2021 (v0.2.0)" "bofc.pl"
.SH NAME
.PP
.B psmq_ioctl_reply_timeout
- Sets time in ms, how long broker will wait for
.I psmq
queue until it starts dropping messages in case queue is full.
.SH SYNOPSIS
.PP
.BI "#include <psmq.h>"
.PP
.BI "int psmq_ioctl_reply_timeout(struct psmq *" psmq ", unsigned short " val ")"
.SH DESCRIPTION
.PP
When clients queue is full and broker is about to put a message on it, such
message will be dropped immediately without hesitation.
If you expect that incoming data will be received faster than you can
process it, you can set how long broker shall wait for you to free up
space on your queue.
This time is specified in milliseconds.
.PP
Be advised though!
If you set this to high value, broker will be stuck waiting for your client,
other messages will not be processed by broker util it can deliver message
for you!
This can lead to situations where other clients won't be able to send data
to broker as its queue can get full too when messages are not being processed.
.SH "BROKER RESPONSE"
.PP
Response frame is
.PP
.nf
    0     1         3
    +-----+---------+
    | req | timeout |
    +-----+---------+
.fi
.TP
.I req
This will always be
.BR PSMQ_CTRL_CMD_IOCTL .
.TP
.I timeout
timeout set in broker stored as unsigned short.
.SH "RETURN VALUE"
.PP
Library function will return 0 on success and -1 on errors.
On broker side this ioctl cannot fail,
msg.data[0] will have PSMQ_IOCTL_REPLY_TIMEOUT value and
msg.data[1:2] will contain set timeout.
.SH ERRORS
.TP
.B EINVAL
.I psmq
is
.B NULL
or
.I val
is bigger than 65535.
.TP
.B EBADF
.I psmq
has not yet been initialized
.SH EXAMPLE
Set reply timeout.
.PP
.nf
    #include <psmq.h>

    static int on_receive(struct psmq_msg *msg, char *topic,
            unsigned char *payload, unsigned short paylen)
    {
        unsigned short timeout;

        switch (msg->ctrl.cmd)
        {
        case PSMQ_CTRL_CMD_IOCTL:
            /* payload[0] contains IOCTL number used in request,
             * so you can perform different actions depending
             * on response for different IOCTL */
            switch (payload[0])
            {
            case PSMQ_IOCTL_REPLY_TIMEOUT:
                memcpy(&timeout, payload + 1, sizeof(timeout));
                fprintf(stder, "timeout set to %hu\\n", timeout);
                return 0;
            }
        }
    }

    int main(void)
    {
        struct psmq psmq;
        struct psmq_msg msg;

        /* initialize psmq object that will create /sub mqueue for
         * receiving data, and will connect to broker of name /brok.
         * Max items in queue is set to 10 */
        psmq_init(&psmq, "/brok", "/sub", 10);

        /* set reply timeout with psmq_ioctl() function */
        psmq_ioctl(&psmq, PSMQ_IOCTL_REPLY_TIMEOUT, 100);

        /* every ioctl can also be called with dedicated function */
        /* psmq_ioctl_reply_timeout(&psmq, 100); */

        /* we will receive reply from broker for each ioctl sent */
        psmq_receive(&psmq, &msg, NULL);
        on_receive(&msg, PSMQ_TOPIC(msg), PSMQ_PAYLOAD(msg), msg.paylen);

        /* after work is finished, we need to deregister from broker to
         * make space in broker for another client */
        psmq_cleanup(&psmq);
        return 0;
    }
.fi
.SH "BUG REPORTING"
.PP
Please, report all bugs to "Michał Łyszczek <michal.lyszczek@bofc.pl>"
.SH "SEE ALSO"
.PP
.BR psmqd (1),
.BR psmq-pub (1),
.BR psmq-sub (1),
.BR psmq_cleanup (3),
.BR psmq_init (3),
.BR psmq_publish (3),
.BR psmq_receive (3),
.BR psmq_subscribe (3),
.BR psmq_timedreceive (3),
.BR psmq_timedreceive_ms (3),
.BR psmq_unsubscribe (3),
.BR psmq_building (7),
.BR psmq_overview (7).