⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socketswriter.h

📁 Symbian 手机网络通信程序 sockets-vc
💻 H
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */


#ifndef __SOCKETSWRITER_H__
#define __SOCKETSWRITER_H__

// INCLUDES
#include <in_sock.h>
#include "TimeOutNotifier.h"

// FORWARD DECLARATIONS
class CTimeOutTimer;
class MEngineNotifier;

// CLASS DECLARATION
/**
* CSocketsWriter
*  This class handles writing data to the socket.
*  Data to be written is accumulated in iTransferBuffer,
*  and is then transferred to iWriteBuffer for the actual
*  write to the socket.
*/
class CSocketsWriter : public CActive, public MTimeOutNotifier
    {
    public: // Constructors and destructors

        /**
        * NewL.
        * Two-phased constructor.
        * Creates a CSocketsWriter object using two phase construction,
        * and returns a pointer to the created object.
        * @param aEngineNotifier An observer for status reporting.
        * @param aSocket Socket to write to.
        * @return A pointer to the created instance of CSocketsWriter.
        */
        static CSocketsWriter* NewL( MEngineNotifier& aEngineNotifier,
                                     RSocket& aSocket );

        /**
        * NewLC.
        * Two-phased constructor.
        * Creates a CSocketsWriter object using two phase construction,
        * and returns a pointer to the created object.
        * @param aEngineNotifier An observer for status reporting.
        * @param aSocket Socket to write to.
        * @return A pointer to the created instance of CSocketsWriter.
        */
        static CSocketsWriter* NewLC( MEngineNotifier& aEngineNotifier,
                                      RSocket& aSocket );

        /**
        * ~CSocketsWriter.
        * Destructor.
        * Destroys the object and release all memory objects.
        */
        virtual ~CSocketsWriter();

    public: // New functions

        /**
        * IssueWrite.
        * Writes the data to the socket ( buffered ).
        * @param aData The data to be written.
        */
        void IssueWriteL( const TDesC8& aData );

    public: // Functions from base classes

        /**
        * From MTimeOutNotifier, TimerExpired.
        * Handles a timeout event.
        */
        void TimerExpired();

    protected: // Functions from base classes

        /**
        * From CActive, DoCancel.
        * Cancels any outstanding operation.
        */
        void DoCancel();

        /**
        * From CActive, RunL.
        * Called when operation completes.
        */
        void RunL();

    private: // Constructors and destructors

        /**
        * CSocketsWriter.
        * C++ default constructor.
        * Performs the first phase of two phase construction.
        * @param aEngineNotifier An observer for status reporting.
        * @param aSocket Socket to write to.
        */
        CSocketsWriter( MEngineNotifier& aEngineNotifier, RSocket& aSocket );

        /**
        * ConstructL.
        * 2nd phase constructor.
        */
        void ConstructL();

    private: // New functions

        /**
        * SendNextPacket.
        * Handles a 'write buffer empty' situation.
        */
        void SendNextPacket();

    private: // Constants

        /**
        * KWriteBufferSize, the size of the write buffer in bytes.
        */
        enum { KWriteBufferSize = 20 };

        /**
        * KTimeOut, the maximum time allowed for a write to complete.
        */
        static const TInt KTimeOut;

    private: // Enumerations

        /**
        * TWriteState, records whether a write request is pending.
        *   - ESending  A write request is pending with the socket server.
        *   - EWaiting  The idle state for this object.
        *
        */
        enum TWriteState
            {
            ESending,
            EWaiting
            };

    private: // Data

        /**
        * iSocket, the socket to write to.
        */
        RSocket& iSocket;

        /**
        * iEngineNotifier, an observer for status reporting.
        */
        MEngineNotifier& iEngineNotifier;

        /**
        * iTransferBuffer, accumulate data to send in here.
        */
        TBuf8<KWriteBufferSize> iTransferBuffer;

        /**
        * iWriteBuffer, holds data currently being sent to socket.
        */
        TBuf8<KWriteBufferSize> iWriteBuffer;

        /**
        * iTimer, a timer used to cancel an outstanding write
        *         after a predefined timeout.
        * Owned by CSocketsWriter object.
        */
        CTimeOutTimer* iTimer;

        /**
        * iTimeOut, the timeout to use.
        */
        TInt iTimeOut;

        /**
        * iWriteStatus, the state of this active object.
        */
        TWriteState iWriteStatus;
    };

#endif // __SOCKETSWRITER_H__

// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -