/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include <eikgted.h>
#include <eikenv.h>
#include <stringloader.h>
#include <ImClientExam.rsg>
#include "SocketsEngine.h"
#include "TimeOutTimer.h"
#include "SocketsReader.h"
#include "SocketsWriter.h"
#include "Sockets.pan"
#include "UINotifier.h"
// STATIC MEMBER INITIALISATIONS
const TInt CSocketsEngine::KTimeOut = 30000000; // 30 seconds time-out
const TInt CSocketsEngine::KDefaultPortNumber = 7;
// ========================= MEMBER FUNCTIONS ==================================
// -----------------------------------------------------------------------------
// CSocketsEngine::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CSocketsEngine* CSocketsEngine::NewL( MUINotifier& aConsole )
{
CSocketsEngine* self = CSocketsEngine::NewLC( aConsole );
CleanupStack::Pop( self );
return self;
}
// -----------------------------------------------------------------------------
// CSocketsEngine::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CSocketsEngine* CSocketsEngine::NewLC( MUINotifier& aConsole )
{
CSocketsEngine* self = new ( ELeave ) CSocketsEngine( aConsole );
CleanupStack::PushL( self );
self->ConstructL();
return self;
}
// -----------------------------------------------------------------------------
// CSocketsEngine::CSocketsEngine()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CSocketsEngine::CSocketsEngine( MUINotifier& aConsole )
: CActive( EPriorityStandard ),
iConsole( aConsole ),
iPort( KDefaultPortNumber ),
iServerName( KDefaultServerName )
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CSocketsEngine::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CSocketsEngine::ConstructL()
{
ChangeStatus( ENotConnected );
// Start a timer
iTimer = CTimeOutTimer::NewL( EPriorityHigh, *this );
CActiveScheduler::Add( this );
// Open channel to Socket Server
User::LeaveIfError( iSocketServ.Connect() );
// Create socket read and write active objects
iSocketsReader = CSocketsReader::NewL( *this, iSocket );
iSocketsWriter = CSocketsWriter::NewL( *this, iSocket );
}
// -----------------------------------------------------------------------------
// CSocketsEngine::~CSocketsEngine()
// Destructor.
// -----------------------------------------------------------------------------
//
CSocketsEngine::~CSocketsEngine()
{
Cancel();
delete iSocketsReader;
iSocketsReader = NULL;
delete iSocketsWriter;
iSocketsWriter = NULL;
delete iTimer;
iTimer = NULL;
iSocketServ.Close();
}
// -----------------------------------------------------------------------------
// CSocketsEngine::ConnectL()
// Initiates connection of socket, using iServerName and iPort.
// -----------------------------------------------------------------------------
//
void CSocketsEngine::ConnectL()
{
// Initiate connection process
if ( iEngineStatus == ENotConnected )
{
TInetAddr addr;
if ( addr.Input( iServerName ) == KErrNone )
{
// server name is already a valid ip address
ConnectL( addr.Address() );
}
else // need to look up name using dns
{
// Initiate DNS
User::LeaveIfError( iResolver.Open( iSocketServ,
KAfInet,
KProtocolInetUdp ) );
// DNS request for name resolution
iResolver.GetByName( iServerName, iNameEntry, iStatus );
ChangeStatus( ELookingUp );
// Request time out
iTimer->After( KTimeOut );
SetActive();
}
}
}
// -----------------------------------------------------------------------------
// CSocketsEngine::ConnectL()
// Initiates a connect operation on a socket.
// -----------------------------------------------------------------------------
//
void CSocketsEngine::ConnectL( TUint32 aAddr )
{
// Initiate attempt to connect to a socket by IP address
if ( iEngineStatus == ENotConnected )
{
// Open a TCP socket
User::LeaveIfError( iSocket.Open( iSocketServ,
KAfInet,
KSockStream,
KProtocolInetTcp ) );
// Set up address information
iAddress.SetPort( iPort );
iAddress.SetAddress( aAddr );
// Initiate socket connection
iSocket.Connect( iAddress, iStatus );
ChangeStatus( EConnecting );
// Start a timeout
iTimer->After( KTimeOut );
SetActive();
}
}
// -----------------------------------------------------------------------------
// CSocketsEngine::Disconnect()
// Disconnects socket.
// -----------------------------------------------------------------------------
//
void CSocketsEngine::Disconnect()
{
__ASSERT_ALWAYS( iEngineStatus == EConnected,
User::Panic( KPanicSocketsEngine, ESocketsBadState ) );
// Cancel all outstanding operations
// Since we are connected, the only possibilities are read and write
iSocketsReader->Cancel();
iSocketsWriter->Cancel();
iSocket.Close();
ChangeStatus( ENotConnected );
}
// -----------------------------------------------------------------------------
// CSocketsEngine::DoCancel()
// Cancels any outstanding operation.
// -----------------------------------------------------------------------------
//
void CSocketsEngine::DoCancel()
{
iTimer->Cancel();
// Cancel appropriate request to socket
switch ( iEngineStatus )
{
case EConnecting:
iSocket.CancelConnect();
iSocket.Close();
break;
case ELookingUp:
// Cancel look up attempt
iResolver.Cancel();
iResolver.Close();
break;
default:
User::Panic( KPanicSocketsEngine, ESocketsBadStatus );
break;
}
ChangeStatus( ENotConnected );
}
// -----------------------------------------------------------------------------
// CSocketsEngine::WriteL()
// Writes data to socket.
// -----------------------------------------------------------------------------
//
void CSocketsEngine::WriteL( const TDesC8& aData )
{
if ( iEngineStatus == EConnected )
{
iSocketsWriter->IssueWriteL( aData );
}
}
// -----------------------------------------------------------------------------
// CSocketsEngine::Read()
// Initiates read of data from socket.
// -----------------------------------------------------------------------------
//
void CSocketsEngine::Read()
{
if ( ( iEngineStatus == EConnected ) && ( !iSocketsReader->IsActive() ) )
{
iSocketsReader->Start();
}
}
// -----------------------------------------------------------------------------
// CSocketsEngine::RunL()
// Called when operation completes.
// -----------------------------------------------------------------------------
//
void CSocketsEngine::RunL()
{
// Active object request complete handler.
// iEngineStatus flags what request wa
IM.rar_IM Symbian_s60_s60 3rd_symbian 3rd_symbian im
版权申诉
172 浏览量
2022-09-22
19:54:27
上传
评论
收藏 129KB RAR 举报
alvarocfc
- 粉丝: 105
- 资源: 1万+
最新资源
- HM2305B-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 基于52单片机、ADC0832、LCD1602、两个74HC393和一个74HC08的频率测量计 不能用,请私我
- HM2302-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- python实战项目-学生成绩管理系统(基础版)
- 微信小程序源码 实现查公交 滴滴公交 app 源码下载
- HM2302E-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 基于C#图片相似度比较,感知哈希算法
- VR开发的概要介绍与分析
- 自动驾驶定位系列教程七:点云畸变补偿.pdf
- HM2302D-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0