資源簡介
該DEMO主要根據官網例子改編,另外加了些個人處理,保留接發數據傳播,另外支持數萬并發

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Net.Sockets;
using?System.Text;
using?System.Threading.Tasks;
namespace?BRKJ.IPCO.Client
{
????public?class?BufferManager
????{
????????int?m_numBytes;?????????????????//?the?total?number?of?bytes?controlled?by?the?buffer?pool??
????????byte[]?m_buffer;????????????????//?the?underlying?byte?array?maintained?by?the?Buffer?Manager??
????????Stack?m_freeIndexPool;?????//???
????????int?m_currentIndex;
????????int?m_bufferSize;
????????public?BufferManager(int?totalBytes?int?bufferSize)
????????{
????????????m_numBytes?=?totalBytes;
????????????m_currentIndex?=?0;
????????????m_bufferSize?=?bufferSize;
????????????m_freeIndexPool?=?new?Stack();
????????}
????????//?Allocates?buffer?space?used?by?the?buffer?pool??
????????public?void?InitBuffer()
????????{
????????????//?create?one?big?large?buffer?and?divide?that???
????????????//?out?to?each?SocketAsyncEventArg?object??
????????????m_buffer?=?new?byte[m_numBytes];
????????}
????????//?Assigns?a?buffer?from?the?buffer?pool?to?the???
????????//?specified?SocketAsyncEventArgs?object??
????????//??
????????//?true?if?the?buffer?was?successfully?set?else?false ??
????????public?bool?SetBuffer(SocketAsyncEventArgs?args)
????????{
????????????if?(m_freeIndexPool.Count?>?0)
????????????{
????????????????args.SetBuffer(m_buffer?m_freeIndexPool.Pop()?m_bufferSize);
????????????}
????????????else
????????????{
????????????????if?((m_numBytes?-?m_bufferSize)?????????????????{
????????????????????return?false;
????????????????}
????????????????args.SetBuffer(m_buffer?m_currentIndex?m_bufferSize);
????????????????m_currentIndex?+=?m_bufferSize;
????????????}
????????????return?true;
????????}
????????//?Removes?the?buffer?from?a?SocketAsyncEventArg?object.????
????????//?This?frees?the?buffer?back?to?the?buffer?pool??
????????public?void?FreeBuffer(SocketAsyncEventArgs?args)
????????{
????????????m_freeIndexPool.Push(args.Offset);
????????????args.SetBuffer(null?0?0);
????????}
????}????
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????189??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\App.config
?????文件???????9497??2018-07-28?15:33??TCPSOCKET.IPCO\BRKJ.IPCO.Client\bin\ClientDebug.rar
?????文件??????20480??2018-07-28?15:33??TCPSOCKET.IPCO\BRKJ.IPCO.Client\bin\Debug\BRKJ.IPCO.Client.exe
?????文件????????189??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\bin\Debug\BRKJ.IPCO.Client.exe.config
?????文件???????4064??2018-07-28?14:04??TCPSOCKET.IPCO\BRKJ.IPCO.Client\BRKJ.IPCO.Client.csproj
?????文件???????2165??2018-07-28?13:47??TCPSOCKET.IPCO\BRKJ.IPCO.Client\BufferManager.cs
?????文件??????13392??2018-07-28?15:05??TCPSOCKET.IPCO\BRKJ.IPCO.Client\CliectSocket.cs
?????文件???????5750??2018-07-28?13:58??TCPSOCKET.IPCO\BRKJ.IPCO.Client\ClientRequest.cs
?????文件???????5088??2018-07-28?15:32??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Form1.cs
?????文件???????7478??2018-07-28?15:32??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Form1.Designer.cs
?????文件???????5817??2018-07-28?15:32??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Form1.resx
?????文件????????538??2018-07-28?13:47??TCPSOCKET.IPCO\BRKJ.IPCO.Client\MySocketEventArgs.cs
?????文件????????864??2018-07-28?15:07??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\BRKJ.IPCO.Client.csproj.FileListAbsolute.txt
?????文件????????977??2018-07-28?15:33??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\BRKJ.IPCO.Client.csproj.GenerateResource.Cache
?????文件??????20480??2018-07-28?15:33??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\BRKJ.IPCO.Client.exe
?????文件????????180??2018-07-28?15:33??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\BRKJ.IPCO.Client.Form1.resources
?????文件??????46592??2018-07-28?15:33??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\BRKJ.IPCO.Client.pdb
?????文件????????180??2018-07-28?14:14??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\BRKJ.IPCO.Client.Properties.Resources.resources
?????文件???????7109??2018-07-28?13:53??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????????0??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件??????????0??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件??????????0??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????文件????????528??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Program.cs
?????文件???????1356??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Properties\AssemblyInfo.cs
?????文件???????2884??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Properties\Resources.Designer.cs
?????文件???????5612??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Properties\Resources.resx
?????文件???????1103??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Properties\Settings.Designer.cs
?????文件????????249??2018-07-28?11:42??TCPSOCKET.IPCO\BRKJ.IPCO.Client\Properties\Settings.settings
?????文件????????189??2018-07-28?11:41??TCPSOCKET.IPCO\BRKJ.IPCO.Server\BRKJ.IPCO.Server\App.config
?????文件???????1152??2018-07-28?12:08??TCPSOCKET.IPCO\BRKJ.IPCO.Server\BRKJ.IPCO.Server\AsyncUserToken.cs
............此處省略57個文件信息
- 上一篇:C# DBHelper類
- 下一篇:C#線程間操作無效Study
評論
共有 條評論