Async socket IO

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Muylaert

    Async socket IO

    Hi

    I have a question about Sockets in C#.

    Is it possible that the BeginReceive returns an AsyncResult where
    CompletedSynchr onously is set to true.
    I would think it is, this is the way Overlapped IO worked in Win32.

    Now, if this happens,
    A. Is the Callback method executed?
    B. Is this executed inside the caller thread or still on the
    threadpool.
    C. Is the callerthread blocked until this callback is executed?

    kind regards

    Alexander


  • Alexander Muylaert

    #2
    Re: Async socket IO

    And if I do need to check for this,

    wich one is correct. Do I need to check the IsCompleted or
    CompletedSynchr onously member?

    private void StartReceive(){
    IAsyncResult Result;

    do {

    Result = Socket.BeginRec eive(FReceiveBu ffer, 0, 1024,
    SocketFlags.Non e, new AsyncCallback(O nReceiveCallbac k), this);

    } while (Result.Complet edSynchronously );

    }

    private void StartReceive(){
    IAsyncResult Result;

    do {

    Result = Socket.BeginRec eive(FReceiveBu ffer, 0, 1024,
    SocketFlags.Non e, new AsyncCallback(O nReceiveCallbac k), this);

    } while (Result.IsCompl eted);

    }


    Comment

    • Robert Jordan

      #3
      Re: Async socket IO

      Hi Alexander,
      [color=blue]
      > I have a question about Sockets in C#.
      >
      > Is it possible that the BeginReceive returns an AsyncResult where
      > CompletedSynchr onously is set to true.
      > I would think it is, this is the way Overlapped IO worked in Win32.
      >
      > Now, if this happens,
      > A. Is the Callback method executed?[/color]

      Yes, when you call EndReceive.
      [color=blue]
      > B. Is this executed inside the caller thread or still on the
      > threadpool.[/color]

      On caller's thread.
      [color=blue]
      > C. Is the callerthread blocked until this callback is executed?[/color]

      Yes. It blocks when you call EndReceive.

      bye
      Rob

      Comment

      Working...