Source: sctpassociation.h


Annotated List
Files
Globals
Hierarchy
Index
/*
 *  $Id: sctpassociation_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 Association
 *
 */

#ifndef SCTPASSOCIATION_H
#define SCTPASSOCIATION_H


#include "tdsystem.h"
#include "condition.h"
#include "internetaddress.h"
#include "sctpsocket.h"
#include "sctpnotificationqueue.h"


#include <sctp.h>


namespace Coral {


/**
  * This class manages a SCTP assocation. Note: The constructor is protected,
  * a SCTP assocation can be created from an SCTP socket using associate() or
  * accept().
  *
  * @short   SCTP Association
  * @author  Thomas Dreibholz (dreibh@exp-math.uni-essen.de)
  * @version 1.0
  *
  * @see SCTPSocket
  * @see SCTPSocket#associate
  * @see SCTPSocket#accept
  */
class SCTPAssociation
{
   // ====== Friend classes =================================================
   friend class SCTPSocket;
   friend class SCTPConnectionlessSocket;
   friend class SCTPSocketMaster;


   // ====== Destructor =====================================================
   public:
   /**
     * Destructor.
     */
   ~SCTPAssociation();


   // ====== Association functions ==========================================
   /**
     * Get internal association ID.
     *
     * @return Association ID.
     */
   inline unsigned int getID() const;

   /**
     * Get local addresses.
     *
     * @param addressArray Reference to store NULL-terminated array of local addresses. The addresses are allocated automatically and have to be freed using deleteAddressList().
     * @return true, if addressEntries are sufficient; false otherwise.
     *
     * @see SocketAddress#deleteAddressList
     */
   bool getLocalAddresses(SocketAddress**& addressArray);

   /**
     * Get remote addresses.
     *
     * @param addressArray Reference to store NULL-terminated array of local addresses. The addresses are allocated automatically and have to be freed using deleteAddressList().
     * @return true, if addressEntries are sufficient; false otherwise.
     *
     * @see SocketAddress#deleteAddressList
     */
   bool getRemoteAddresses(SocketAddress**& addressArray);


   /**
     * Receive data.
     *
     * @param buffer Buffer to store data to.
     * @param bufferSize Size of data buffer; this will be overwritten with actual size of data content.
     * @param flags Flags; this will be overwritten with actual reception flags.
     * @param streamID Variable to store stream ID to.
     * @param protoID Variable to store protocol ID to.
     * @return error code (0 for success).
     */
   int receive(char*           buffer,
               size_t&         bufferSize,
               int&            flags,
               unsigned short& streamID,
               unsigned int&   protoID);

   /**
     * Receive data.
     *
     * @param buffer Buffer to store data to.
     * @param bufferSize Size of data buffer; this will be overwritten with actual size of data content.
     * @param flags Flags; this will be overwritten with actual reception flags.
     * @param streamID Variable to store stream ID to.
     * @param protoID Variable to store protocol ID to.
     * @param addressArray Reference to store NULL-terminated array of peer addresses. The addresses are allocated automatically and have to be freed using deleteAddressList(). Set NULL to skip creation of the address array.
     * @param status Variable to store SCTPNotification data to.
     * @return error code (0 for success).
     */
   int receiveFrom(char*             buffer,
                   size_t&           bufferSize,
                   int&              flags,
                   unsigned short&   streamID,
                   unsigned int&     protoID,
                   SocketAddress***  addressArray,
                   SCTPNotification& notification);


   /**
     * Send data.
     *
     * @param buffer Data to be sent.
     * @param length Length of data to be sent.
     * @param flags Flags.
     * @param streamID Stream ID.
     * @param protoID Protocol ID.
     * @return error code (0 for success).
     */
   int send(const char*          buffer,
            const size_t         length,
            const int            flags,
            const unsigned short streamID,
            const unsigned int   protoID);


   /**
     * Shutdown.
     */
   void shutdown();

   /**
     * Abort.
     */
   void abort();


   // ====== Notification flags =============================================
   /**
     * Get notification flags.
     *
     * @return Notification flags.
     */
   inline unsigned int getNotificationFlags() const;

   /**
     * Get notification flags.
     *
     * @param notificationFlags Notification flags.
     */
   inline void setNotificationFlags(const unsigned int notificationFlags);


