PC Review


Reply
Thread Tools Rate Thread

Async Sockets Buffer Manager / Buffer Pool

 
 
Matijaz
Guest
Posts: n/a
 
      5th Sep 2012
Hello,

I have written async sockets based TCP Client application for CF. I have encountered the problem with segmented heap. I suppose it is caused pinned objects (byte[] buffers) which can't be compacted by GC. I saw some implementation for full framework based on ArraySegment but this doesn't seem to work for me. Can someone give me a hint how to deal with this problem or pointme out to any resources on the internet?

This is snippet of receive callback code:

private void ReceiveData(StateObject state)
{
asyncEvent.Reset();

Socket socket = state.workSocket;

if (socket != null)
socket.BeginReceive(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, receiveCallback, state);

}

private void ReceiveCallback(IAsyncResult ar)
{
try {

// Retrieve the state object and the client socket
// from the asynchronous state object.
StateObject state = (StateObject)ar.AsyncState;
Socket socket = state.workSocket;

int bytesRead = socket.EndReceive(ar);

AsyncEventSet(NotifyCommand.ReceivedData, null);

if (bytesRead > 0)
{
addDataBuffer(state.buffer, bytesRead);

// Wake up parser thread - there is a job to do
RaiseParseEvent();

// Reset timeouts
ResetTimeouts();

//Start recieving again
ReceiveData(state);
}

} catch (Exception ex) {
AsyncEventSet(NotifyCommand.Error, ex.Message);
logError("Receive exception: " + ex.Message);
}

}

Best regards
Matijaz
 
Reply With Quote
 
 
 
 
matijaz69@gmail.com
Guest
Posts: n/a
 
      5th Sep 2012
> I have written async sockets based TCP Client application for CF. I have
> encountered the problem with segmented heap. I suppose it is caused pinned
> objects (byte[] buffers) which can't be compacted by GC. I saw some
> implementation for full framework based on ArraySegment but this doesn't seem
> to work for me. Can someone give me a hint how to deal with this problem or
> point me out to any resources on the internet?


Just noticed I didn't make myself clear. I'm looking for buffer pool / buffer manager working solution that can be ported to .NET Compact Framework.

Best regards
Matijaz
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing an async client (sockets/async/thread) asharda@woh.rr.com Microsoft C# .NET 8 17th Mar 2008 11:04 PM
Any harm in using Async=true to sql server 2005 for non-async db calls Chris Becker Microsoft ADO .NET 1 23rd Mar 2007 01:18 AM
Async sockets vs synch sockets and threads nyhetsgrupper@gmail.com Microsoft C# .NET 4 20th Sep 2006 04:06 AM
Async Sockets, Buffer Pinning Greg Young Microsoft C# .NET 4 6th Aug 2006 01:02 PM
Async in asp.net 2.0 and async application block =?Utf-8?B?TGVuZWlzZTQ0?= Microsoft Dot NET 2 4th Jan 2006 04:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:30 PM.