gsdpport.cpp

来自「Symbian mobile os C++ GSDP编程」· C++ 代码 · 共 56 行

CPP
56
字号
// gsdpport.cpp
//
// Port allocator for the GSDP server
//
// Copyright (c) 2000-2002 Symbian Ltd.  All rights reserved.

#include "gsdpserver.h"

#include <f32file.h>
#include <s32file.h>

/*
	class CGsdpPortAllocator
*/

// construct/destruct

void CGsdpPortAllocator::ConstructL()
	{
	User::LeaveIfError(iFs.Connect());
	RFileReadStream stream;
	stream.PushL();
	TInt err=stream.Open(iFs, KGsdpPortAllocationFile, EFileRead | EFileWrite);
	if (!err)
		{
		iNextPortId=stream.ReadInt32L();
		}
	else if (err==KErrNotFound)
		{
		iNextPortId=0;
		NextPortId();
		}
	else
		User::Leave(err);
	CleanupStack::PopAndDestroy(); // stream
	}

CGsdpPortAllocator::~CGsdpPortAllocator()
	{
	iFs.Close();
	}

// utility

TUint32 CGsdpPortAllocator::NextPortId()
	{
	iNextPortId++;
	RFileWriteStream stream;
	stream.PushL();
	User::LeaveIfError(stream.Replace(iFs, KGsdpPortAllocationFile, EFileRead | EFileWrite));
	stream.WriteInt32L(iNextPortId);
	stream.CommitL();
	CleanupStack::PopAndDestroy(); // stream
	return iNextPortId;
	}

⌨️ 快捷键说明

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