   // ====== Association parameters =========================================
   /**
     * Get association parameters.
     *
     * @param associationParameters Reference to store association parameters.
     * @return true, if successful; false otherwise.
     */
   bool getAssociationParameters(SCTP_Association_Status& associationParameters);

   /**
     * Set association parameters.
     *
     * @param associationParameters Association parameters.
     * @return true, if successful; false otherwise.
     */
   bool setAssociationParameters(const SCTP_Association_Status& associationParameters);


   // ====== Path parameters ================================================
   /**
     * Get path parameters.
     *
     * @param pathIndex Path index (-1 for primary).
     * @param pathParameters Reference to store path parameters.
     * @return true, if successful; false otherwise.
     */
   bool getPathParameters(const int          pathIndex,
                          SCTP_PathStatus&   pathParameters);

   /**
     * Set path parameters.
     *
     * @param pathIndex Path index (-1 for primary).
     * @param pathParameters Path parameters.
     * @return true, if successful; false otherwise.
     */
   bool setPathParameters(const int              pathIndex,
                          const SCTP_PathStatus& pathParameters);

   /**
     * Get primary address.
     *
     * @return Primary address. This address has to be deleted after usage.
     */
   SocketAddress* getPrimaryAddress();

   /**
     * Set primary address of given association.
     *
     * @param primary Primary address.
     * @return true for success; false otherwise.
     */
   bool setPrimary(const SocketAddress& primary);

   /**
     * Set peer primary address of given association.
     *
     * @param primary Peer primary address.
     * @return true for success; false otherwise.
     */
   bool setPeerPrimary(const SocketAddress& primary);

   /**
     * Add address to given association.
     *
     * @param addAddress Address to be added.
     * @return true for success; false otherwise.
     */
   bool addAddress(const SocketAddress& addAddress);

   /**
     * Delete address from given association.
     *
     * @param delAddress Address to be deleted.
     * @return true for success; false otherwise.
     */
   bool deleteAddress(const SocketAddress& delAddress);


   // ====== Other parameters ===============================================
   /**
     * Get send buffer size.
     *
     * @param Send buffer size (-1 in case of error).
     */
   ssize_t getSendBuffer();

   /**
     * Set send buffer size.
     *
     * @param size Send buffer size.
     */
   bool setSendBuffer(const size_t size);

   /**
     * Get receive buffer size.
     *
     * @param Receive buffer size (-1 in case of error).
     */
   ssize_t getReceiveBuffer();

   /**
     * Set receive buffer size.
     *
     * @param size Receive buffer size.
     */
   bool setReceiveBuffer(const size_t size);

   /**
     * Get traffic class.
     *
     * @param streamID Stream ID (default: 0).
     * @return Traffic class (-1 in case of error).
     */
   int getTrafficClass(const int streamID = 0);

   /**
     * Set traffic class.
     *
     * @param trafficClass Traffic class.
     * @param streamID Stream ID (-1 for all streams, default).
     */
   bool setTrafficClass(const card8 trafficClass,
                        const int   streamID = -1);

   /**
     * Update condition types.
     */
   enum UpdateConditionTypes {
      UCT_Read   = 0,
      UCT_Write  = 1,
      UCT_Except = 2
   };

   /**
     * Get pointer to update condition.
     *
     * @param type Update condition type.
     * @return Update condition.
     */
   inline Condition* getUpdateCondition(const cardinal type);


   // ====== Protected data =================================================
   protected:
   SCTPAssociation(SCTPSocket*        socket,
                   const unsigned int associationID,
                   const unsigned int notificationFlags);


   // ====== Private data ===================================================
   private:
   SCTPSocket*           Socket;
   SCTPNotificationQueue InQueue;
   Condition             EstablishCondition;
   Condition             ShutdownCompleteCondition;
   Condition             ReadyForTransmit;
   Condition             ReadUpdateCondition;
   Condition             WriteUpdateCondition;
   Condition             ExceptUpdateCondition;

   card64                LastUsage;
   cardinal              UseCount;

   unsigned int          AssociationID;
   unsigned int          NotificationFlags;

   bool                  CommunicationUpNotification;
   bool                  CommunicationLostNotification;
   bool                  ShutdownCompleteNotification;
   bool                  IsShuttingDown;
};


}


#include "sctpassociation.icc"


#endif

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