[snmp] ListeningContext problems

Jeremy Stone Jeremy.Stone at cyclone-technology.com
Thu Jul 17 15:52:07 BST 2008


Have noticed a couple of problem with ListeningContext:

(1)    uk.co.westhawk.snmp.stack.ListeningContext destroys itself when
either the last RawPduListener or the last UnhandledRawPduListener is
removed - even though there may be a listener of the other type
registered.

 

Suggest following code change:

(a)    Add method:

    private void destroyIfNoListeners()

    {

        if (pduSupport.getListenerCount() == 0

                && unhandledSupport.getListenerCount() == 0)

        {

            destroy();

        }

    }

 

(b)   Call this from removeUnhandledRawPduListener and
removeRawPduListener instead of checking the respective listener counts.

 

(2)    The startListening method sets the value of the soc member before
it calls soc.create(...). If soc.create fails (e.g. there is another
process listening on the port), subsequent calls to startListening will
not throw an IOException (because soc!=null) but will not try to
re-create the socket. Therefore callers will erroneously assume that the
socket is created successfully.

 

Maybe should only set soc after a successful call to create, i.e:

 

    protected void startListening() throws java.io.IOException

    {

        synchronized (SOC_LOCK)

        {

            if (soc == null)

            {

                ContextSocketFace tempSoc = AbstractSnmpContext

                        .getSocket(typeSocket);

                tempSoc.create(hostPort, bindAddr);

 

                soc = tempSoc;

 

......etc as before

            }

            if (me == null)

            {

......etc as before

            }

        }

    }

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

Cyclone Technology Ltd. Registered in England and Wales No 3114265, Registered Office: 1 Church Walk, Tenbury Wells, WR15 8HT

Visit our website at www.cyclone-technology.com


More information about the snmp mailing list