捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  粤ICP备10103342号-1 DELPHI盒子 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 盒子检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
 
广告
评论:ScktIocp(与ScktComp兼容的IOCP组件)
melice 42149 2012/2/25 22:09:00
下载链接似乎down了,谁能共享一下么,谢谢。
from 38519 2009/9/1 17:05:43
我是这样改的

function ReceiveText: string; virtual;
function TCustomWinSocket.ReceiveText: string;
begin
  if ReceiveLength > 0 then
  begin
    SetLength(Result, ReceiveLength);
    ReceiveBuf(Result[1], Length(Result));
  end else Result := '';
end;

function TServerClientWinSocket.ReceiveLength: Integer;
begin
  Result := FStream.Position;
end;
function TServerClientWinSocket.ReceiveBuf(var Buf; Count: Integer): Integer;
var
  P, Len: Integer;
begin
  Lock;
  try
    if FStream.Position >= Count then begin
      P := FStream.Position - Count;
      FStream.Position := P;
      Len := Count;
    end else begin
      P := 0;
      Len := FStream.Position;
      FStream.Position := P;
    end;

    Result := FStream.Read(Buf, Len);
    if FStream.Position = FStream.Size then begin
       //大于4K就放掉重新分配内存,否则,只是将指针移动到头部
      if FStream.Size > 4096 then
        FStream.Clear
      else
        FStream.Position := 0;
    end else begin
      FStream.Position := P + (Len - Result);
    end;
  finally
    UnLock;
  end;
end;
cmd9x 38066 2009/7/19 11:25:48
新修改:
TCustomWinSocket类添加了
function ReceiveText: string; virtual;
function TCustomWinSocket.ReceiveText: string;
begin
  if ReceiveLength > 0 then
  begin
    SetLength(Result, ReceiveLength);
    ReceiveBuf(Result[1], Length(Result));
  end else Result := '';
end;

function TServerClientWinSocket.ReceiveLength: Integer;
begin
  Result := FStream.Position;
end;
function TServerClientWinSocket.ReceiveBuf(var Buf; Count: Integer): Integer;
var P1: Integer;
  PS, PD: Pointer;
begin
  Lock;
  try
    P1 := FStream.Position;
    FStream.Seek(0, soBeginning);
    FStream.ReadBuffer(Buf, Count);
    if FStream.Position = P1 then
    begin
    {大于4K就放掉重新分配内存,否则,只是将指针移动到头部}
      if FStream.Size > 4096 then
        FStream.Clear
      else
        FStream.Seek(0, soBeginning);
    end
    else if FStream.Position < P1 then
    begin
      PS := Pointer(Longint(FStream.Memory) + FStream.Position);
      Move(PS^, FStream.Memory^, P1 - FStream.Position);
      FStream.Position := P1 - FStream.Position;
    end;
  finally
    UnLock;
  end;
end;

QQ群:1285183
glwang 37960 2009/7/13 15:04:09
谢谢控主的解答,希望能持续完善升级!
cmd9x 37957 2009/7/13 12:36:48
1、支持D2009没什么难的,把所有的String改成AnsiString,PChar改成PAnsiPChar就差不多了。
2、这个组件是一个服务组件,设IP地址做什么呢?
3、至于只能连少量链接的情况倒是没有碰到,你可以自己写个可以产生多个客户端的程序来测,要想链接上万,必须导入注册文件以修改系统链接数限制
4、关于内存泄漏这个我没什么好说的,源码摆着呢,高手们帮忙检查一下吧
5、关于替换ScktComp,我的建议是在单元引入时加编译选项{$IFDEF IOCP}uScktIocp{$ELSE}uScktComp{$ENDIF};这样就可以直接替换了
cmd9x 37956 2009/7/13 12:23:59
关于内存流接收数据,设计初衷是这样的:
用内存流接收数据后会触发OnRead事件,实现这个事件时要调用
TServerClientWinSocket.ReceiveBuf
这时会将数据从内存流中读出来,为了不频繁分配内存,只对内存流的指针改了位置。
而真正应该改的地方是
function TServerClientWinSocket.ReceiveLength: Integer;
begin
  Result := FStream.Position;
  {原来是Result := FStream.Size;(的确会因为上次数据较多而产生垃圾数据)}
