Skip to content

Commit

Permalink
优化测试程序
Browse files Browse the repository at this point in the history
  • Loading branch information
rongxi.yuan committed Dec 8, 2015
1 parent 13a08e2 commit 78bc173
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
39 changes: 20 additions & 19 deletions test/rudp_sender/rudp_sender/rudp_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
#include "rudp/rudp_interface.h"
#include "rudp/rudp_socket.h"
#include <math.h>

#define PACKET_NUM 1000
#define SEND_DELAY 5
#define PACKET_NUM 10
#define SEND_DELAY 100

RUDPConnection::RUDPConnection()
{
packet_count_ = 0;
timer_id_ = 0;
count_ = 0;
byte_count_ = 0;
stat_ = NULL;
}

Expand Down Expand Up @@ -57,13 +58,14 @@ void RUDPConnection::cancel_timer()

void RUDPConnection::heartbeat()
{
send_packet();
uint64_t cur_count = CBaseTimeValue::get_time_value().msec();
if(tick_count_ + 1000 < cur_count)
{
cout << "send packet number = " << ceil(packet_count_ * 1000.0 /(cur_count - tick_count_)) << endl;
cout << "push packet number = " << (packet_count_ * 1000 / (cur_count - tick_count_))
<< ", bandwidth = " << (byte_count_ / 1024) << "kb/s" << endl;
packet_count_ = 0;
tick_count_ = cur_count;
byte_count_ = 0;
}
}

Expand All @@ -75,17 +77,15 @@ void RUDPConnection::send_packet()
packet.user_id = count_;
packet.ts = CBaseTimeValue::get_time_value().msec();
packet.nick = "zerok775";
packet.ctx = "abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890";
packet.ctx = "abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890abcdefg1234567890";

uint64_t begin_ts = CBaseTimeValue::get_time_value().msec();

for(int32_t i = 0; i < PACKET_NUM; i ++)
this->send(packet);

uint64_t cur_count = CBaseTimeValue::get_time_value().msec();

//cout << "send delay = " << cur_count - begin_ts << endl;
packet_count_ += PACKET_NUM;
for (int32_t i = 0; i < PACKET_NUM; i++){
if(this->send(packet) != 0)
return ;
packet_count_++;
}
}

int32_t RUDPConnection::handle_timeout(const void *act, uint32_t timer_id)
Expand Down Expand Up @@ -125,6 +125,8 @@ int32_t RUDPConnection::connect(const Inet_Addr& src_addr, const Inet_Addr& dst_
return -1;
}

rudp_sock_.set_option(4, RUDP_SEND_BUFFER);

//绑定一个事件器
RUDP()->bind_event_handle(rudp_sock_.get_handler(), this);

Expand All @@ -147,7 +149,7 @@ int32_t RUDPConnection::send(RUDPTestPacket& packet)
bin_strm->rewind(true);
*bin_strm << packet;

if(sbuffer_.put(*bin_strm))
if (sbuffer_.put(*bin_strm))
{
RUDP()->register_event(rudp_sock_.get_handler(), MASK_WRITE);
ret = 0;
Expand Down Expand Up @@ -232,17 +234,16 @@ int32_t RUDPConnection::rudp_output_event(int32_t rudp_id)
state_ = RUDP_CONN_CONNECTED;
ts_ = CBaseTimeValue::get_time_value().msec();

heartbeat();
set_timer(SEND_DELAY);

tick_count_ = CBaseTimeValue::get_time_value().msec();
}

//send_packet();

if(sbuffer_.data_length() > 0)
sbuffer_.send(rudp_sock_);
if (sbuffer_.data_length() == 0)
send_packet();

byte_count_ += sbuffer_.send(rudp_sock_);

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions test/rudp_sender/rudp_sender/rudp_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class RUDPConnection : public CEventHandler,
BinStream istrm_;

uint32_t packet_count_;
uint32_t byte_count_;
uint64_t ts_;

uint32_t count_;
Expand Down
6 changes: 3 additions & 3 deletions test/rudp_sender/rudp_sender/rudp_reciver.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "base_reactor_instance.h"
#include "revolver/base_reactor_instance.h"
#include "reciver_thread.h"
#include "udp_handler.h"
#include "rudp_listen_handler.h"
#include "rudp_interface.h"
#include "rudp/rudp_interface.h"
#include "rudp_connection.h"
#include "stat_packet.h"

Expand Down Expand Up @@ -69,7 +69,7 @@ int main(int agc, char* argv[])

if(c == 'e')
{
if(conn != NULL && conn->get_state() != RUDP_CONN_IDLE)
if (conn != NULL && (conn->get_state() == RUDP_CONN_CONNECTING || conn->get_state() == RUDP_CONN_CONNECTED))
conn->close();

break;
Expand Down
12 changes: 7 additions & 5 deletions test/rudp_sender/rudp_sender/rudp_reciver.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -21,12 +21,14 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand All @@ -41,7 +43,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>../../../bin/debug/rudp_sender</OutDir>
<IntDir>../../../tmp/rudp_sender</IntDir>
<IntDir>D:\code\opensource\revolver\bin\debug\rudp_sender</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
Expand All @@ -53,13 +55,13 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../../common/core;../../../common/rudp;../../../common/revolver;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../../common/core;../../../common/rudp;../../../common/revolver;../../../common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>../../../lib/debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>../../../common/lib/debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>core.lib;rudp.lib;revolver.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>../../../bin/debug/rudp_sender/rudp_sender.exe</OutputFile>
</Link>
Expand All @@ -73,7 +75,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../../common/revolver;../../../common/core;../../../common/rudp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../../common/revolver;../../../common/core;../../../common/rudp;../../../common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
Expand Down

0 comments on commit 78bc173

Please sign in to comment.