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...
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Do you want to do this in C++? Then please post your question in the C/C++ Forum. If it's in .NET, use the .NET Forum. The Experts there will be happy to help you.

    Greetings,
    Nepomuk

    Comment

    • Arulmurugan
      New Member
      • Jan 2008
      • 90

      #3
      I don’t have any idea about,how this can be implemented in Vc++. The general techniques are as follows.
      Lets assume two process A and B. A is the one which collects packets and it intimates to Process B to process it.

      Semaphore var = 0;
      Queue q

      Process B() {
      Lock semaphore(var); //here is a wait until process A unlocks
      read from a Q(q);
      Do your work.
      }


      Process A(){
      Do your work;
      write into a Q(q);
      Unlock semaphore(var);
      }
      Regards,
      Arul

      Comment

      • selvialagar
        New Member
        • Apr 2008
        • 57

        #4
        Hi...
        I have some doubts in your reply. Whenever the data comes, How the process B, knows the data is available in the stream..

        I think the process done by Process B are
        1. Check for the data available in the stream.
        2. If the data is available, then check for the free space available in the pool.
        Then get the data from the stream, copy the data to the pool of free space
        3. then, at last, give an intimation to the process A.
        4. if the data in the pool, is taken by process A, then Log the data in a file.
        5. wait for the data

        Am i correct?

        Comment

        • Arulmurugan
          New Member
          • Jan 2008
          • 90

          #5
          Originally posted by selvialagar
          Hi...
          I have some doubts in your reply. Whenever the data comes, How the process B, knows the data is available in the stream..

          I think the process done by Process B are
          1. Check for the data available in the stream.
          2. If the data is available, then check for the free space available in the pool.
          Then get the data from the stream, copy the data to the pool of free space
          3. then, at last, give an intimation to the process A.
          4. if the data in the pool, is taken by process A, then Log the data in a file.
          5. wait for the data

          Am i correct?
          Now i bit clear about what you want to do....


          /* semaphore is used to give a signal to another process here */

          Semaphore var = 0; /* var semaphore is locked, which means some
          has to unlock it, then only any one can lock it.*/

          Semaphore var1 = 1; /* any one can do semaphore lock *.*/

          Queue q /* it used to pass information b/w two process */

          Process B() {

          while(1){
          Lock semaphore(var); /* here is Process B becuse 'var=0' this var can be 1, when
          process A executes 'Unlock semaphore(var); '
          Means that process a after completes it work, it send a signal
          to process B.
          i.e waiting for a signal from process 'A'*/
          read from a Q(q); /* Once the process 'A' unlocks Process 'B' reads from the Q
          Note Now Process B is process processing but Process is locked
          by semaphore var1 . until some one else unlock the semaphore
          Process 'A' can not be continue*/

          Unlock semaphore(var1) ;/* Okay Process 'B' took informtaion from the Q, so it has
          Enoguh informtion to proceed, Now it can unlock the send a
          signal to Process 'A' to continue by unlocking the semaphore
          'var1' Unlock semaphore(var1)
          Send a signal to process 'A'*/
          Do your work. /* do your work*/
          } /* end while */
          }


          Process A(){
          while (1){
          Lock semaphore(var1) /* var1=1 so process a can get lock...., it will not wait for anything
          first time..., Note it is not unlock this semaphore..., which
          second third etc it can not lock again, some one has to unlock
          it then only it can lock 2nd and 3rd time.
          Who is unlocking it, it done by Process 'B' i.e just receving
          signal to Process 'B' to continue
          */
          Do your work; /* Do your work */
          write into a Q(q); /* write into a Q */
          Unlock semaphore(var); /* var was 0, Now unlock this semaphore leads var=1, so process B
          can continue becuse Proceess 'B' 'Lock semaphore(var); ' process
          A to unlock. it is signal sending a signal to process B
          to continue */

          }
          }

          Feel free to discuss more on this.....
          Regards,
          Arul

          Comment

          Working...