Skip to content

autoConnect connects too early with asynPortDriver #224

@exzombie

Description

@exzombie

The asynPortDriver::connect() function is virtual. However, it is called indirectly from the constructor because asynManager::registerPort() calls it when autoConnect is true. This is a problem because the object is not fully constructed yet, so it is not possible to call an overridden connect function. This makes it more difficult for derived drivers to do connection management using asyn facilities.

I thought about different options for fixing this, but it's not possible without breaking compatibility in some way.

  • Enabling autoconnect with a separate function after construction (e.g. in the iocsh command that creates the driver, or in a factory function) is the most sensible, but requires derived drivers to know to do it. Having the autoConnect parameter to asynPortDriver constructor is then superfluous.
  • Enabling autoconnect later in the constructor might work most of the time because asyn sets up a timer to fire after 10ms, and the constructor should be done by then. Hopefully. I don't like this too much.
  • Enabling autoconnect from the callback thread would ensure that construction is complete. But not only does this change the behavior significantly, it also breaks when there is no IOC where it reverts to the current behavior because interruptAccept is always on.

So, I don't see a general solution. I guess drivers will just have to cope. At least, merging #217 would make enabling autoconnect later work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions