Skip to content

Commit 196637e

Browse files
committed
bugfix for the issue 50 : throwing exception for protocol errors.
1 parent 0c0409a commit 196637e

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#ifndef REDIS_COMMON_H
55
#define REDIS_COMMON_H
66

7+
static zend_class_entry *redis_ce;
8+
static zend_class_entry *redis_exception_ce;
9+
static zend_class_entry *spl_ce_RuntimeException = NULL;
10+
711
#define redis_sock_name "Redis Socket Buffer"
812
#define REDIS_SOCK_STATUS_FAILED 0
913
#define REDIS_SOCK_STATUS_DISCONNECTED 1

library.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
8787
case '-':
8888
return NULL;
8989

90+
case '$':
91+
*buf_len = atoi(inbuf + 1);
92+
resp = redis_sock_read_bulk_reply(redis_sock, *buf_len TSRMLS_CC);
93+
return resp;
94+
9095
case '+':
9196
case ':':
9297
// Single Line Reply
@@ -97,18 +102,15 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
97102
memcpy(resp, inbuf, *buf_len);
98103
resp[*buf_len] = 0;
99104
return resp;
100-
} else {
101-
printf("protocol error \n");
102-
return NULL;
103105
}
104106

105-
case '$':
106-
*buf_len = atoi(inbuf + 1);
107-
resp = redis_sock_read_bulk_reply(redis_sock, *buf_len TSRMLS_CC);
108-
return resp;
109-
110107
default:
111-
printf("protocol error, got '%c' as reply type byte\n", inbuf[0]);
108+
zend_throw_exception_ex(
109+
redis_exception_ce,
110+
0 TSRMLS_CC,
111+
"protocol error, got '%c' as reply type byte\n",
112+
inbuf[0]
113+
);
112114
}
113115

114116
return NULL;

redis.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535

3636
static int le_redis_sock;
3737

38-
static zend_class_entry *redis_ce;
39-
static zend_class_entry *redis_exception_ce;
40-
static zend_class_entry *spl_ce_RuntimeException = NULL;
4138

4239

4340
ZEND_DECLARE_MODULE_GLOBALS(redis)

0 commit comments

Comments
 (0)