Source: sctpsocketmaster.h


Annotated List
Files
Globals
Hierarchy
Index
/*
 *  $Id: sctpsocketmaster_h.html,v 1.6 2001/11/30 14:02:34 dreibh Exp $
 *
 * SCTP implementation according to RFC 2960.
 * Copyright (C) 1999-2001 by Thomas Dreibholz
 *
 * Realized in co-operation between Siemens AG
 * and University of Essen, Institute of Computer Networking Technology.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * There are two mailinglists available at www.sctp.de which should be used for
 * any discussion related to this implementation.
 *
 * Contact: discussion@sctp.de
 *          dreibh@exp-math.uni-essen.de
 *
 * Purpose: SCTP Socket Master
 *
 */

#ifndef SCTPSOCKETMASTER_H
#define SCTPSOCKETMASTER_H


#include "tdsystem.h"
#include "thread.h"
#include "sctpsocket.h"
#include "sctpnotificationqueue.h"


#include <sctp.h>
#include <multimap.h>
#include <set.h>


namespace Coral {


/**
  * This class manages the interaction between the SCTP Socket class and the
  * userland SCTP implementation. It is implemented as a singleton and
  * automatically instantiated at program startup.
  *
  * @short   SCTP Socket Master
  * @author  Thomas Dreibholz (dreibh@exp-math.uni-essen.de)
  * @version 1.0
  */
class SCTPSocketMaster : public Thread
{
   // ====== Friend classes =================================================
   friend class SCTPSocket;
   friend class SCTPConnectionlessSocket;
   friend class SCTPAssociation;


   // ====== Constructor/Destructor =========================================
   public:
   /**
     * Constructor.
     */
   SCTPSocketMaster();

   /**
     * Destructor.
     */
   ~SCTPSocketMaster();


   // ====== Lock/unlock ====================================================
   /**
     * Lock the SCTP implementation for exclusive access. This includes
     * Thread's critical section lock.
     */
   inline void lock();

   /**
     * Unlock the SCTP implementation. This includes
     * Thread's critical section lock.
     */
   inline void unlock();


   // ====== User socket notifications ======================================
   struct UserSocketNotification {
      int       FileDescriptor;
      short int Mask;
      Condition UpdateCondition;
   };

   /**
     * Add user socket to notification list. The socket is automatically
     * removed from the list when the first notification is received! This
     * is necessary to avoid endless loops of select() -> notification ->
     * select() -> ... calls!
     *
     * @param usn User socket notification description.
     */
   void addUserSocketNotification(UserSocketNotification* usn);

   /**
     * Remove user socket from notification list.
     *
     * @param usn User socket notification description.
     */
   void deleteUserSocketNotification(UserSocketNotification* usn);


   // ====== Public data ====================================================
   public:
   /**
     * Result of sctp_initLibrary() call. If not 0, the SCTP initialization
     * failed.
     */
   static int InitializationResult;


   /**
     * Master instance (singleton).
     */
   static SCTPSocketMaster MasterInstance;


   // ====== Protected data =================================================
   protected:
   static cardinal                               LockLevel;
   static SCTP_ulpCallbacks                      Callbacks;
   static multimap<unsigned short, SCTPSocket*>  SocketList;
   static set<unsigned short>                    ClosingSockets;
   static multimap<unsigned int, unsigned short> ClosingAssociations;
   static card64                                 LastGarbageCollection;
   static cardinal                               OldCancelState;


   static SCTPSocket* getSocketForAssociationID(const unsigned int assocID);
   static void delayedDeleteAssociation(const unsigned short instanceID,
                                        const unsigned int assocID);
   static void delayedDeleteSocket(const unsigned short instanceID);


   // ====== Private data ===================================================
   private:
   void run();
   static void lock(void* data);
   static void unlock(void* data);

   static void socketGarbageCollection();
   static bool associationGarbageCollection(const unsigned int assocID,
                                            const bool         sendAbort);

   static void initNotification(SCTPNotification& notification);
   static bool initNotification(SCTPNotification& notification,
                                unsigned int      assocID,
                                unsigned short    streamID);
   static void addNotification(SCTPSocket*             socket,
                               unsigned int            assocID,
                               const SCTPNotification& notification);

   static void dataArriveNotif(unsigned int assocID,
                               unsigned int streamID,
                               unsigned int len,
                               unsigned int protoID,
                               unsigned int unordered,
                               void*        ulpDataPtr);
   static void networkStatusChangeNotif(unsigned int   assocID,
                                        short          destAddrIndex,
                                        unsigned short newState,
                                        void*          ulpDataPtr);
   static void* communicationUpNotif(unsigned int   assocID,
                                     unsigned short status,
                                     int            noOfDestinations,
                                     unsigned short noOfInStreams,
                                     unsigned short noOfOutStreams,
                                     void*          dummy);
   static void communicationLostNotif(unsigned int   assocID,
                                      unsigned short status,
                                      void*          ulpDataPtr);
   static void communicationErrorNotif(unsigned int   assocID,
                                       unsigned short status,
                                       void*          dummy);
   static void sendFailureNotif(unsigned int   assocID,
                                unsigned char* unsent_data,
                                unsigned int   dataLength,
                                unsigned int*  context,
                                void*          dummy);
   static void restartNotif(unsigned int assocID,
                            void*        ulpDataPtr);
   static void shutdownCompleteNotif(unsigned int assocID,
                                     void*        ulpDataPtr);
   static void queueStatusChangeNotif(unsigned int assocID,
                                      int          queueType,
                                      int          queueIdentifier,
                                      int          queueLength,
                                      void*        ulpData);
   static void asconfStatusNotif(unsigned int assocID,
                                 unsigned int correlationID,
                                 int          result,
                                 void*        request,
                                 void*        ulpData);
   static void userCallback(int       fileDescriptor,
                            short int eventMask,
                            void*     userData);
};


}


#include "sctpsocketmaster.icc"


#endif

Generated by: dreibh@kappes on Fri Nov 30 14:03:21 2001, using kdoc 2.0a53.