How to store incoming packets or how to allocate pool of free space for the packets?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • selvialagar
    New Member
    • Apr 2008
    • 57

    How to store incoming packets or how to allocate pool of free space for the packets?

    I am doing a project in embedded system (in vc++.net 2003)...I need to allocate a pool of free space for the incoming packets.Once i received the packet in the pool, an intimation must be given to me that the requested packet has come.How to do this?

    Meanwhile, an packet comes for another process which runs in the backend,an intimation must be given for that process.I know, it is possible by multithreading. I need some ideas, how to implement this? How to generate the intimation? Awaiting for the response...
  • BageDevimo
    New Member
    • Jul 2008
    • 10

    #2
    Ok, so if I understand you right. You want a thread running, constantly receiving, and adding the received packets to a pool, then when a certain packet is received, you another thread or something to be notified of it?

    if so, then you could allocate your 'pool of packets' as a queue.. Then just add stuff to it when received. Also, for the letting stuff know bit, then you could either have functions / threads that want packets 'subscribe' to this thread, with what kinda of packet it wants. Are the packets identifiable? Do they have a header which can indicate who 'wants' the packet? If so, why not just have your threads and functions that want packets Peek the top of the queue and check if the packet they want is on the top?

    I dunno if this is what you want..

    Ben Anderson,

    Comment

    • selvialagar
      New Member
      • Apr 2008
      • 57

      #3
      Originally posted by BageDevimo
      Ok, so if I understand you right. You want a thread running, constantly receiving, and adding the received packets to a pool, then when a certain packet is received, you another thread or something to be notified of it?

      if so, then you could allocate your 'pool of packets' as a queue.. Then just add stuff to it when received. Also, for the letting stuff know bit, then you could either have functions / threads that want packets 'subscribe' to this thread, with what kinda of packet it wants. Are the packets identifiable? Do they have a header which can indicate who 'wants' the packet? If so, why not just have your threads and functions that want packets Peek the top of the queue and check if the packet they want is on the top?

      I dunno if this is what you want..

      Ben Anderson,

      Exactly sir...You are right. Packets are identifiable by the Feature ID. Can i implement this with Semaphore or InterProcess Communication or Just using threads? Which one is the best option..I don't know clearly about semaphores..Ple ase explain it. I have to do it in VC++.Net 2003. Please give me the basic idea behind this...

      Comment

      • BageDevimo
        New Member
        • Jul 2008
        • 10

        #4
        Lol. I've no idea what a SemaPore thing is either, i'd check out the http://en.wikipedia.org/wiki/Semaphore_(programming).

        But i'd just use threads.. that should work fine. Have a thread looking called a recieve call, even a blocking one (non async) should be fine as long as the loop never terminates.. Unless the program is shutting down, of course.

        So if you create a queue of classes, each which have an array for all the bytes of the packet, and a enum for the type/header/FeatureID, then just have each thread/function that is requesting a packet 'peek' at the top item of the queue, if its the FeatureID it wants, the pop it off, and deal with it, else leave it and wait for its packet to be on the top. Provided all functions/threads looking for packets are polling the queue fairly constantly, this should work fine, and a big advantage is there is no need to manually declare all the memory.

        Ben Anderson,

        Comment

        Working...