コード例 #1
0
ファイル: EventConnection.cpp プロジェクト: thwlxmyljz/AFN
int EventConnection::RecBuf()
{
	int errCode = YQER_OK;
	BOOL parseBuffer = FALSE;
	BOOL bufferedData = FALSE;
	BYTE msg[BUF_SIZE];
	BYTE* pMsg = msg;
	DWORD msgLen = (DWORD)bufferevent_read(bev, msg, BUF_SIZE-1 );
	LOG(LOG_INFORMATION,"rec pkg len[%d] data:%s",msgLen, TYQUtils::Byte2Hex(msg,msgLen).c_str());
	if (m_buffer){
		appendData2Buffer(msg,msgLen);
		pMsg = m_buffer;		
		msgLen = m_buffer_size;
		parseBuffer = TRUE;
	}
	while(msgLen > 0) 
	{
		IPackage* pkg = createPackage();
		if (!pkg)
			break;
		DWORD eatLen = 0;
		errCode = pkg->ParseProto(pMsg,msgLen,eatLen);
		pMsg += eatLen;
		msgLen -= eatLen;
		if (errCode == YQER_OK){
			//由handlePackage进行删除pkg
			errCode = handlePackage(pkg);
		}
		else if (errCode == YQER_PKG_Err(1)){
			//半截包,缓存起来继续接收
			YQLogMin("RecBuf,half pkg, bufferred and wait left data...");
			if (parseBuffer){
				memmove(m_buffer,pMsg,msgLen);
				m_buffer_size = msgLen;
			}
			else{
				m_buffer_size = msgLen;
				m_buffer = new BYTE[m_buffer_size];
				memcpy(m_buffer,pMsg,msgLen);
			}
			delete pkg;
			bufferedData = TRUE;
			break;
		}
		else{
			YQLogMin("RecBuf, pkg invalid!");
			delete pkg;
		}
	}

	if (!bufferedData && m_buffer){
		delete[] m_buffer;
		m_buffer = NULL;
		m_buffer_size = 0;
	}

	return errCode;
}
コード例 #2
0
ファイル: funciones.c プロジェクト: Hernandn/tp-2016-1c-so
void comunicacionConNucleo(Configuration* config, char* arch_programa){

	logDebug("Iniciando comunicacion con Nucleo.");

	int resp;
	int socket;
	int buffer;

	socket = abrirConexionInetConServer(config->ip_nucleo,config->puerto_nucleo);
	resp = leerSocketClient(socket, (char *)&buffer, sizeof(int));

	if (resp < 1)
	{
			printf ("Me han cerrado la conexión\n");
			exit(-1);
	}

	logInfo("Soy la consola %d\n",buffer);


	//handshake con Nucleo
	logDebug("Iniciando Handshake con Nucleo.");
	handshake(socket);

	//iniciar programa
	logDebug("Iniciando programa AnSISOP.");
	iniciarProgramaAnsisop(socket,arch_programa);

	int continua = 1;
	while (continua)
	{
		Package* package = createPackage();
		if(recieve_and_deserialize(package,socket) > 0){
			if(package->msgCode==PROGRAMA_FINALIZADO){
				continua = 0;
				logDebug("Nucleo me informa que finalizo mi programa");
			} else if(package->msgCode==GENERIC_EXCEPTION){
				continua = 0;
				logDebug("Nucleo me informa: %s",package->message);
			} else if(package->msgCode==PRINT_VARIABLE){
				int valor = deserializar_imprimirVariable_consola(package->message);
				printf("print> %d\n",valor);
			} else if(package->msgCode==PRINT_TEXT){
				printf("print> %s\n",package->message);
			}
		}
		destroyPackage(package);
	}

	close(socket);
}
コード例 #3
0
ファイル: package.c プロジェクト: caizongchao/open-mika
/**
 ** Get the w_Package for a class, creating it if it does not already exist.
 */
w_package getPackageForClazz(w_clazz clazz, w_instance loader) {
  w_string class_name = clazz->dotified;
  w_instance effective_loader = loader ? loader : systemClassLoader;
  w_hashtable ht = loader2packages(effective_loader);
  w_string package_name;
  w_int i;
  w_int j;
  w_package p;

  for (i = 0; string_char(class_name, i) == '['; ++i); 
  for (j = string_length(class_name) - 1; string_char(class_name, j) != '.'; --j); 
  package_name = j > i ? w_substring(class_name, i, j - i) : registerString(string_empty);
  ht_lock(ht);
  p = (w_package)ht_read_no_lock(ht, (w_word)package_name);
  if (!p) {
    p = createPackage(package_name, effective_loader);
    ht_write_no_lock(ht, (w_word)package_name, (w_word)p);
  }
  clazz->package = p;
  ht_unlock(ht);
  deregisterString(package_name);

  return p;
}