Пример #1
0
status_t
Inode::OpenAttr(const char* _name, int mode, OpenAttrCookie* cookie,
	bool create, int32 type)
{
	ASSERT(_name != NULL);
	ASSERT(cookie != NULL);

	(void)type;

	status_t result = LoadAttrDirHandle();
	if (result != B_OK)
		return result;

	char* name = AttrToFileName(_name);
	if (name == NULL)
		return B_NO_MEMORY;
	MemoryDeleter nameDeleter(name);

	OpenDelegationData data;
	data.fType = OPEN_DELEGATE_NONE;

	OpenState* state = new OpenState;
	if (state == NULL)
		return B_NO_MEMORY;

	state->fFileSystem = fFileSystem;
	result = NFS4Inode::OpenAttr(state, name, mode, &data, create);
	if (result != B_OK) {
		delete state;
		return result;
	}

	fFileSystem->AddOpenFile(state);

	cookie->fOpenState = state;
	cookie->fFileSystem = fFileSystem;
	cookie->fMode = mode;

	if (data.fType != OPEN_DELEGATE_NONE) {
		Delegation* delegation
			= new(std::nothrow) Delegation(data, this, state->fClientID, true);
		if (delegation != NULL) {
			delegation->fInfo = state->fInfo;
			delegation->fFileSystem = fFileSystem;
			state->fDelegation = delegation;
			fFileSystem->AddDelegation(delegation);
		}
	}

	if (create || (mode & O_TRUNC) == O_TRUNC) {
		struct stat st;
		st.st_size = 0;
		WriteStat(&st, B_STAT_SIZE, cookie);
	}

	return B_OK;
}
Пример #2
0
//-----------------------------------------------------------------------------
void USER_IMPL::Run()
{
STG_LOCKER lock(&mutex);

if (stgTime > static_cast<time_t>(lastWriteStat + settings->GetStatWritePeriod()))
    {
    printfd(__FILE__, "USER::WriteStat user=%s\n", GetLogin().c_str());
    WriteStat();
    }
if (creditExpire.ConstData() && creditExpire.ConstData() < stgTime)
    {
    WriteServLog("User: %s. Credit expired.", login.c_str());
    credit = 0;
    creditExpire = 0;
    WriteConf();
    }

if (passive.ConstData()
    && (stgTime % 30 == 0)
    && (passiveTime.ModificationTime() != stgTime))
    {
    passiveTime = passiveTime + (stgTime - passiveTime.ModificationTime());
    printfd(__FILE__, "===== %s: passiveTime=%d =====\n", login.c_str(), passiveTime.ConstData());
    }

if (!authorizedBy.empty())
    {
    if (connected)
        property.Stat().lastActivityTime = stgTime;

    if (!connected && IsInetable())
        Connect();

    if (connected && !IsInetable())
        {
        if (disabled)
            Disconnect(false, "disabled");
        else if (passive)
            Disconnect(false, "passive");
        else
            Disconnect(false, "no cash");
        }

    if (stgTime - lastScanMessages > 10)
        {
        ScanMessage();
        lastScanMessages = stgTime;
        }
    }
else
    {
    if (connected)
        Disconnect(false, "not authorized");
    }

}
Пример #3
0
Файл: u.c Проект: Bhoft/lg.srv
void	_ShowStatistic( SkLine *l, int ashtml )
{
	int		i;
	int		numcl=0;

	for( i=0; i < 30; i++ )
	{
		if ( cl_array[i] != 0 )
			numcl++;
	}
	WriteStat(l,ashtml,"Clients connected (all)   : %d",numcl);
	for( i=0; i<30; i++ )
	{

		if ( cl_array[i] == 0 )
			continue;
		switch( cl_array[i]->data->mode )
		{
		case MODE_UNKNOWN :
			WriteStat(l,ashtml," [%d] - protocol             : ?",i);
			break;
		case MODE_LOG :
			WriteStat(l,ashtml," [%d] - protocol             : LOG",i);
			break;
		case MODE_HTTP :
			WriteStat(l,ashtml," [%d] - protocol             : HTTP",i);
			break;
		}
	}
	WriteStat(l,ashtml,"noWrongSize (>20kBytes)   : %d",noWrongSize);
	WriteStat(l,ashtml,"MaxLog (def:48)           : %d",maxlog);
}
Пример #4
0
int CMainCtrl::Run()
{
	while(1)
	{
		if(Flag_Exit == m_iRunFlag)
		{
			TLib_Log_LogMsg("Server Exit!\n");
			return 0;
		}
		
		if(Flag_ReloadCfg == m_iRunFlag)
		{
			ReadCfgFile(m_stConfig.m_szCfgFileName);
			TLib_Log_LogMsg("reload config file ok!\n");
			m_iRunFlag = 0;
		}

		// 1ms
		if(m_Svr2MePipe.GetCodeLength() == 0)
			m_stEPollFlow.Wait(1);
		else
			m_stEPollFlow.Wait(0);		

		//每次循环取一次
		gettimeofday(&m_tNow,NULL);
		
		//读取客户端包
		CheckClientMessage();    
		
		//读取服务器端包
		CheckSvrMessage(); 

		//检测通讯超时
		CheckTimeOut();    

		//写统计
		WriteStat();
	}
	
	return 0;
}
Пример #5
0
status_t
Inode::Open(int mode, OpenFileCookie* cookie)
{
	ASSERT(cookie != NULL);

	MutexLocker locker(fStateLock);

	OpenDelegationData data;
	data.fType = OPEN_DELEGATE_NONE;
	if (fOpenState == NULL) {
		RevalidateFileCache();

		OpenState* state = new(std::nothrow) OpenState;
		if (state == NULL)
			return B_NO_MEMORY;

		state->fInfo = fInfo;
		state->fFileSystem = fFileSystem;
		state->fMode = mode & O_RWMASK;
		status_t result = OpenFile(state, mode, &data);
		if (result != B_OK) {
			delete state;
			return result;
		}

		fFileSystem->AddOpenFile(state);
		fOpenState = state;
		cookie->fOpenState = state;
		locker.Unlock();
	} else {
		fOpenState->AcquireReference();
		cookie->fOpenState = fOpenState;
		locker.Unlock();

		int newMode = mode & O_RWMASK;
		int oldMode = fOpenState->fMode & O_RWMASK;
		if (oldMode != newMode && oldMode != O_RDWR) {
			if (oldMode == O_RDONLY)
				RecallReadDelegation();

			status_t result = OpenFile(fOpenState, O_RDWR, &data);
			if (result != B_OK) {
				locker.Lock();
				ReleaseOpenState();
				return result;
			}
			fOpenState->fMode = O_RDWR;
		} else {
			int newMode = mode & O_RWMASK;
			uint32 allowed = 0;
			if (newMode == O_RDWR || newMode == O_RDONLY)
				allowed |= R_OK;
			if (newMode == O_RDWR || newMode == O_WRONLY)
				allowed |= W_OK;

			status_t result = Access(allowed);
			if (result != B_OK) {
				locker.Lock();
				ReleaseOpenState();
				return result;
			}
		}
	}

	if ((mode & O_TRUNC) == O_TRUNC) {
		struct stat st;
		st.st_size = 0;
		WriteStat(&st, B_STAT_SIZE);
		file_cache_set_size(fFileCache, 0);
	}

	cookie->fFileSystem = fFileSystem;
	cookie->fMode = mode;
	cookie->fLocks = NULL;

	if (data.fType != OPEN_DELEGATE_NONE) {
		Delegation* delegation
			= new(std::nothrow) Delegation(data, this, fOpenState->fClientID);
		if (delegation != NULL) {
			delegation->fInfo = fOpenState->fInfo;
			delegation->fFileSystem = fFileSystem;
			SetDelegation(delegation);
		}
	}

	return B_OK;
}