end;
netfun2000 37676 2009/6/7 15:57:34
FastMM4发现内存泄漏:
----------2009/6/7 15:52:36----------
FastMM has detected an error during a free block scan operation. FastMM detected that a block has been modified after being freed. 

The previous block size was: 4127

This block was previously allocated by thread 0xF84, and the stack trace (return addresses) at the time was:
402D48 
456CA4 
4583CA 
44D09F 
45475C 
4586A4 
7C82F23B [Unknown function at ProcessIdToSessionId]

The allocation number was: 527

The block was previously freed by thread 0xF84, and the stack trace (return addresses) at the time was:
402D73 

The current thread ID is 0xF84, and the stack trace (return addresses) leading to this error is:
40B826 
40B86E 
4041FF 
4044BE 
7C82F23B [Unknown function at ProcessIdToSessionId]

Current memory dump of 256 bytes starting at pointer address 7FF33110:
41 02 00 C0 00 00 00 00 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
A  .  .  ? .  .  .  .  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
�  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
�  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
�  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
�  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
�  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
�  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
�  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
dozhyuy 37660 2009/6/5 15:58:44
好东西....学习了
yao_ming 37585 2009/5/26 19:45:56
你好,我下了你的东西,用你的编译程序测试,最多只能达到278个连接?请释疑,谢谢。
peliao 37567 2009/5/25 11:47:55
再过一年,我看我能把我写的IOCP发出来不, 对了,我的也和楼主源自同一作者
glwang 37565 2009/5/25 7:28:50
转帖zhousan修正的帖子
//zhousan 修正一个bug 
//接收到数据直接在上次数据基础上覆盖,若上次数据较多,则会多出一段垃圾数据
//单元:ScktIocp.pas

function TServerClientWinSocket.WorkBlock(var Block: PBlock;
  Transfered: DWORD): DWORD;
var
  ErrCode: Integer;
  Flag, BytesSend: Cardinal;
begin
  Result := RESPONSE_SUCCESS;
  with Block^.Data do
  try
    case Block^.Data.Event of
      seRead:
      begin
        {利用内存流来保存收到的数据,有可能造成频繁的内存重新分配,可以改进}
        Lock;
        FStream.Clear;         //<<---接收到流前先清空原内容,
        FStream.Write(Buffer, Transfered);
        UnLock;
        Self.Event(Self, seRead);        
        if not PrepareRecv(Block) then
          Result := RESPONSE_FAIL;
      end;
      seWrite:
      begin
//        Self.Event(Self, seWrite);
        Dec(wsaBuffer.len, Transfered);
        if wsaBuffer.len <= 0 then
        begin
          { 发送完成,将Block置空,返回到FBlock的可使用的缓区中 }
          Block.Data.IsUse := False;
          Block := nil;
        end else
        begin
          { 数据还没发送完成,继续发送 }
          Flag := 0;
          Inc(wsaBuffer.buf, Transfered);
          FillChar(Overlapped, SizeOf(Overlapped), 0);
          if SOCKET_ERROR = WSASend(FSocket, @wsaBuffer, 1, BytesSend,
          Flag, @Overlapped, nil) then
          begin
          ErrCode := WSAGetLastError;
          if ErrCode <> ERROR_IO_PENDING then
          Error(Self, eeSend, ErrCode);
          end;
        end;
      end;
    end;
  except
    Result := RESPONSE_FAIL;
  end;
end;
glwang 37535 2009/5/21 18:33:34
不能设置IOCP组件的IP地址,有毛用啊!!!!!!!!!!
blueflag 37528 2009/5/20 23:06:09
不错,希望继续更新~~~~~~~~~~
array 37510 2009/5/19 8:56:29
如果能做到跟TServerSocket完全兼容就完美了。现在的版本跟TServerSocket使用上是差不多,还不能做到直接替换就能拥有IOCP特性。
softbug 37509 2009/5/18 23:12:27
支持2009了吗?
555a 37504 2009/5/18 14:00:41
最近想学这方面的东东,太好了,谢谢..........
siow 37503 2009/5/18 13:00:30
好东东,学习ing
第一页 上一页 下一页 最后页 有 17 条纪录 共1页 1 - 17
 用户名:
 密 码:
自动登陆(30天有效)
 
  DELPHI盒子版权所有 技术支持:深圳市麟瑞科技有限公司 1999-2024 V4.01 粤ICP备10103342号-1 更新RSS列表