Example #1
0
bool CShare::CreateShare(const char* ID, const int &size)
{
	DestroyShare();
	char Map_ID[256];
	char Read_ID[256];
	char Write_ID[256];

  sprintf(Map_ID, "%s_Map", ID);
  if (strlen(Map_ID) > 250)
  {
  	printf("Error: CShare::CreateShare with ID too long. It won't be able to connect Catcher!\n");
  	return false;
  }
  
  sprintf(Read_ID, "%s_Read", ID);
  sprintf(Write_ID, "%s_Write", ID);
  
	m_hMap = ::CreateFileMapping(	(HANDLE)0xFFFFFFFF,
									0,					// Security
									PAGE_READWRITE,
									0,					// size --> high order
									size,				// size --> low order
									Map_ID		// map ID
								);
	if( m_hMap==NULL )
		goto Create_Failed;

	m_pSharedData = (char *)::MapViewOfFile(m_hMap,
									FILE_MAP_WRITE,
									0,				// offset high
									0,				// offset low
									0				// number of bytes, 0-->entire
									);
	if( m_pSharedData==NULL )
		goto Create_Failed;

	Data_Read[0] = ::CreateEvent(NULL, TRUE, FALSE, Read_ID);
	if( Data_Read[0]==NULL )
		goto Create_Failed;

	Data_Read[1] = ::CreateEvent(NULL, TRUE, FALSE, NULL);
	if( Data_Read[1]==NULL )
		goto Create_Failed;

	Data_Written[0] = ::CreateEvent(NULL, TRUE, FALSE, Write_ID);
	if( Data_Written[0]==NULL )
		goto Create_Failed;
	Data_Written[1] = Data_Read[1];

	m_size = size - sizeof(int);
	return true;

Create_Failed:
	DestroyShare();
	return false;
}
Example #2
0
void ShareMng::Cleanup()
{
	int			i, j;
	Time_t		cur_time = Time();
	ShareInfo	*info, *next;

	for (info=Top(); info; info=next) {
		next = Next(info);
		if (!*(_int64 *)&info->attachTime) continue;

		int	clip_host = 0;
		for (i=0; i < info->fileCnt; i++) {
			for (j=0; j < info->hostCnt; j++) {
				if (info->transStat[info->fileCnt * j + i] == TRANS_BUSY) break;
				if (info->transStat[info->fileCnt * j + i] == TRANS_INIT) {
					if (GET_MODE(info->fileInfo[i]->Attr()) != IPMSG_FILE_CLIPBOARD) break;
					if (info->host[j]->hostStatus & IPMSG_CLIPBOARDOPT) {
						clip_host++;
					}
				}
			}
			if (j != info->hostCnt) break;
		}
		if (i == info->fileCnt && j == info->hostCnt) {
			if (clip_host > 0 && FileTime2UnixTime(&info->attachTime) + 1200 > cur_time) continue;
			DestroyShare(info);
		}
	}
}
Example #3
0
BOOL ShareMng::EndHostShare(int packetNo, HostSub *hostSub, FileInfo *fileInfo, BOOL done)
{
	ShareInfo *info = Search(packetNo);

	if (info == NULL)
		return	FALSE;

	for (int i=0; i < info->hostCnt; i++)
	{
		if (IsSameHostEx(&info->host[i]->hostSub, hostSub))
		{
			if (fileInfo)
			{
				info->transStat[info->fileCnt * i + GetFileInfoNo(info, fileInfo)] = done ? TRANS_DONE : TRANS_INIT;
				if (!done)
					return	statDlg->Refresh(), TRUE;
				for (int j=0; j < info->fileCnt; j++)
					if (info->transStat[info->fileCnt * i + j] != TRANS_DONE)
						return	statDlg->Refresh(), TRUE;
			}
			if (info->host[i]->RefCnt(-1) == 0)
			{
				cfg->fileHosts.DelHost(info->host[i]);
				delete info->host[i];
			}
			memmove(info->host + i, info->host + i + 1, (--info->hostCnt - i) * sizeof(Host *));
			memmove(info->transStat + info->fileCnt * i, info->transStat + info->fileCnt * (i + 1), (info->hostCnt - i) * info->fileCnt);
			if (info->hostCnt == 0)
				DestroyShare(info);
			return	statDlg->Refresh(), TRUE;
		}
	}
	return	FALSE;
}
Example #4
0
CShare::~CShare()
{
	DestroyShare();
}