Skip to content

Commit

Permalink
更新到最新版本
Browse files Browse the repository at this point in the history
  • Loading branch information
away authored and away committed Oct 28, 2016
1 parent 167cc00 commit 0993021
Show file tree
Hide file tree
Showing 40 changed files with 2,010 additions and 1,361 deletions.
6 changes: 3 additions & 3 deletions trunk/teaf(isgw)/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
}

ACE_INET_Addr svr_addr(atoi(argv[2]),argv[1]);
ACE_Time_Value time_out(1); //等待 1 s
ACE_Time_Value zero(0,0); //不等待 立即返回
//ACE_Time_Value time_out(1); //等待 1 s
//ACE_Time_Value zero(0,0); //不等待 立即返回
ACE_Time_Value *time_null=NULL; //会导致永久阻塞

int send_len = 0;
Expand Down Expand Up @@ -115,7 +115,7 @@ int ACE_TMAIN(int argc, ACE_TCHAR *argv[])

// 接收消息
memset(buffer, 0, sizeof(buffer));
recv_len = peer.recv(buffer, sizeof(buffer), &time_out);
recv_len = peer.recv(buffer, sizeof(buffer)); //, &time_out
if(recv_len>0)
{
ACE_DEBUG((LM_INFO, "[%D] recv_len=%d,msg is ", recv_len));
Expand Down
2 changes: 1 addition & 1 deletion trunk/teaf(isgw)/client/makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CXX=g++
CFLAGS=
INCLUDE=-I../comm/ -I./
LIBS=-static -lACE -lnsl -lm -lz -lc -ldl -lpthread -lrt
LIBS=-static -L/data/lib/lib -lACE -lnsl -lm -lz -lc -ldl -lpthread -lrt

BINARY = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
TARGET = client
Expand Down
205 changes: 103 additions & 102 deletions trunk/teaf(isgw)/comm/ibc_prot.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,105 +7,106 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
******************************************************************************/
/*******************************************************************************
* @file ibc_prot.h
*
* 此文件为内部批量处理模块需要的协议定义
* 批量处理指令通过分解之后拥有共同的 IBCRKey 通过这个来关联
* 暂时只支持 tcp 协议
*
* @author xwfang
******************************************************************************/
#ifndef _IBC_PORT_H_
#define _IBC_PORT_H_
#include "easyace_all.h"
#include "qmode_msg.h"
#include "pp_prot.h"

///内部批量处理结果 数据结构 key 部分
typedef struct stIBCRKey
{
uint32 sock_fd; //socket 的文件描述符
uint32 sock_seq; //socket的序列号,sock_fd值相同时可以用来区分
uint32 msg_seq; //消息的序列号,唯一标识一个请求
}IBCRKey;

///内部批量处理结果 数据结构 value 部分
typedef struct stIBCRValue
{
//ACE_Thread_Mutex lock; //只有获得此锁才能对此结构进行操作
uint32 time;
uint32 cmd;
uint32 uin;
uint32 total; // 总的需要处理的关联记录数
uint32 cnum; // 当前已经处理的关联记录数
uint32 snum; // 处理成功的关联记录数
uint32 msg_len; //后面的有效消息长度
uint32 sock_fd_; //以下带 _ 的这些为透传的信息
uint32 sock_seq_;
uint32 msg_seq_;
uint32 prot_;
uint32 time_;
int rflag_;
int endflag_; // 是否进行end 回调
char msg[MAX_INNER_MSG_LEN+1]; //接受到的消息体
std::list<std::string> msg_list; // 接受的消息体
uint32 msg_num; // 消息体记录数

stIBCRValue()
{
time = 0;
cmd = 0;
uin = 0;
total = 0;
cnum = 0;
snum = 0;
msg_len = 0;
sock_fd_ = 0;
sock_seq_ = 0;
msg_seq_ = 0;
prot_ = 0;
rflag_ = 0;
endflag_ = 0;
msg_num = 0;
memset(msg, 0x0, sizeof(msg));
msg_list.clear();
msg_num = 0;
}
}IBCRValue;

///内部批量处理结果 数据结构
typedef struct stIBCRMsg
{
IBCRKey key;
IBCRValue value;
}IBCRMsg;

/// IBCRKey 比较函数
class IBCR_COMP
{
public:
bool operator() (const IBCRKey& x, const IBCRKey& y) const
{
// sock_fd,sock_seq,msg_seq 相同的情况返回 false 确保作为唯一主键
if (x.sock_fd == y.sock_fd
&& x.sock_seq == y.sock_seq
&& x.msg_seq == y.msg_seq
)
{
return false;
}

if (x.msg_seq == y.msg_seq)
{
return true;
}

return x.msg_seq > y.msg_seq; // 从大到小,因为大的比较新,删除从尾部删除
}
};

///存储结果的 map
typedef map<IBCRKey, IBCRValue, IBCR_COMP> IBCR_MAP;

#endif // _IBC_PORT_H_
/*******************************************************************************
* @file ibc_prot.h
*
* 此文件为内部批量处理模块需要的协议定义
* 批量处理指令通过分解之后拥有共同的 IBCRKey 通过这个来关联
* 暂时只支持 tcp 协议
*
* @author xwfang
******************************************************************************/
#ifndef _IBC_PORT_H_
#define _IBC_PORT_H_
#include "easyace_all.h"
#include "qmode_msg.h"
#include "pp_prot.h"

///内部批量处理结果 数据结构 key 部分
typedef struct stIBCRKey
{
uint32 sock_fd; //socket 的文件描述符
uint32 sock_seq; //socket的序列号,sock_fd值相同时可以用来区分
uint32 msg_seq; //消息的序列号,唯一标识一个请求
}IBCRKey;

///内部批量处理结果 数据结构 value 部分
typedef struct stIBCRValue
{
//ACE_Thread_Mutex lock; //只有获得此锁才能对此结构进行操作
uint32 time;
uint32 cmd;
uint32 uin;
uint32 total; // 总的需要处理的关联记录数
uint32 cnum; // 当前已经处理的关联记录数
uint32 snum; // 处理成功的关联记录数
uint32 msg_len; //后面的有效消息长度
uint32 sock_fd_; //以下带 _ 的这些为透传的信息
uint32 sock_seq_;
uint32 msg_seq_;
uint32 prot_;
uint32 time_;
int rflag_;
int endflag_; // 是否进行end 回调
char msg[MAX_INNER_MSG_LEN+1]; //接受到的消息体
std::list<std::string> msg_list; // 接受的消息体
uint32 msg_num; // 消息体记录数

stIBCRValue()
{
time = 0;
cmd = 0;
uin = 0;
total = 0;
cnum = 0;
snum = 0;
msg_len = 0;
sock_fd_ = 0;
sock_seq_ = 0;
msg_seq_ = 0;
prot_ = 0;
time_ = 0;
rflag_ = 0;
endflag_ = 0;
msg_num = 0;
memset(msg, 0x0, sizeof(msg));
msg_list.clear();
msg_num = 0;
}
}IBCRValue;

///内部批量处理结果 数据结构
typedef struct stIBCRMsg
{
IBCRKey key;
IBCRValue value;
}IBCRMsg;

/// IBCRKey 比较函数
class IBCR_COMP
{
public:
bool operator() (const IBCRKey& x, const IBCRKey& y) const
{
// sock_fd,sock_seq,msg_seq 相同的情况返回 false 确保作为唯一主键
if (x.sock_fd == y.sock_fd
&& x.sock_seq == y.sock_seq
&& x.msg_seq == y.msg_seq
)
{
return false;
}

if (x.msg_seq == y.msg_seq)
{
return true;
}

return x.msg_seq > y.msg_seq; // 从大到小,因为大的比较新,删除从尾部删除
}
};

///存储结果的 map
typedef map<IBCRKey, IBCRValue, IBCR_COMP> IBCR_MAP;

#endif // _IBC_PORT_H_
3 changes: 1 addition & 2 deletions trunk/teaf(isgw)/comm/isgw_comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
******************************************************************************/
#ifndef _ISGW_COMM_H_
#define _ISGW_COMM_H_

#include "pp_prot.h"
#include "easyace_all.h"
#include "qmode_msg.h"
#include "pp_prot.h"
//#include "object_que.h"

#define ISGW_Object_Que ACE_Object_Que
Expand Down
29 changes: 27 additions & 2 deletions trunk/teaf(isgw)/comm/isgw_oper_base.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <assert.h>
#include "isgw_oper_base.h"
#include "isgw_sighdl.h"
//#define ISGW_USE_LUA

#ifdef ISGW_USE_REDIS
#include "rds_access.h"
#endif

#ifdef ISGW_USE_LUA
#include "lua_oper.h"
#endif
Expand Down Expand Up @@ -44,6 +48,9 @@ IsgwOperBase* IsgwOperBase::instance()

int IsgwOperBase::init()
{
#ifdef ISGW_USE_REDIS
RdsSvr::instance().init();
#endif
return 0;
}

Expand All @@ -62,7 +69,7 @@ int IsgwOperBase::internal_process(QModeMsg& req, char* ack, int& ack_len)
//
case CMD_TEST:
{
ACE_DEBUG((LM_INFO, "[%D] IsgwOperBase start to process CMD_TEST\n"));
ACE_DEBUG((LM_DEBUG, "[%D] IsgwOperBase start to process CMD_TEST\n"));
//
#ifdef ISGW_USE_IBC
int max = 100;
Expand Down Expand Up @@ -131,6 +138,18 @@ int IsgwOperBase::internal_process(QModeMsg& req, char* ack, int& ack_len)
return ret;
}
break;
#ifdef ISGW_USE_REDIS
case CMD_GET_REDIS:
{
string uin = "29320361";
string key = "hello";
string value;
RdsSvr::instance().get_string_val("1", uin, key, value);
snprintf(ack, MAX_INNER_MSG_LEN, "value=%s", value.c_str());
return 0;
}
break;
#endif
case CMD_SYS_LOAD_CONF:
reload_config();
break;
Expand Down Expand Up @@ -253,6 +272,8 @@ int IsgwOperBase::is_auth(QModeMsg& req, char* ack, int& ack_len)
return 0;
}

//!!! 注意,此回调函数是在主线程中调用的,
//!!! 请不要做耗时的操作,不然会影响接入性能
int IsgwOperBase::reload_config()
{
ACE_DEBUG((LM_INFO, "[%D] IsgwOperBase::reload_config\n"));
Expand All @@ -265,12 +286,16 @@ int IsgwOperBase::reload_config()
return 0;
}

//!!! 注意,此回调函数是在主线程中调用的,
//!!! 请不要做耗时的操作,不然会影响接入性能
int IsgwOperBase::time_out()
{
ACE_DEBUG((LM_DEBUG, "[%D] IsgwOperBase::time_out\n"));
return 0;
}

//!!! 注意,此回调函数是在主线程中调用的,
//!!! 请不要做耗时的操作,不然会影响接入性能
int IsgwOperBase::handle_close(int fd)
{
ACE_DEBUG((LM_DEBUG, "[%D] IsgwOperBase::handle_close,fd=%d\n",fd));
Expand Down
Loading

0 comments on commit 0993021

Please sign in to comment.