Skip to content

Commit

Permalink
Make sure to disconnect the adapter in the destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
gahr authored and badboy committed Jul 27, 2015
1 parent 9069b14 commit 4a632a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions adapters/qt.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* Copyright (C) 2014 Pietro Cerutti <[email protected]>
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
Expand All @@ -9,7 +9,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Expand Down Expand Up @@ -69,19 +69,27 @@ class RedisQtAdapter : public QObject {
}

public:
RedisQtAdapter(QObject * parent = 0)
RedisQtAdapter(QObject * parent = 0)
: QObject(parent), m_ctx(0), m_read(0), m_write(0) { }

~RedisQtAdapter() { }
~RedisQtAdapter() {
if (m_ctx != 0) {
m_ctx->ev.data = NULL;
}
}

void setContext(redisAsyncContext * ac) {
int setContext(redisAsyncContext * ac) {
if (ac->ev.data != NULL) {
return REDIS_ERR;
}
m_ctx = ac;
m_ctx->ev.data = this;
m_ctx->ev.addRead = RedisQtAddRead;
m_ctx->ev.delRead = RedisQtDelRead;
m_ctx->ev.addWrite = RedisQtAddWrite;
m_ctx->ev.delWrite = RedisQtDelWrite;
m_ctx->ev.cleanup = RedisQtCleanup;
return REDIS_OK;
}

private:
Expand Down
2 changes: 1 addition & 1 deletion examples/example-qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ExampleQt : public QObject {

signals:
void finished();

public slots:
void run();

Expand Down

0 comments on commit 4a632a6

Please sign in to comment.