pIoBuff := FIOBufferManager.GetIOData;
          if pIoBuff <> nil then
          begin
            if (WSARecvFrom(FSocket,@pIoBuff^.DataBuf,1,@pIoBuff^.Bytes,
            @ulFlags,PSockAddr(@pIoBuff^.RemoteAddr),@pIoBuff^.RemoteAddrLen,POverlapped(pIoBuff),nil) <> SOCKET_ERROR)
            or (WSAGetLastError() = ERROR_IO_PENDING) then
            begin
              FWorkerEvents[I] := CreateEvent(nil,True,False,nil);
              New(PWP);
              PWP^.UDP := Self;
              PWP^.WorkerEventIndex := i;
              FWorkerThreads[i] := TWorkerThread.Create(PWP,0);
            end
            else
            begin
              OutputDebugString(PChar(IntToStr(WSAGetLastError)));
              FIOBufferManager.RecoverIOData(pIoBuff);
            end;
          end;
          Result := True;
        end;constructor TIOBufferManager.Create(Count: Integer);
var
  i:Integer;
  pIoBuf:PIOBuffer;
begin
  FUsedList := TDouList.Create;
  FFreeList := TDouList.Create;
  InitializeCriticalSection(FLock);
  for i := 1 to Count do
  begin
    New(pIoBuf);
    FillChar(pIoBuf^.Overlapped,SizeOf(pIoBuf^.Overlapped),0);
    pIoBuf^.DataBuf.buf := @pIoBuf^.Buffer;
    pIoBuf^.DataBuf.len := BUFFER_SIZE;
    pIoBuf^.RemoteAddrLen := SizeOf(TSockAddr);
    pIoBuf^.Point := FFreeList.AddEnd(pIoBuf);
    pIoBuf^.Bytes := BUFFER_SIZE;
  end;   
end;function TIOBufferManager.GetIOData: PIOBuffer;
var
  point:PNode;
begin
  EnterCriticalSection(FLock);
  point := FFreeList.PopHead;
  if point <> nil then
  begin
    Result := PIOBuffer(point^.pData);
    FUsedList.AddPosition(point);
  end
  else
  begin
    New(Result);
    FillChar(Result^.Overlapped,SizeOf(Result^.Overlapped),0);
    Result^.DataBuf.buf := @Result^.Buffer;
    Result^.DataBuf.len := BUFFER_SIZE;
    Result^.RemoteAddrLen := SizeOf(Result^.RemoteAddr);
    Result^.Bytes := BUFFER_SIZE;
    Result^.Point := FUsedList.AddEnd(Result);
  end;
  LeaveCriticalSection(FLock);
end;

解决方案 »

  1.   

    WSAEFAULT
    10014 Bad address.    The system detected an invalid pointer address in attempting to use a pointer argument of a call. This error occurs if an application passes an invalid pointer value, or if the length of the buffer is too small. For instance, if the length of an argument, which is a sockaddr structure, is smaller than the sizeof(sockaddr).
      

  2.   

    我都找了,顺便给你一贴,http://topic.csdn.net/t/20060621/10/4833982.html希望对你有帮助