diff options
Diffstat (limited to 'AFBClient.cpp')
-rw-r--r-- | AFBClient.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/AFBClient.cpp b/AFBClient.cpp index 5ffad29..497b746 100644 --- a/AFBClient.cpp +++ b/AFBClient.cpp @@ -206,7 +206,6 @@ AFBClient::Impl::~Impl() { TRACE(); afb_wsj1_unref(wsj1); sd_event_unref(loop); - loop = nullptr; } int AFBClient::Impl::init(int port, char const *token) { @@ -214,6 +213,12 @@ 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; @@ -248,7 +253,8 @@ int AFBClient::Impl::init(int port, char const *token) { 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; |