Skip to content

Commit

Permalink
[CHG] 增加日志打印,修改网络字节序的转换,屏蔽gateway收到反馈后的主动关闭代码
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjluoning committed Apr 21, 2015
1 parent 6495d0e commit 394620e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
13 changes: 6 additions & 7 deletions server/src/push_server/apns_client_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ void CAPNSClientHandler::OnClose(uint32_t nsockid)
if (pClient)
{
pClient->StartReConnectGateway();
//暂时不进行feedback的链接,由于sslconnect是阻塞的,会导致ioloop卡住
//pClient->StartReConnectFeedback();
pClient->StartReConnectFeedback();
}
}

Expand Down Expand Up @@ -51,11 +50,11 @@ void CAPNSClientHandler::OnRecvData(const char* szBuf, int32_t nBufSize)
if (msg.ParseFromArray(m_Msg.Data(), m_Msg.GetResMsgLength()))
{
PUSH_SERVER_INFO("apns gateway client recv resp, cmd id: %u, status: %u, notification id: %u", (uint32_t)msg.GetCommandID(), (uint32_t)msg.GetStatus(), msg.GetNotificationID());
apns_client_ptr pClient = CSessionManager::GetInstance()->GetAPNSClient();
if (pClient)
{
pClient->StopGateWayClient();
}
//apns_client_ptr pClient = CSessionManager::GetInstance()->GetAPNSClient();
//if (pClient)
//{
// pClient->StopGateWayClient();
//}
}
else
{
Expand Down
20 changes: 16 additions & 4 deletions server/src/push_server/apns_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ BOOL CAPNSGateWayMsg::SerializeToArray()
BOOL bRet = FALSE;
if (m_databuffer.GetWriteOffset() != 0)
{
PUSH_SERVER_WARN("push msg serialize failed, databuffer offset: %d.", m_databuffer.GetWriteOffset());
return bRet;
}
if (m_strDeviceToken.length() != APNS_DEVICE_TOKEN_HEX_LENGTH )
{
PUSH_SERVER_WARN("push msg serialize failed, device token length: %d, token: %s.", m_strDeviceToken.length(), m_strDeviceToken.c_str());
return bRet;
}

string strPayload = _BuildPayload();
if (strPayload.length() > APNS_PAY_LOAD_MAX_LENGTH || strPayload.length() == 0)
{
PUSH_SERVER_WARN("push msg serialize failed, payload length: %d.", strPayload.length());
return bRet;
}

Expand Down Expand Up @@ -81,15 +84,15 @@ BOOL CAPNSGateWayMsg::SerializeToArray()
//notification ID
nItemID = APNS_ITEM_NOTIFICATION_ID;
nItemDataLength = htons(sizeof(m_nNotificationID));
int32_t nNotificationID = htons(m_nNotificationID);
int32_t nNotificationID = htonl(m_nNotificationID);
m_databuffer.Write((const char*)&nItemID, sizeof(nItemID));
m_databuffer.Write((const char*)&nItemDataLength, sizeof(nItemDataLength));
m_databuffer.Write((const char*)&nNotificationID, sizeof(nNotificationID));

//expiration date
nItemID = APNS_ITEM_EXPIRATION_DATE;
nItemDataLength = htons(sizeof(m_nExpirationDate));
int32_t nExpirationDate = htons(m_nExpirationDate);
int32_t nExpirationDate = htonl(m_nExpirationDate);
m_databuffer.Write((const char*)&nItemID, sizeof(nItemID));
m_databuffer.Write((const char*)&nItemDataLength, sizeof(nItemDataLength));
m_databuffer.Write((const char*)&nExpirationDate, sizeof(nExpirationDate));
Expand Down Expand Up @@ -185,7 +188,7 @@ CAPNSGateWayResMsg::~CAPNSGateWayResMsg()
BOOL CAPNSGateWayResMsg::CheckMsgAvailable()
{
BOOL bRet = FALSE;
if (m_databuffer.GetWriteOffset() > GetDataLength())
if (m_databuffer.GetWriteOffset() >= GetDataLength())
{
bRet = TRUE;
}
Expand Down Expand Up @@ -227,10 +230,14 @@ CAPNSFeedBackResMsg::~CAPNSFeedBackResMsg()
BOOL CAPNSFeedBackResMsg::CheckMsgAvailable()
{
BOOL bRet = FALSE;
if (m_databuffer.GetWriteOffset() > GetDataLength())
if (m_databuffer.GetWriteOffset() >= GetDataLength())
{
bRet = TRUE;
}
else
{
PUSH_SERVER_INFO("CheckMsgAvailable error.");
}
return bRet;
}

Expand All @@ -239,6 +246,7 @@ BOOL CAPNSFeedBackResMsg::ParseFromArray(const char *buf, uint32_t len)
BOOL bRet = FALSE;
if (m_databuffer.GetWriteOffset() != 0)
{
PUSH_SERVER_INFO("ParseFromArray error, GetWriteOffset.");
return bRet;
}
Append(buf, len);
Expand All @@ -260,5 +268,9 @@ BOOL CAPNSFeedBackResMsg::ParseFromArray(const char *buf, uint32_t len)
m_Token = device_token;
bRet = TRUE;
}
else
{
PUSH_SERVER_INFO("CheckMsgAvailable error 2.0");
}
return bRet;
}

0 comments on commit 394620e

Please sign in to comment.