示例#1
0
void Win32App::v_run()
{
	bool ret = init_window();
	v_init();

	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));
	while (ret)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		if (msg.message == WM_QUIT) {
			ret = false;
		}
		else
		{
			v_update();
			v_render();
			ret = true;
		}

	}
	v_shutdown();

}
示例#2
0
void D3DApp::v_run()
{
	bool ret = init_window();
	v_init();

#ifdef USE_CAMERA
	D3DSphereCamera::getInstance()->init(m_hWnd);
	D3DEulerCamera::getInstance()->init(m_hInstance, m_hWnd);
#endif

	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));
	while (ret)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		if (msg.message == WM_QUIT) {
			ret = false;
		}
		else
		{
			v_update();
			v_render();
			ret = true;
		}

	}
	v_shutdown();

}
示例#3
0
文件: v_api.c 项目: pqhwan/TCP
/*
1. shutdown read :
	a) added read_lock to sturct socket (bool)
	b) v_socket will initialize the read_lock to 0
	c) whenever v_shutdown is called with read_lock only, the followiing happens :
		i) set the read_lock = 1
		ii) When v_read() reads the data from the buffer, CB_WRIE nbytes (read) 0's 
		So the pointer is fine and adwin is shrinking constantly
*/
int v_shutdown(socket_t *socket, int shut_type) {

	printf("IN SHUTDOWN\n");

	//1. get the socket by id
	socket_t *so = fd_lookup(socket);
	if(so == NULL) return 0; //no such socket

	if (shut_type == SHUTDOWN_READ) {
		
		printf("\t Request for shutdown read\n");
		so->read_lock = 1; 

	}

	/******************* CLOSING RECIVING WINDOW ***************
	* Send FIN
	* 1. if current state == Established
	*	-> change to FIN_WAIT_1
	* 2. if current state == CLOSE_WAIT (peer already closed down)
	*	-> change to LAST_ACK
	***********************************************************/

	else if (shut_type == SHUTDOWN_WRITE) {
		printf("\t Request for shutdown write\n");
		if (so->state == ESTABLISHED) {
			set_socketstate(so,FIN_WAIT_1);
			tcp_send_handshake(FIN_WAIT_1, so);

		}
		else if (so->state == CLOSE_WAIT) {
			printf("a\n");
			set_socketstate(so, LAST_ACK);
			printf("b\n");
			tcp_send_handshake(LAST_ACK, so);
		}
		
		
	}
	else if (shut_type == SHUTDOWN_BOTH) {
		printf("Request for shutdown read and write\n");		
		v_shutdown(so->id, SHUTDOWN_READ); //recursion huh?
		v_shutdown(so->id, SHUTDOWN_WRITE);

	}
	return 0;
}
示例#4
0
文件: v_api.c 项目: pqhwan/TCP
/******************** v_cose() ********************************
transmit all the packets not yet transmitted, then close the connection
***************************************************************/
int v_close(int socket) {

	socket_t *so = fd_lookup(socket);
	
	if(so == NULL) {
		printf(_RED_"v_close: socket %d does not exist"_NORMAL_"\n", socket);
		return -EBADF;
	}
#ifdef DEBUG
	printf(_BLUE_"v_close: socket %d "_NORMAL_"\n", socket);
#endif

	//while(!CB_EMPTY(socket->sendw->buf)){
	//	v_shutdown(socket, SHUTDOWN_READ);
	//}
	
	if(so->state == LISTENING) return 0;


	//this hack doesn't work sometimes
	//for example, retransmission queue being empty doesn't always mean
	//that everything has been sent (sent packet might have been in the process of
	//being queued for retransmission)
	
	seg_t *el;
	int count;
	DL_COUNT(so->sendw->retrans_q_head,el,count);
	int sum = count + CB_SIZE(so->sendw->buf) + CB_SIZE(so->recvw->buf)
		+ so->recvw->oor_q_size;
	int newsum = sum;
	//TODO shut down sending window
	while(!CB_EMPTY(so->sendw->buf) || !CB_EMPTY(so->recvw->buf)
		|| count || so->recvw->oor_q_size){

		#ifdef DEBUG
		if(sum != newsum){
			printf(_BRED_"V_CLOSED STALLED-----------\n[retransq %d], [sendwindow %d], [recvwindow %d], [oorq %d]\n"_NORMAL_,
				count, CB_SIZE(so->sendw->buf), CB_SIZE(so->recvw->buf), so->recvw->oor_q_size);
			sum = newsum;
		}
		#endif

		newsum = count + CB_SIZE(so->sendw->buf) + CB_SIZE(so->recvw->buf)
			+ so->recvw->oor_q_size;
		DL_COUNT(so->sendw->retrans_q_head,el,count);
	}

	//TODO memory stuff
	printf(_BRED_"---CANCELING THREAD, DELETING SOCKET---\n"_NORMAL_);
	v_shutdown(socket, SHUTDOWN_BOTH);
	pthread_cancel(so->th);
	HASH_DELETE(hh1, fd_list, so);

	return 0;

}
示例#5
0
void OGLApp::v_run()
{	
	app = std::make_shared<OGLApp>(*this);

	std::cout << "Starting GLFW context" << std::endl;
	if (!glfwInit())
	{
		std::cerr << "Failed to initialize GLFW" << std::endl;
		return;
	}
	sw = WindowInfo::getInstance()->getWidth();
	sh = WindowInfo::getInstance()->getHeight();

	int MonitorCount;
	GLFWmonitor ** monitors = glfwGetMonitors(&MonitorCount);

#ifdef _DEBUG
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
#endif
	//glfwGetPrimaryMonitor(), 
	pWindow = glfwCreateWindow(sw, sh, WindowInfo::getInstance()->getTitle().c_str(), nullptr, nullptr);
	glfwSetWindowPos(pWindow, WindowInfo::getInstance()->getPosX() - 100, WindowInfo::getInstance()->getPosY() - 100);
	glfwMakeContextCurrent(pWindow);

	glfwSetCursorPosCallback(pWindow, glfw_mouse);          // - Directly redirect GLFW mouse position events to AntTweakBar
	glfwSetScrollCallback(pWindow, glfw_scroll);    // - Directly redirect GLFW mouse wheel events to AntTweakBar
	glfwSetKeyCallback(pWindow, glfw_key);                         // - Directly redirect GLFW key events to AntTweakBar
#ifdef USE_ANT
	glfwSetMouseButtonCallback(pWindow, glfw_mouseButton); // - Directly redirect GLFW mouse button events to AntTweakBar
	glfwSetCharCallback(pWindow, glfw_char);                      // - Directly redirect GLFW char events to AntTweakBar
#endif
	glfwSetWindowSizeCallback(pWindow, glfw_resize);


	//glfwSetInputMode(pWindow, GLFW_STICKY_KEYS, GL_TRUE);
	// GLFW Options
    //glfwSetInputMode(pWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);


	if (pWindow == NULL) {
		std::cerr << "Failed to create GLFW pWindow" << std::endl;
		glfwTerminate();
		return;
	}
	glewExperimental = GL_TRUE;

	//Check the GLSL and OpenGL status 
	if (glewInit() != GLEW_OK)
	{
		std::cerr << "Failed to initialize GLEW" << std::endl;
		return;
	}
	const GLubyte *renderer = glGetString(GL_RENDERER);
	const GLubyte *vendor = glGetString(GL_VENDOR);
	const GLubyte *version = glGetString(GL_VERSION);
	const GLubyte *glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION);

	m_GLRenderer = (const char *)renderer;
	m_GLVersion  = (const char *)version;
	m_GLSLVersion = (const char *)glslVersion;

	GLint major, minor;
	glGetIntegerv(GL_MAJOR_VERSION, &major);
	glGetIntegerv(GL_MINOR_VERSION, &minor);
	std::cout << "GL Vendor    :" << vendor << std::endl;
	std::cout << "GL Renderer  : " << renderer << std::endl;
	std::cout << "GL Version (std::string)  : " << version << std::endl;
	std::cout << "GL Version (integer) : " << major << "." << minor << std::endl;
	std::cout << "GLSL Version : " << glslVersion << std::endl;
	std::cout << "--------------------------------------------------------------------------------"
		<< std::endl;
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);

#ifdef USE_FONT
	m_pFont.init();
#endif
#ifdef USE_CEGUI
	OGLCEGUI::getInstance()->init();
	OGLCEGUI::getInstance()->setupCallbacks(pWindow);
#endif
	v_init();


	while (!glfwWindowShouldClose(pWindow))
	{
		glfwPollEvents();
		v_movement(pWindow);

		countFps();

		static GLfloat lastFrame = static_cast<float>(glfwGetTime());
		GLfloat currentFrame = static_cast<float>(glfwGetTime());
		GLfloat deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;

		v_update();
		v_render();

#ifdef USE_FONT
		glDisable(GL_DEPTH_TEST);
		m_pFont.render("Graphics card: " + m_GLRenderer, 10, sh - 40);
		m_pFont.render("GL Version: " + m_GLVersion, 10, sh - 70);
		m_pFont.render("GLSL Version: " + m_GLSLVersion, 10, sh - 100);
		m_pFont.render("FPS: " + std::to_string(m_fps), 10, 30);
		//glEnable(GL_DEPTH_TEST);
#endif

#ifdef USE_CEGUI
		 OGLCEGUI::getInstance()->render();
#endif
		glfwSwapBuffers(pWindow);
	}

	v_shutdown();

	glfwTerminate();
}