List of ports

10 posts / 0 new
Last post
mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
List of ports

I am looking for a method to run through the list of public ports and get their names.

  1. Node=List->lh_Head;
  2. while((NextNode=Node->ln_Succ))
  3. {
  4. ...
  5. get port name from Node
  6. ...
  7. }

Is there a master list of ports in Exec to step through?

zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
I do like that in SysMon

I do like that in SysMon Ports tab

  1. struct Node *Portnode;
  2. struct List *execPortlist = &(SysBase->PortList);
  3.  
  4. for (Portnode = GetHead(execPortlist);
  5. Portnode != NULL; Portnode = GetSucc(Portnode))
  6. {
  7.  
  8. ...
  9. }
mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Nice! Thank you! I had to

Nice! Thank you!

I had to update one line to this:
struct List *execPortlist = &(((struct ExecBase *)SysBase)->PortList);

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
You should put

You should put Forbid()/Permit() around your list scanning code to stop ports from being added/removed while you are scanning the list and causing your program to crash.

  1. IExec->Forbid();
  2. for (node = ((struct ExecBase *)SysBase)->PortList.lh_Head;
  3. node->ln_Succ != NULL;
  4. node = node->ln_Succ)
  5. {
  6. // ...
  7. }
  8. IExec->Permit();
zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
@Salass00 In my program,

@Salass00

In my program, SysMon, I use MutexObtain / MutexRelease instead of Forbid / Permit to lock the PortList.

What is the best method ? Are all the Forbid / Permit have to be transformed in MutexObtain / MutexRelease ?

Thank you for your advices.

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
@zzd10h FindPort(),

@zzd10h

FindPort(), AddPort() and RemPort() functions all use Forbid() based locking. If your program uses some other method then it is broken.

Also you should keep in mind restrictions when in Forbid() state. That is:
1. Don't call Wait() or anything that will indirectly call Wait() (this includes AllocVecTags() if AVT_Wait is left at it's default value and anything that involves file I/O, mutexes or semaphores) as this will break the program's Forbid() state.
2. Do what needs to be done as quickly as possible and don't waste any time.

If you need to copy data from the list then I suggest allocating a large enough buffer beforehand and using that. If it turns out that your estimated buffer size was too small you can allocate a bigger one and begin the scan again.

zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
"If your program uses some

"If your program uses some other method then it is broken."
Yes, i know, i wonder everyday why it doesn't crash more often ;)

More seriously, i thought that Forbid() have to be avoided for an eventual future and have to be replaced by Mutex.
If it's not true, what is the rule ?

Thanks

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
"If your program uses some


"If your program uses some other method then it is broken."
Yes, i know, i wonder everyday why it doesn't crash more often ;)

Luck :-)


More seriously, i thought that Forbid() have to be avoided for an eventual future and have to be replaced by Mutex.
If it's not true, what is the rule ?

You can only replace a forbid / permit pair with a mutex or semaphore when all processes accessing the data you want to protect know about the mutetx / semaphore.

So for your own new programs that share data between multiple processes than using amutex or semaphore is far better than forbid / permit (and that's not really a new guideline) but for accessing pubic data structure like the port list then there must be a public mutext or semaphore to arbitrate access, and as far as I know there isn't one for the port list. One can't be added easily as so many old prgranms are using Forbid/Permit pairs to access the Port List.

That makes me wander exactly what mutex you were obtaining in your program.

zzd10h
zzd10h's picture
Offline
Last seen: 6 years 4 months ago
Joined: 2012-08-24 20:56
Ah ok, thank you, therefore i

Ah ok, thank you, therefore i have to revert all my Mutex to Forbid.

I don't know which Mutex I obtained, but as you said i should be lucky to don't have crash (nobody reported crashs about that in SysMon or FastCompress where I use FindPort, maybe simply because no amigans use them ;) )

Sorry for the offtopic, mritter.

mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Not a problem at all. I am

Not a problem at all. I am still learning new OS4 stuff all the time.

Log in or register to post comments