|
1 | 1 | /*-
|
2 | 2 | * Copyright (C) 2014 Pietro Cerutti <[email protected]>
|
3 |
| - * |
| 3 | + * |
4 | 4 | * Redistribution and use in source and binary forms, with or without
|
5 | 5 | * modification, are permitted provided that the following conditions
|
6 | 6 | * are met:
|
|
9 | 9 | * 2. Redistributions in binary form must reproduce the above copyright
|
10 | 10 | * notice, this list of conditions and the following disclaimer in the
|
11 | 11 | * documentation and/or other materials provided with the distribution.
|
12 |
| - * |
| 12 | + * |
13 | 13 | * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
14 | 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15 | 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -69,19 +69,27 @@ class RedisQtAdapter : public QObject {
|
69 | 69 | }
|
70 | 70 |
|
71 | 71 | public:
|
72 |
| - RedisQtAdapter(QObject * parent = 0) |
| 72 | + RedisQtAdapter(QObject * parent = 0) |
73 | 73 | : QObject(parent), m_ctx(0), m_read(0), m_write(0) { }
|
74 | 74 |
|
75 |
| - ~RedisQtAdapter() { } |
| 75 | + ~RedisQtAdapter() { |
| 76 | + if (m_ctx != 0) { |
| 77 | + m_ctx->ev.data = NULL; |
| 78 | + } |
| 79 | + } |
76 | 80 |
|
77 |
| - void setContext(redisAsyncContext * ac) { |
| 81 | + int setContext(redisAsyncContext * ac) { |
| 82 | + if (ac->ev.data != NULL) { |
| 83 | + return REDIS_ERR; |
| 84 | + } |
78 | 85 | m_ctx = ac;
|
79 | 86 | m_ctx->ev.data = this;
|
80 | 87 | m_ctx->ev.addRead = RedisQtAddRead;
|
81 | 88 | m_ctx->ev.delRead = RedisQtDelRead;
|
82 | 89 | m_ctx->ev.addWrite = RedisQtAddWrite;
|
83 | 90 | m_ctx->ev.delWrite = RedisQtDelWrite;
|
84 | 91 | m_ctx->ev.cleanup = RedisQtCleanup;
|
| 92 | + return REDIS_OK; |
85 | 93 | }
|
86 | 94 |
|
87 | 95 | private:
|
|
0 commit comments