| 发表于:2007-01-22 12:52:525楼 得分:40 |
没看见你的重叠i/o,异步发送是用重叠i/o来实现的。 mystruct stru; 是个局部变量,在真正发送数据时stru已经析构,data.buf(&stru), 已经是个无效的地址了。 type piobuffer = ^tiobuffer; tiobuffer = packed record ol: twsaoverlapped; sclient: tsocket; noperation: byte; buf: pbyte; nlen: integer; nseq: integer; next: piobuffer; end; function ttcpsock.postsend(pcontext: piocontext; pbuffer: piobuffer): bool; var dwbytes,dwflags: dword; buf: wsabuf; begin result := true; dwflags := 0; pbuffer^.noperation := op_write; buf.len := pbuffer^.nlen; buf.buf := pchar(pbuffer^.buf); if((wsasend(pcontext^.sconnect,@buf,1,dwbytes,dwflags,@pbuffer^.ol,nil) <> no_error)) then begin if(wsagetlasterror <> wsa_io_pending) then begin outpshow(true,pchar( '投递wsasend失败! ')); releasebuffer(pbuffer); result := false; exit; end; end; inc(pcontext^.noutsend); end; | | |
|