TRACE();
afb_wsj1_unref(wsj1);
sd_event_unref(loop);
- loop = nullptr;
}
int AFBClient::Impl::init(int port, char const *token) {
char *uribuf = nullptr;
int rc = -1;
+ if (this->loop != nullptr && this->wsj1 != nullptr) {
+ fputs("AFBClient instance is already initialized!\n", stderr);
+ rc = -EALREADY;
+ goto fail;
+ }
+
if ((token == nullptr) || strlen(token) > token_maxlen) {
fprintf(stderr, "Token is invalid\n");
rc = -EINVAL;
wsj1 = afb_ws_client_connect_wsj1(
loop, uribuf, const_cast<struct afb_wsj1_itf *>(&itf), this);
if (wsj1 == nullptr) {
- sd_event_unref(loop);
+ sd_event_unref(this->loop);
+ this->loop = nullptr;
fprintf(stderr, "Connection to %s failed: %m\n", uribuf);
rc = -errno;
goto fail;