synchronous/blocking mode is not really supported
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
mosquitto |
New
|
Undecided
|
Unassigned |
Bug Description
It seems that blocking mode is not really supported.
Topology: publisher -- broker -- subscriber
Publisher simply publish a message then exit.
Subscriber sometimes can receive message published by publisher, but sometimes not.
The root cause is, libmosquitto does not really support blocking mode.
mosquitto_
That means mosquitto_
Logs can prove that:
----
1387273535: New connection from 172.18.111.243 on port 1883.
1387273535: New client connected from 172.18.111.243 as TestClientId (c1, k3600).
1387273535: Sending CONNACK to TestClientId (0)
1387273535: Socket error on client TestClientId, disconnecting.
----
We can see:
1) Broker has not received PUBLISH message from publisher.
2) Broker has not received DISCONNECT message from publisher.
All because blocking mode is not really supported.
In blocking mode,
mosquitto_
If QoS not 0, mosquitto_publish should wait unit ...
mosquitto_subscribe should wait unit ...
...
Here is code of the publisher:
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "mosquitto.h"
#define dbg(fmt, args...) \
printf("%s(%u): "fmt"\n", __FUNCTION__, __LINE__, ##args)
int main(int argc, char *argv[])
{
struct mosquitto *mosq = NULL;
int rv;
const char topic[] = "TestTopic";
const char buf[] = "Hello, world";
if (MOSQ_ERR_SUCCESS != mosquitto_
return -1;
}
if (NULL == (mosq = mosquitto_
rv = -1;
goto quit;
}
rv = mosquitto_
if (MOSQ_ERR_SUCCESS != rv) {
if (MOSQ_ERR_ERRNO == rv) {
}
rv = -1;
goto quit;
}
if (MOSQ_ERR_SUCCESS != mosquitto_
rv = -1;
goto quit;
}
quit:
if (NULL != mosq) {
}
mosquitto_
return rv;
}
description: | updated |
summary: |
- Blocking mode is not really supported + synchronous/blocking mode is not really supported |
You are correct, the design of the library is intentionally asynchronous.
The only consideration of blocking is in the network socket interface itself, i.e. does the call to connect() block. This is blocking at the socket level not the protocol level.