Beispiel #1
0
int ReadBuf(char *program_name, ui08 *pBuf, int len)
{
  if (len > bufLen && bufLen)
  {
    memcpy( pBuf, pExtract0, bufLen);
    pBuf   += bufLen;
    len    -= bufLen;
    bufLen  = 0;
  }

  if (!bufLen)
  {
    if ((bufLen = ReadMsg(program_name, buff)) == -1)
      return( -1);

    pExtract0 = buff;
  }

  if (len)
  {
    memcpy(pBuf, pExtract0, len);

    pExtract0 += len;
    bufLen    -= len;
  }

  return(len);
}
void Server::ClientToClinet(const SOCKET& ClientSock, char* buffer)
{
	//	std::lock_guard<std::mutex> guard(ClientMutex);
	int tmpID = 0, i;
	int index = 0;
	bool flagConnect = false;
	if (ReadMsg(ClientSock, tmpID, buffer))
	{
		SendCommandMsg(ClientSock, TakeIP);
		std::lock_guard<std::mutex> guard(ClientMutex);
		for (i = 0; i < m_AllClients.size(); i++)
		{
			if (m_AllClients[i].IDSock == tmpID)
			{
				strcpy(buffer, inet_ntoa(m_AllClients[i].client_addr.sin_addr));
				send(ClientSock, (char *)&buffer[0], BUFFER_SIZE, 0);
				memset(buffer, '\0', BUFFER_SIZE);
				flagConnect = true;
				break;
			}
		}
		if (!flagConnect)
			SendCommandMsg(ClientSock, Cancel);
	}

}
bool Server::GetListFromClient(const SOCKET& ClientSock, const int& IDclient, char* buffer, std::string& tmpAllClientFiles)
{
	tmpAllClientFiles.clear();
	bool flagConnect = false;
	int cm = 0;
	int size = 0;
	SendCommandMsg(ClientSock, SendListToServer);
	if (ReadMsg(ClientSock, cm, buffer))
	{
		if (cm == Ok)
		{
			SendCommandMsg(ClientSock, Ok);
			if (ReadMsg(ClientSock, size, buffer))
			{
				SendCommandMsg(ClientSock, Ok);
				flagConnect = true;
				tmpAllClientFiles = std::to_string(IDclient);
				tmpAllClientFiles += ':';
				do
				{
					if (recv(ClientSock, (char *)&buffer[0], BUFFER_SIZE, 0) != SOCKET_ERROR)
					{
						tmpAllClientFiles += buffer;
						size -= BUFFER_SIZE;
						memset(buffer, '\0', BUFFER_SIZE);
					}
					else
					{
						flagConnect = false;
						break;
					}
				} while (size > 0);
				memset(buffer, '\0', BUFFER_SIZE);
				if (flagConnect)
				{
					std::cout << tmpAllClientFiles << "\n";
					WriteInfoFromClient(IDclient, tmpAllClientFiles);//записываем информацию от клиента в вектор данных сервера						
					return true;
				}
			}
		}
	}
	return false;
}
Beispiel #4
0
int main(int argc, char **argv)
{
    if (argc == 1)
    {
        printf("usage: ntlmread <msg>\n");
        return -1;
    }
    ReadMsg(argv[1], (PRUint32) strlen(argv[1]));
    return 0;
}
Beispiel #5
0
//定时器触发(从串口读取数据)
void Gprs::timeout_slot()
{
	if(fd)
    	{
		if(read(fd,buff,sizeof(buff))!=0)
		{  
                        qDebug()<<QString(buff);
	       		ReadMsg(QString(buff));
			resetBuff();
		}
	}	
}
void Server::SendListToCLient(const SOCKET& ClientSock, const int& IDclient, char* buffer)
{
	std::string tmpAllClientFiles = "";
	int cm = 0, i = 0;
	int size = 0;
	int BytesSend = 0;
	GetAllList(tmpAllClientFiles, IDclient);
	if (tmpAllClientFiles.size() > 0)
	{
		SendCommandMsg(ClientSock, SetListClients);
		if (ReadMsg(ClientSock, cm, buffer))
		{
			if (cm == Ok)
			{
				size = tmpAllClientFiles.size();
				//Send size of allFiles list
				SendCommandMsg(ClientSock, size);
				if (ReadMsg(ClientSock, cm, buffer))
				{
					if (cm == Ok)
					{
						do
						{
							strcpy(buffer, tmpAllClientFiles.c_str());
							send(ClientSock, (char *)&buffer[0], BUFFER_SIZE, 0);
							//отправка всего списка клиенту
							//send(ClientSock, (char *)&tmpAllClientFiles.c_str()[BytesSend], BUFFER_SIZE, 0);

							BytesSend += BUFFER_SIZE;
							size -= BUFFER_SIZE;
						} while (size > 0);
						memset(buffer, '\0', BUFFER_SIZE);
					}
				}
			}
		}
	}
}
void Server::GetNewListFromClient(const SOCKET& ClientSock, int& IDclient, char* buffer, std::string& tmpAllClientFiles, bool flagConnect)
{
	tmpAllClientFiles.clear();
	int cm = 0;
	int size = 0;
	SendCommandMsg(ClientSock, GetNewList);
	if (ReadMsg(ClientSock, cm, buffer))
	{
		if (cm == Ok)
		{
			if (GetListFromClient(ClientSock, IDclient, buffer, tmpAllClientFiles))
				flagConnect = true;
		}
		SendNewListToAllClients(IDclient, buffer, tmpAllClientFiles);
	}
}
Beispiel #8
0
int RunTest(){
	int place = 0;
	int BUF_SIZE = 80;
	char buf[BUF_SIZE]; /* Input buffer */
	const int fd = 4;
	fputs ("Started Dispatcher waiting input\n", stderr);
	FILE *fp;
	fp = fopen("/Users/dupper/Desktop/dupTestCode/in.txt", "rt"); /* Make fd into FILE* for reading */
		 fputs("Found the file descriptor\n", stderr);
	if (fp == NULL) {
				fprintf(stderr,"BAD FILE DESCRIPTOR %d TO CONFIG\n", fd);
		 		return EXIT_FAILURE;
	 }
	while(fgets(buf, 80, fp) != NULL)
	 {
		fprintf(stderr, "READING FILE\n");
		 /* get a line, up to 80 chars from fr.  done if NULL */
		 sscanf (buf, "%d", &place);
		 fprintf(stderr,"%d:Convert place number from string to int\n", place);
		 /* convert the string to a long int */
		 fprintf (stderr, "%d,%d\n", place,place);
	 }



	fprintf(stderr,"%d:Read config file\n", place);
	fclose(fp);
	int resultWrite =-1;
	int resultRead =-1;
	if(place==1){
		resultWrite =WriteMsg("Hello world\n", place);
	}else{
		resultRead = ReadMsg(place);
	}
if((resultRead == -1 && resultWrite== EXIT_SUCCESS) || (resultWrite == -1 && resultRead== EXIT_SUCCESS)){
	fprintf(stderr,"%d:Success\n", place);
	return EXIT_SUCCESS;
}else{
	fprintf(stderr,"%d:Failure\n", place);
	return EXIT_FAILURE;
}


}
Beispiel #9
0
/**
 * GetCommand - 获取命令串
 * @cmd:	希望取得命令串的命令字
 * @CMD:	保存命令串的缓存区
 */
