diff --git a/plugins/emperor_amqp/amqp.c b/plugins/emperor_amqp/amqp.c index 28357d86..3f7ff7b6 100644 --- a/plugins/emperor_amqp/amqp.c +++ b/plugins/emperor_amqp/amqp.c @@ -73,26 +73,29 @@ static int amqp_send_ack(int fd, uint64_t delivery_tag) { uint32_t size = 4 + 8 + 1; - size = htonl(size); + struct uwsgi_buffer *ub = uwsgi_buffer_new(64); // send type and channel - amqp_send(fd, "\1\0\1", 3); + if (uwsgi_buffer_append(ub, "\1\0\1", 3)) goto end; // send size - amqp_send(fd, &size, 4); - - // send class 60 method 80 - amqp_send(fd, "\x00\x3C\x00\x50", 4); - + if (uwsgi_buffer_u32be(ub, size)) goto end; + // send class 60 method 80 + if (uwsgi_buffer_append(ub, "\x00\x3C\x00\x50", 4)) goto end; // set delivery_tag - delivery_tag = htonll(delivery_tag); - amqp_send(fd, &delivery_tag, 8); + if (uwsgi_buffer_u64be(ub, delivery_tag)) goto end; + if (uwsgi_buffer_append(ub, "\0\xCE", 2)) goto end; - // empty bits - amqp_send(fd, "\0", 1); + // send buffer to socket + if (write(fd, ub->buf, ub->pos) < 0) { + uwsgi_error("amqp_send_ack()/write()"); + goto end; + } - // send frame-end - amqp_send(fd, "\xCE", 1); + uwsgi_buffer_destroy(ub); return 0; +end: + uwsgi_buffer_destroy(ub); + return -1; } char *uwsgi_amqp_consume(int fd, uint64_t *msgsize, char **routing_key) {