Skip to content

Commit

Permalink
build sample succ
Browse files Browse the repository at this point in the history
  • Loading branch information
garryyan committed May 27, 2017
1 parent 3270f44 commit 0051d3c
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 95 deletions.
13 changes: 8 additions & 5 deletions mars/comm/comm-mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
4B0280921DE7037B001721C0 /* nat64_prefix_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4B02808B1DE7037B001721C0 /* nat64_prefix_util.cc */; };
4B0280931DE7037B001721C0 /* unix_socket.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4B02808E1DE7037B001721C0 /* unix_socket.cc */; };
4B299C011CEF0AEA00E2315B /* boost_exception.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4B299C001CEF0AEA00E2315B /* boost_exception.cc */; };
4B315DA51ED81F680005F132 /* socketselect.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4BB712511DE8149B00185734 /* socketselect.cc */; };
4B3C3E0A1E120D9400351897 /* netinfo_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4B3C3E081E120D9400351897 /* netinfo_util.cc */; };
4B3C3E211E1210A100351897 /* complexconnect.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4B3C3E201E1210A100351897 /* complexconnect.cc */; };
4BA235641E5AB6E1002B769D /* socketbreaker.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4BA2355E1E5AB6E1002B769D /* socketbreaker.cc */; };
4BA235651E5AB6E1002B769D /* socketpoll.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4BA235601E5AB6E1002B769D /* socketpoll.cc */; };
4BB712531DE8149B00185734 /* socketselect.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4BB712511DE8149B00185734 /* socketselect.cc */; };
4BB712F71DE8229A00185734 /* loginfo_extract.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BB712F51DE8229A00185734 /* loginfo_extract.c */; };
55D917841CC7BD7A0076CBD9 /* message_queue.cc in Sources */ = {isa = PBXBuildFile; fileRef = 55D9093D1CC7BD760076CBD9 /* message_queue.cc */; };
55D918241CC7BD7A0076CBD9 /* mmap_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = 55D90A141CC7BD770076CBD9 /* mmap_util.cc */; };
Expand Down Expand Up @@ -139,6 +139,8 @@
4B02808C1DE7037B001721C0 /* nat64_prefix_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nat64_prefix_util.h; sourceTree = "<group>"; };
4B02808E1DE7037B001721C0 /* unix_socket.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unix_socket.cc; sourceTree = "<group>"; };
4B299C001CEF0AEA00E2315B /* boost_exception.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = boost_exception.cc; sourceTree = "<group>"; };
4B315D941ED81DB30005F132 /* socketbreaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = socketbreaker.h; sourceTree = "<group>"; };
4B315D951ED81DB30005F132 /* socketpoll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = socketpoll.h; sourceTree = "<group>"; };
4B3C3E081E120D9400351897 /* netinfo_util.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = netinfo_util.cc; sourceTree = "<group>"; };
4B3C3E091E120D9400351897 /* netinfo_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netinfo_util.h; sourceTree = "<group>"; };
4B3C3E201E1210A100351897 /* complexconnect.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = complexconnect.cc; sourceTree = "<group>"; };
Expand Down Expand Up @@ -568,7 +570,7 @@
);
sourceTree = "<group>";
};
4BB712501DE8149B00185734 /* SocketSelect */ = {
4BB712501DE8149B00185734 /* socket */ = {
isa = PBXGroup;
children = (
4BA2355E1E5AB6E1002B769D /* socketbreaker.cc */,
Expand Down Expand Up @@ -606,6 +608,8 @@
55D90A151CC7BD770076CBD9 /* socket */ = {
isa = PBXGroup;
children = (
4B315D941ED81DB30005F132 /* socketbreaker.h */,
4B315D951ED81DB30005F132 /* socketpoll.h */,
4B3C3E201E1210A100351897 /* complexconnect.cc */,
4B0280891DE7037B001721C0 /* getsocktcpinfo.cc */,
4B02808A1DE7037B001721C0 /* getsocktcpinfo.h */,
Expand Down Expand Up @@ -768,7 +772,7 @@
55D90B0A1CC7BD770076CBD9 /* unix */ = {
isa = PBXGroup;
children = (
4BB712501DE8149B00185734 /* SocketSelect */,
4BB712501DE8149B00185734 /* socket */,
55D90B0E1CC7BD770076CBD9 /* thread */,
);
path = unix;
Expand Down Expand Up @@ -848,9 +852,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4B315DA51ED81F680005F132 /* socketselect.cc in Sources */,
1F25BFCD1CD37AF500AC1003 /* lockpool.cpp in Sources */,
1F25BFCE1CD37AF500AC1003 /* date_generators.cpp in Sources */,
4BA235661E5AB6E1002B769D /* socketselect.cc in Sources */,
1F25BFCF1CD37AF500AC1003 /* greg_month.cpp in Sources */,
1F25BFD01CD37AF500AC1003 /* greg_names.hpp in Sources */,
1F25BFD11CD37AF500AC1003 /* greg_weekday.cpp in Sources */,
Expand All @@ -867,7 +871,6 @@
1F25BFDB1CD37AF500AC1003 /* utf8_codecvt_facet.cpp in Sources */,
4B0280831DE70343001721C0 /* http.cc in Sources */,
1F25BFDC1CD37AF500AC1003 /* windows_file_codecvt.cpp in Sources */,
4B3D44411E36F11500F69213 /* socketselect.cc in Sources */,
1F25BFDD1CD37AF500AC1003 /* windows_file_codecvt.hpp in Sources */,
1F25BFDE1CD37AF500AC1003 /* file_descriptor.cpp in Sources */,
1F25BFDF1CD37AF500AC1003 /* mapped_file.cpp in Sources */,
Expand Down
33 changes: 19 additions & 14 deletions samples/Mac/PublicComponentV2/log_crypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <stdio.h>

static const char kMagicSyncStart = '\x03';
static const char kMagicAsyncStart ='\x05';
Expand Down Expand Up @@ -284,15 +285,17 @@ bool LogCrypt::GetPeriodLogs(const char* const _log_path, int _begin_hour, int _
}


void LogCrypt::CryptSyncLog(const char* const _log_data, size_t _input_len, char* _output, size_t& _output_len) {
uint16_t seq = __GetSeq(false);
uint32_t len = std::min(_input_len, _output_len - GetHeaderLen() - GetTailerLen());
void LogCrypt::CryptSyncLog(const char* const _log_data, size_t _input_len, AutoBuffer& _out_buff) {
_out_buff.AllocWrite(GetHeaderLen() + GetTailerLen() + _input_len);

memcpy(_output + GetHeaderLen(), _log_data, len);
_output[GetHeaderLen() + len] = kMagicEnd;
_output[0] = kMagicSyncStart;
uint16_t seq = __GetSeq(false);
uint32_t len = _input_len;

memcpy(_output + 1, &seq, sizeof(seq));
memcpy((char*)_out_buff.Ptr() + GetHeaderLen(), _log_data, len);
((char*)_out_buff.Ptr())[GetHeaderLen() + len] = kMagicEnd;
((char*)_out_buff.Ptr())[0] = kMagicSyncStart;

memcpy((char*)_out_buff.Ptr() + 1, &seq, sizeof(seq));

struct timeval tv;
gettimeofday(&tv, 0);
Expand All @@ -301,16 +304,18 @@ void LogCrypt::CryptSyncLog(const char* const _log_data, size_t _input_len, char

char hour = (char)tm_tmp.tm_hour;

memcpy(_output+3, &hour, sizeof(hour));
memcpy(_output+4, &hour, sizeof(hour));
memcpy(_output+5, &len, sizeof(len));
memcpy((char*)_out_buff.Ptr()+3, &hour, sizeof(hour));
memcpy((char*)_out_buff.Ptr()+4, &hour, sizeof(hour));
memcpy((char*)_out_buff.Ptr()+5, &len, sizeof(len));

_output_len = GetHeaderLen() + GetTailerLen() + len;
_out_buff.Length(GetHeaderLen() + GetTailerLen() + _input_len, GetHeaderLen() + GetTailerLen() + _input_len);
}

void LogCrypt::CryptAsyncLog(const char* const _log_data, size_t _input_len, char* _output, size_t& _output_len) {
_output_len = std::min(_input_len, _output_len);
memcpy(_output, _log_data, _output_len);
void LogCrypt::CryptAsyncLog(const char* const _log_data, size_t _input_len, AutoBuffer& _out_buff) {
_out_buff.AllocWrite(_input_len);

memcpy(_out_buff.Ptr(), _log_data, _input_len);
_out_buff.Length(_input_len, _input_len);
}

bool LogCrypt::Fix(char* _data, size_t _data_len, bool& _is_async, uint32_t& _raw_log_len) {
Expand Down
7 changes: 5 additions & 2 deletions samples/Mac/PublicComponentV2/log_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <stdint.h>
#include <string>

#include "mars/comm/autobuffer.h"


class LogCrypt {
public:
LogCrypt(): seq_(0) {}
Expand All @@ -48,8 +51,8 @@ class LogCrypt {

bool GetPeriodLogs(const char* const _log_path, int _begin_hour, int _end_hour, unsigned long& _begin_pos, unsigned long& _end_pos, std::string& _err_msg);

void CryptSyncLog(const char* const _log_data, size_t _input_len, char* _output, size_t& _output_len);
void CryptAsyncLog(const char* const _log_data, size_t _input_len, char* _output, size_t& _output_len);
void CryptSyncLog(const char* const _log_data, size_t _input_len, AutoBuffer& _out_buff);
void CryptAsyncLog(const char* const _log_data, size_t _input_len, AutoBuffer& _out_buff);

bool Fix(char* _data, size_t _data_len, bool& _is_async, uint32_t& _raw_log_len);

Expand Down
38 changes: 19 additions & 19 deletions samples/Mac/PublicComponentV2/longlink_packer.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Tencent is pleased to support the open source community by making Mars available.
// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.

// Licensed under the MIT License (the "License"); you may not use this file except in
// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://opensource.org/licenses/MIT

Expand Down Expand Up @@ -43,12 +43,12 @@ struct __STNetMsgXpHeader {
#pragma pack(pop)

namespace mars {
namespace stn {
namespace stn {
longlink_tracker* (*longlink_tracker::Create)()
= []() {
return new longlink_tracker;
};

void SetClientVersion(uint32_t _client_version) {
sg_client_version = _client_version;
}
Expand All @@ -69,13 +69,13 @@ static int __unpack_test(const void* _packed, size_t _packed_len, uint32_t& _cmd
if (client_version != sg_client_version) {
_package_len = 0;
_body_len = 0;
return LONGLINK_UNPACK_FALSE;
return LONGLINK_UNPACK_FALSE;
}
_cmdid = ntohl(st.cmdid);
_seq = ntohl(st.seq);
_body_len = ntohl(st.body_length);
_package_len = head_len + _body_len;
_seq = ntohl(st.seq);
_body_len = ntohl(st.body_length);
_package_len = head_len + _body_len;

if (_package_len > 1024*1024) { return LONGLINK_UNPACK_FALSE; }
if (_package_len > _packed_len) { return LONGLINK_UNPACK_CONTINUE; }

Expand All @@ -90,7 +90,7 @@ void (*longlink_pack)(uint32_t _cmdid, uint32_t _seq, const AutoBuffer& _body, c
st.cmdid = htonl(_cmdid);
st.seq = htonl(_seq);
st.body_length = htonl(_body.Length());

_packed.AllocWrite(sizeof(__STNetMsgXpHeader) + _body.Length());
_packed.Write(&st, sizeof(st));

Expand All @@ -102,21 +102,21 @@ void (*longlink_pack)(uint32_t _cmdid, uint32_t _seq, const AutoBuffer& _body, c

int (*longlink_unpack)(const AutoBuffer& _packed, uint32_t& _cmdid, uint32_t& _seq, size_t& _package_len, AutoBuffer& _body, AutoBuffer& _extension, longlink_tracker* _tracker)
= [](const AutoBuffer& _packed, uint32_t& _cmdid, uint32_t& _seq, size_t& _package_len, AutoBuffer& _body, AutoBuffer& _extension, longlink_tracker* _tracker) {
size_t body_len = 0;
int ret = __unpack_test(_packed.Ptr(), _packed.Length(), _cmdid, _seq, _package_len, body_len);
size_t body_len = 0;
int ret = __unpack_test(_packed.Ptr(), _packed.Length(), _cmdid, _seq, _package_len, body_len);

if (LONGLINK_UNPACK_OK != ret) return ret;

_body.Write(AutoBuffer::ESeekCur, _packed.Ptr(_package_len-body_len), body_len);

return ret;
};


#define NOOP_CMDID 6
#define SIGNALKEEP_CMDID 243
#define PUSH_DATA_TASKID 0

uint32_t (*longlink_noop_cmdid)()
= []() -> uint32_t {
return NOOP_CMDID;
Expand All @@ -136,15 +136,15 @@ void (*longlink_noop_req_body)(AutoBuffer& _body, AutoBuffer& _extend)
= [](AutoBuffer& _body, AutoBuffer& _extend) {

};

void (*longlink_noop_resp_body)(const AutoBuffer& _body, const AutoBuffer& _extend)
= [](const AutoBuffer& _body, const AutoBuffer& _extend) {

};

uint32_t (*longlink_noop_interval)()
= []() -> uint32_t {
return 0;
return 0;
};

bool (*longlink_complexconnect_need_verify)()
Expand All @@ -156,11 +156,11 @@ bool (*longlink_ispush)(uint32_t _cmdid, uint32_t _taskid, const AutoBuffer& _bo
= [](uint32_t _cmdid, uint32_t _taskid, const AutoBuffer& _body, const AutoBuffer& _extend) {
return PUSH_DATA_TASKID == _taskid;
};

bool (*longlink_identify_isresp)(uint32_t _sent_seq, uint32_t _cmdid, uint32_t _recv_seq, const AutoBuffer& _body, const AutoBuffer& _extend)
= [](uint32_t _sent_seq, uint32_t _cmdid, uint32_t _recv_seq, const AutoBuffer& _body, const AutoBuffer& _extend) {
return _sent_seq == _recv_seq && 0 != _sent_seq;
};
}

}
}
10 changes: 5 additions & 5 deletions samples/Mac/PublicComponentV2/longlink_packer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Tencent is pleased to support the open source community by making Mars available.
// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.

// Licensed under the MIT License (the "License"); you may not use this file except in
// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://opensource.org/licenses/MIT

Expand All @@ -12,7 +12,7 @@


/*
* longlink_packer.cpp
* longlink_packer.h
*
* Created on: 2012-7-18
* Author: yerungui
Expand Down Expand Up @@ -40,7 +40,7 @@ class AutoBuffer;

namespace mars {
namespace stn {

class longlink_tracker {
public:
static longlink_tracker* (*Create)();
Expand Down Expand Up @@ -85,7 +85,7 @@ extern bool (*longlink_complexconnect_need_verify)();
*/
extern bool (*longlink_ispush)(uint32_t _cmdid, uint32_t _taskid, const AutoBuffer& _body, const AutoBuffer& _extend);
extern bool (*longlink_identify_isresp)(uint32_t _sent_seq, uint32_t _cmdid, uint32_t _recv_seq, const AutoBuffer& _body, const AutoBuffer& _extend);
}

}
}
#endif // STN_SRC_LONGLINKPACKER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <stdio.h>

static const char kMagicSyncStart = '\x03';
static const char kMagicAsyncStart ='\x05';
Expand Down Expand Up @@ -284,15 +285,17 @@ bool LogCrypt::GetPeriodLogs(const char* const _log_path, int _begin_hour, int _
}


void LogCrypt::CryptSyncLog(const char* const _log_data, size_t _input_len, char* _output, size_t& _output_len) {
uint16_t seq = __GetSeq(false);
uint32_t len = std::min(_input_len, _output_len - GetHeaderLen() - GetTailerLen());
void LogCrypt::CryptSyncLog(const char* const _log_data, size_t _input_len, AutoBuffer& _out_buff) {
_out_buff.AllocWrite(GetHeaderLen() + GetTailerLen() + _input_len);

memcpy(_output + GetHeaderLen(), _log_data, len);
_output[GetHeaderLen() + len] = kMagicEnd;
_output[0] = kMagicSyncStart;
uint16_t seq = __GetSeq(false);
uint32_t len = _input_len;

memcpy(_output + 1, &seq, sizeof(seq));
memcpy((char*)_out_buff.Ptr() + GetHeaderLen(), _log_data, len);
((char*)_out_buff.Ptr())[GetHeaderLen() + len] = kMagicEnd;
((char*)_out_buff.Ptr())[0] = kMagicSyncStart;

memcpy((char*)_out_buff.Ptr() + 1, &seq, sizeof(seq));

struct timeval tv;
gettimeofday(&tv, 0);
Expand All @@ -301,16 +304,18 @@ void LogCrypt::CryptSyncLog(const char* const _log_data, size_t _input_len, char

char hour = (char)tm_tmp.tm_hour;

memcpy(_output+3, &hour, sizeof(hour));
memcpy(_output+4, &hour, sizeof(hour));
memcpy(_output+5, &len, sizeof(len));
memcpy((char*)_out_buff.Ptr()+3, &hour, sizeof(hour));
memcpy((char*)_out_buff.Ptr()+4, &hour, sizeof(hour));
memcpy((char*)_out_buff.Ptr()+5, &len, sizeof(len));

_output_len = GetHeaderLen() + GetTailerLen() + len;
_out_buff.Length(GetHeaderLen() + GetTailerLen() + _input_len, GetHeaderLen() + GetTailerLen() + _input_len);
}

void LogCrypt::CryptAsyncLog(const char* const _log_data, size_t _input_len, char* _output, size_t& _output_len) {
_output_len = std::min(_input_len, _output_len);
memcpy(_output, _log_data, _output_len);
void LogCrypt::CryptAsyncLog(const char* const _log_data, size_t _input_len, AutoBuffer& _out_buff) {
_out_buff.AllocWrite(_input_len);

memcpy(_out_buff.Ptr(), _log_data, _input_len);
_out_buff.Length(_input_len, _input_len);
}

bool LogCrypt::Fix(char* _data, size_t _data_len, bool& _is_async, uint32_t& _raw_log_len) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <stdint.h>
#include <string>

#include "mars/comm/autobuffer.h"


class LogCrypt {
public:
LogCrypt(): seq_(0) {}
Expand All @@ -48,8 +51,8 @@ class LogCrypt {

bool GetPeriodLogs(const char* const _log_path, int _begin_hour, int _end_hour, unsigned long& _begin_pos, unsigned long& _end_pos, std::string& _err_msg);

void CryptSyncLog(const char* const _log_data, size_t _input_len, char* _output, size_t& _output_len);
void CryptAsyncLog(const char* const _log_data, size_t _input_len, char* _output, size_t& _output_len);
void CryptSyncLog(const char* const _log_data, size_t _input_len, AutoBuffer& _out_buff);
void CryptAsyncLog(const char* const _log_data, size_t _input_len, AutoBuffer& _out_buff);

bool Fix(char* _data, size_t _data_len, bool& _is_async, uint32_t& _raw_log_len);

Expand Down
Loading

0 comments on commit 0051d3c

Please sign in to comment.