void CEngine::GetCommand(char *cmd,char *CMD)
{
	int dwSize,pos,len,i;
	len=strlen(cmd);
	while(1)
	{
		dwSize = ReadMsg(readBuffer + indexBuf, BUFSIZE);
		if (dwSize == 0)//读取信息出错
		{
			CMD[0] = '\0';//返回空命令串
			return;
		}
		indexBuf+=dwSize;
		if(dwSize==BUFSIZE)//当 dwSize=BUFSIZE 时,具有字符截断的可能
		{
			pos=getcmd(readBuffer,indexBuf,cmd);
			if(pos==-1)//未找到命令字,进行防截断处理
			{
				for(i=indexBuf-1;indexBuf-i<len&&i>=0;i--)
				{
					if (readBuffer[i] == ' ' || readBuffer[i] == '\n' || readBuffer[i] == '\t' || readBuffer[i] == '\0')//向前寻找间隔符
						break;
				}
				if(indexBuf-i>=len)//最后串长度大于关键字长度,必不是关键字
					indexBuf=0;
				else
				{
					memmove(readBuffer, readBuffer + (i + 1), indexBuf - i - 1);
					indexBuf=indexBuf-i-1;
				}
			}
			else
			{
				for(i=pos+len+1;i<indexBuf;i++)
				{
					if (readBuffer[i] == '\r' || readBuffer[i] == '\n' || readBuffer[i] == '\t' || readBuffer[i] == '\0')//命令字后有完整参数,windows平台下从引擎读入的数据中'\n'前包含'\r'。一条命令不以' '作为结束标志。
					{
						memcpy(CMD,readBuffer+pos,i-pos);
						CMD[i-pos]='\0';
						memmove(readBuffer, readBuffer + (i + 1), indexBuf - i - 1);
						indexBuf=indexBuf-i-1;
						return;
					}
				}
				//命令字后无完整参数,保留关键字并继续读取引擎信息
				memmove(readBuffer, readBuffer + pos, indexBuf - pos);
				indexBuf=indexBuf-pos;
			}
		}
		else
		{
			pos=getcmd(readBuffer,indexBuf,cmd);
			if(pos==-1)//未找到命令字,舍弃串
				indexBuf=0;
			else
			{
				for(i=pos+len+1;i<indexBuf;i++)
				{
					if (readBuffer[i] == '\r' || readBuffer[i] == '\n' || readBuffer[i] == '\t' || readBuffer[i] == '\0')//命令字后有完整参数,windows平台下从引擎读入的数据中'\n'前包含'\r'。一条命令不以' '作为结束标志。
					{
						memcpy(CMD,readBuffer+pos,i-pos);
						CMD[i-pos]='\0';
						memmove(readBuffer, readBuffer + (i + 1), indexBuf - i - 1);
						indexBuf=indexBuf-i-1;
						return;
					}
				}
				//命令字后无完整参数,保留关键字并继续读取引擎信息
				memmove(readBuffer, readBuffer + pos, indexBuf - pos);
				indexBuf=indexBuf-pos;
			}
		}
	}
}
void SQDbgServer::BusyWait()
{
	while( !ReadMsg() )
		sleep(0);
}