|
回复 #131 yulihua49 的帖子
这是客户端程序
- #include <unistd.h>
- #include <sccli.h>
- #include <pack.h>
- #include <json_pack.h>
- int test_page(T_Connect *conn,T_NetHead *head)
- {
- int ret;
- JSON_OBJECT json,cmd;
- char *p;
- T_CLI_Var *clip=(T_CLI_Var *)conn->Var;
- INT64 now;
- cmd=json_object_new_object();
- add_string_to_json(cmd,"tablename","TI_CITY");
- add_string_to_json(cmd,"where","WHERE DAIL_AREA_CODE=:DAIL_AREA_CODE AND CITY_STOP_DATE >= :CITY_STOP_DATE");
- add_string_to_json(cmd,"page_size","10");
- add_string_to_json(cmd,"page_idx","1");
- json=json_object_new_object();
- add_string_to_json(json,"DAIL_AREA_CODE","0350");
- add_string_to_json(json,"CITY_STOP_DATE","20110909");
- json_object_object_add(cmd,"values",json);
- p=(char *)json_object_to_json_string(cmd);
- if(isatty(0)) printf("cmd=%s\n",p);
- head->PROTO_NUM=get_srv_no(clip,"page_proc");//如果是我的程序,就"page_select"
- if(head->PROTO_NUM==1) {
- json_object_put(cmd);
- ShowLog(1,"%s:no such svc 'page_select'",__FUNCTION__);
- return -1;
- }
- head->data=p;
- head->PKG_LEN=strlen(head->data);
- head->ERRNO1=head->ERRNO2=head->PKG_REC_NUM=head->D_NODE=0;
- head->O_NODE=LocalAddr(conn->Socket,NULL);
- now=now_usec();
- ret=SendPack(conn,head);
- json_object_put(cmd);
- ret=RecvPack(conn,head);
- if(ret) {
- ShowLog(1,"%s:net err=%d,%s",__FUNCTION__,errno,strerror(errno));
- return -1;
- }
- if(head->ERRNO1 || head->ERRNO2) {
- ShowLog(1,"%s:recv ERRNO=%d,%d",__FUNCTION__,head->ERRNO1,head->ERRNO2);
- return -1;
- }
- ShowLog(2,"%s:svc succeed TIMEVAL=%d",__FUNCTION__,(int)(now_usec() - now));
- if(isatty(0)) printf("data=%s\n",head->data);
- return 0;
- }
复制代码
[ 本帖最后由 yulihua49 于 2011-9-9 17:48 编辑 ] |
|