資源簡(jiǎn)介
SocketAsyncEventArgs 單機(jī)測(cè)試成功突破 6W,59999 還是 100%連接上去的 所以估計(jì)最高性能可能達(dá)到10W以上
值得說明的是 建議使用 SocketAsyncEventArgs 進(jìn)行監(jiān)聽的 讀取數(shù)據(jù)包. 因?yàn)?這2個(gè)地方的 SocketAsyncEventArgs 是同一個(gè),并且內(nèi)存和 SocketAsyncEventArgs 對(duì)象都好回收 好控制
如果使用 SocketAsyncEventArgs 發(fā)送數(shù)據(jù)包那么 SocketAsyncEventArgs 就不好控制了 所以使用傳統(tǒng)的異步模式比較好. 而數(shù)據(jù)包傳出使用 異步代理 進(jìn)行傳出以免堵塞 SocketAsyncEventArgs 線程.
MSND 的 SocketAsyncEventArgs 除了SocketAsyncEventArgsPOOL 和內(nèi)存Manager 其他純屬扯淡.最好別效仿.

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Net.Sockets;
namespace?ZYSocketSuper
{
????internal?sealed?class?BufferManager
????{
????????private?Byte[]?buffer;
????????private?Int32?bufferSize;
????????private?Int32?numSize;
????????private?Int32?currentIndex;
????????private?Stack?freeIndexPool;
????????public?BufferManager(Int32?numsize?Int32?buffersize)
????????{
????????????this.numSize?=?numsize;
????????????this.bufferSize?=?buffersize;
???????????
????????}
????????public?void?Inint()
????????{
????????????buffer?=?new?byte[numSize];
????????????freeIndexPool?=?new?Stack(numSize?/?bufferSize);
????????}
????????internal?void?FreeBuffer(SocketAsyncEventArgs?args)
????????{
????????????freeIndexPool.Push(args.Offset);
????????????args.SetBuffer(null?0?0);
????????}
????????internal?Boolean?SetBuffer(SocketAsyncEventArgs?args)
????????{
????????????if?(this.freeIndexPool.Count?>?0)
????????????{
????????????????args.SetBuffer(this.buffer?this.freeIndexPool.Pop()?this.bufferSize);
????????????}
????????????else
????????????{
????????????????if?((this.numSize?-?this.bufferSize)?????????????????{
????????????????????return?false;
????????????????}
????????????????args.SetBuffer(this.buffer?this.currentIndex?this.bufferSize);
????????????????this.currentIndex?+=?this.bufferSize;
????????????}
????????????return?true;
????????}
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????13312??2009-12-26?14:04??ZYSocketSuper\bin\Debug\ZYSocketSuper.exe
?????文件??????34304??2009-12-26?14:04??ZYSocketSuper\bin\Debug\ZYSocketSuper.pdb
?????文件??????14328??2009-12-26?14:04??ZYSocketSuper\bin\Debug\ZYSocketSuper.vshost.exe
?????文件????????490??2009-06-11?05:14??ZYSocketSuper\bin\Debug\ZYSocketSuper.vshost.exe.manifest
?????文件???????1514??2009-12-26?00:15??ZYSocketSuper\BufferManager.cs
?????文件????????358??2009-12-26?14:04??ZYSocketSuper\obj\Debug\ZYSocketSuper.csproj.FileListAbsolute.txt
?????文件??????13312??2009-12-26?14:04??ZYSocketSuper\obj\Debug\ZYSocketSuper.exe
?????文件??????34304??2009-12-26?14:04??ZYSocketSuper\obj\Debug\ZYSocketSuper.pdb
?????文件???????2435??2009-12-26?13:41??ZYSocketSuper\Program.cs
?????文件???????1358??2009-12-25?23:03??ZYSocketSuper\Properties\AssemblyInfo.cs
?????文件???????2011??2009-12-25?23:26??ZYSocketSuper\SocketAsyncEventArgsPool.cs
?????文件??????12670??2009-12-26?14:04??ZYSocketSuper\ZYSocketSuper.cs
?????文件???????2642??2009-12-25?23:31??ZYSocketSuper\ZYSocketSuper.csproj
?????文件????????929??2009-12-25?23:03??ZYSocketSuper.sln
?????目錄??????????0??2009-12-25?23:03??ZYSocketSuper\obj\Debug\TempPE
?????目錄??????????0??2009-12-25?23:26??ZYSocketSuper\bin\Debug
?????目錄??????????0??2009-12-26?14:04??ZYSocketSuper\obj\Debug
?????目錄??????????0??2009-12-25?23:02??ZYSocketSuper\bin
?????目錄??????????0??2009-12-25?23:02??ZYSocketSuper\obj
?????目錄??????????0??2009-12-25?23:03??ZYSocketSuper\Properties
?????目錄??????????0??2009-12-26?14:04??ZYSocketSuper
-----------?---------??----------?-----??----
???????????????133967????????????????????21
- 上一篇:提取鏈接.txt
- 下一篇:TMS320F28035最小系統(tǒng)
評(píng)論
共有 條評(píng)論