update sproto to support empty request

This commit is contained in:
Cloud Wu
2014-09-07 18:44:04 +08:00
parent db9ab88a6c
commit 01269c88ff
5 changed files with 51 additions and 34 deletions

View File

@@ -422,14 +422,16 @@ lprotocol(lua_State *L) {
}
struct sproto_type * request = sproto_protoquery(sp, tag, SPROTO_REQUEST);
if (request == NULL) {
return 0;
lua_pushnil(L);
} else {
lua_pushlightuserdata(L, request);
}
lua_pushlightuserdata(L, request);
struct sproto_type * response = sproto_protoquery(sp, tag, SPROTO_RESPONSE);
if (response == NULL) {
return 2;
lua_pushnil(L);
} else {
lua_pushlightuserdata(L, response);
}
lua_pushlightuserdata(L, response);
return 3;
}

View File

@@ -329,10 +329,13 @@ import_protocol(struct sproto *s, struct protocol *p, const uint8_t * stream) {
p->p[SPROTO_REQUEST] = NULL;
p->p[SPROTO_RESPONSE] = NULL;
int i;
for (i=0;i<fn;i++) {
int tag = 0;
for (i=0;i<fn;i++,tag++) {
int value = toword(stream + SIZEOF_FIELD * i);
if (value & 1)
return NULL;
if (value & 1) {
tag += (value-1)/2;
continue;
}
value = value/2 - 1;
switch (i) {
case 0: // name
@@ -362,7 +365,7 @@ import_protocol(struct sproto *s, struct protocol *p, const uint8_t * stream) {
}
}
if (p->name == NULL || p->tag<0 || p->p[SPROTO_REQUEST] == NULL) {
if (p->name == NULL || p->tag<0) {
return NULL;
}