Beispiel #1
0
void OvpnMng::ReceiveLoop( void )
{
	// management interface receive loop
	while (m_boTerminateRequest == false)
	{
		// get mutex
		//pthread_mutex_lock(&m_SocketMutex);

		// read from socket
		int l_iLen = read( m_iSocket, l_acBuffer, sizeof(l_acBuffer) );

		// get mutex
		//pthread_mutex_unlock(&m_SocketMutex);

		// copy chars to command string until newline is found
		for (int i = 0; i < l_iLen; i++)
		{
			if (l_acBuffer[i] == '\n')
			{
				// end of line, null terminate the string and pass it to the line parser
				l_acCommand[l_iCmdIdx] = 0;
				l_iCmdIdx = 0;
				handleNewLine(l_acCommand);
			}
			else if (l_acBuffer[i] == '\r')
			{
				// discard \r char
				continue;
			}
			else if ((unsigned int)l_iCmdIdx < sizeof(l_acCommand))
			{
				// copy char to command string
				l_acCommand[l_iCmdIdx] = l_acBuffer[i];
				l_iCmdIdx++;
			}
			else
			{
				// out of string buffer
				std::cout << "[ERROR] received line too long!" << std::endl;
				l_iCmdIdx = 0;
				break;
			}
		}
	}
}
/*************************************************************************
	Handler for when non-printable keys are typed.
*************************************************************************/
void MultiLineEditbox::onKeyDown(KeyEventArgs& e)
{
	// base class processing
	Window::onKeyDown(e);

	if (hasInputFocus() && !isReadOnly())
	{
		WindowEventArgs args(this);
		switch (e.scancode)
		{
		case Key::LeftShift:
		case Key::RightShift:
			if (getSelectionLength() == 0)
			{
				d_dragAnchorIdx = getCaratIndex();
			}
			break;

		case Key::Backspace:
			handleBackspace();
			break;

		case Key::Delete:
			handleDelete();
			break;

		case Key::Return:
		case Key::NumpadEnter:
			handleNewLine(e.sysKeys);
			break;

		case Key::ArrowLeft:
			if (e.sysKeys & Control)
			{
				handleWordLeft(e.sysKeys);
			}
			else
			{
				handleCharLeft(e.sysKeys);
			}
			break;

		case Key::ArrowRight:
			if (e.sysKeys & Control)
			{
				handleWordRight(e.sysKeys);
			}
			else
			{
				handleCharRight(e.sysKeys);
			}
			break;

		case Key::ArrowUp:
			handleLineUp(e.sysKeys);
			break;

		case Key::ArrowDown:
			handleLineDown(e.sysKeys);
			break;

		case Key::Home:
			if (e.sysKeys & Control)
			{
				handleDocHome(e.sysKeys);
			}
			else
			{
				handleLineHome(e.sysKeys);
			}
			break;

		case Key::End:
			if (e.sysKeys & Control)
			{
				handleDocEnd(e.sysKeys);
			}
			else
			{
				handleLineEnd(e.sysKeys);
			}
			break;

        // default case is now to leave event as (possibly) unhandled.
        default:
            return;
		}

		e.handled = true;
	}

}