Пример #1
0
    //FUZZ: disable check_for_lack_ACE_OS
    void send (void const* msg, size_t size)
    {
    //FUZZ: enable check_for_lack_ACE_OS

      if (size > Protocol::MAX_PAYLOAD_SIZE) throw InvalidArg ();

      // Note the potential deadlock if I lock mutex_ and out_data_ in
      // reverse order.

      MessageQueueAutoLock l1 (out_data_);
      AutoLock l2 (mutex_);

      throw_if_failed ();

      out_data_.push (MessagePtr (new Send (msg, size)));

      l1.unlock (); // no need to keep it locked

      while (true)
      {
        throw_if_failed ();

        if (!in_send_data_.empty ())
        {
          MessagePtr m (in_send_data_.front ());
          in_send_data_.pop ();

          std::type_info const* exp = &typeid (*m);

          if (exp == typeid (ACE_TMCast::Aborted))
          {
            throw Group::Aborted ();
          }
          else if (exp == typeid (Commited))
          {
            return;
          }
          else
          {
            // cerr << "send: group-scheduler messaging protocol violation; "
            //     << "unexpected message " << typeid (*m).name ()
            //     << " " << typeid (Aborted).name () << endl;

            ACE_OS::abort ();
          }
        }

        // cerr << "send: waiting on condition" << endl;
        send_cond_.wait ();
        // cerr << "send: wokeup on condition" << endl;
      }
    }
Пример #2
0
void Win32Socket::bind(const SocketName &socketname, bool reuse_address)
{
	if (reuse_address)
	{
		int value = 1;
		int result = setsockopt(handle, SOL_SOCKET, SO_REUSEADDR, (const char *) &value, sizeof(int));
		throw_if_failed(result);
	}

	sockaddr_in addr;
	socketname.to_sockaddr(AF_INET, (sockaddr *) &addr, sizeof(sockaddr_in));
	int result = ::bind(handle, (const sockaddr *) &addr, sizeof(sockaddr_in));
	throw_if_failed(result);
}
Пример #3
0
int Win32Socket::peek(void *data, int size)
{
	int result = ::recv(handle, (char *) data, size, MSG_PEEK);
	throw_if_failed(result);
	reset_receive();
	return result;
}
Пример #4
0
void Win32Socket::process_events()
{
	WSANETWORKEVENTS events = { 0 };
	int result = WSAEnumNetworkEvents(handle, event_handle, &events);
	throw_if_failed(result);

	bool receive_flag = false;
	bool send_flag = false;
	bool except_flag = false;
	if (events.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE))
		receive_flag = true;
	if (events.lNetworkEvents & FD_WRITE)
		send_flag = true;
	if (events.lNetworkEvents & FD_OOB)
		except_flag = true;

	if (events.lNetworkEvents & FD_CONNECT)
	{
		if (events.iErrorCode[FD_CONNECT_BIT] == 0)
			send_flag = true;
		else
			except_flag = true;
	}

	if (receive_flag)
		SetEvent(receive_handle);
	if (send_flag)
		SetEvent(send_handle);
	if (except_flag)
		SetEvent(except_handle);
}
Пример #5
0
void Win32Socket::set_keep_alive(bool enable, int timeout, int interval)
{
	int value = enable ? 1 : 0;
	int result = setsockopt(handle, SOL_SOCKET, SO_KEEPALIVE, (const char *) &value, sizeof(int));
	throw_if_failed(result);

	if (enable && timeout != 0 && interval != 0)
	{
		tcp_keepalive keepalive = { 0 };
		keepalive.onoff = 1;
		keepalive.keepalivetime = timeout;
		keepalive.keepaliveinterval = interval;
		DWORD bytes_returned = 0;
		result = WSAIoctl(handle, SIO_KEEPALIVE_VALS, &keepalive, sizeof(tcp_keepalive), 0, 0, &bytes_returned, 0, 0);
		throw_if_failed(result);
	}
}
Пример #6
0
void Renderer::reacquire()
{
	throw_if_failed(device->CreateVertexBuffer(max_vertices * sizeof(Vertex), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
		vertex_definition, D3DPOOL_DEFAULT, &vertex_buffer, nullptr));

	for (int i = 0; i < 2; ++i)
	{
		device->BeginStateBlock();

		device->SetRenderState(D3DRS_ZENABLE, FALSE);

		device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

		device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
		device->SetRenderState(D3DRS_ALPHAREF, 0x08);
		device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

		device->SetRenderState(D3DRS_LIGHTING, FALSE);

		device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
		device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
		device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
		device->SetRenderState(D3DRS_CLIPPING, TRUE);
		device->SetRenderState(D3DRS_CLIPPLANEENABLE, FALSE);
		device->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE);
		device->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
		device->SetRenderState(D3DRS_FOGENABLE, FALSE);
		device->SetRenderState(D3DRS_COLORWRITEENABLE,
			D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN |
			D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);

		device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
		device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
		device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
		device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
		device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
		device->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
		device->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
		device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
		device->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
		device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
		device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
		device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
		
		device->SetFVF(vertex_definition);
		device->SetTexture(0, nullptr);
		device->SetStreamSource(0, vertex_buffer, 0, sizeof(Vertex));
		device->SetPixelShader(nullptr);

		if (i != 0)
			device->EndStateBlock(&prev_state_block);
		else
			device->EndStateBlock(&render_state_block);
	}
}
Пример #7
0
      void run_tests_common() {
         // Check if throwing an exception works
         try {
            throw_standard_exception(CL_INVALID_VALUE);
            fail("Throwing a standard OpenCL exception should work");
         } catch(const StandardExceptions::InvalidValue) {
            pass();
         } catch(...) {
            fail("Throwing a standard OpenCL exception should result in the right kind of exception being raised");
         }

         // Check that throw_if_failed will not raise exceptions thoughtlessly
         try {
            throw_if_failed(CL_SUCCESS);
            pass();
         } catch(...) {
            fail("throw_if_failed() should not raise an exception in reaction to CL_SUCCESS");
         }

         // Check that it will raise the right exception if that is warranted
         try {
            throw_if_failed(CL_INVALID_VALUE);
            fail("throw_if_failed() should raise an exception if passed an OpenCL error code");
         } catch(const StandardExceptions::InvalidValue) {
            pass();
         }

         // Try decoding empty OpenCL string lists
         using StringVector = std::vector<std::string>;
         check(decode_opencl_list("", ',') == StringVector{}, "Decoding an empty list should lead an empty result");
         check(decode_opencl_list("   ", ' ') == StringVector{}, "Decoding an list with nothing but separators should lead an empty result");
         check(decode_opencl_list(";;;", ';') == StringVector{}, "Decoding an list with nothing but separators should lead an empty result");

         // Try decoding one-, two, three- and four-element lists
         check(decode_opencl_list("this", '@') == StringVector{"this"}, "Decoding a one-element list should work");
         check(decode_opencl_list("this$is", '$') == StringVector{"this", "is"}, "Decoding a two-element list should work");
         check(decode_opencl_list("this-is-sparta", '-') == StringVector{"this", "is", "sparta"}, "Decoding a three-element list should work");
         check(decode_opencl_list("this.is.sparta.!!!", '.') == StringVector{"this", "is", "sparta", "!!!"}, "Decoding a four-element list should work");

         // Add spurious separators in various places and check that they are ignored
         check(decode_opencl_list("...this.is.sparta.!!!", '.') == StringVector{"this", "is", "sparta", "!!!"}, "Decoding a list with spurious separators in front should work");
         check(decode_opencl_list("...this...is...sparta...!!!", '.') == StringVector{"this", "is", "sparta", "!!!"}, "Decoding a list with spurious separators in the middle should work");
         check(decode_opencl_list("...this...is...sparta...!!!...", '.') == StringVector{"this", "is", "sparta", "!!!"}, "Decoding a list with spurious separators in the end should work");
      }
Пример #8
0
int Win32Socket::peek_from(void *data, int size, SocketName &out_socketname)
{
	sockaddr_in new_addr;
	memset(&new_addr, 0, sizeof(sockaddr_in));
	int addr_size = sizeof(sockaddr_in);
	int result = ::recvfrom(handle, (char *) data, size, MSG_PEEK, (sockaddr *) &new_addr, &addr_size);
	throw_if_failed(result);
	out_socketname.from_sockaddr(AF_INET, (sockaddr *) &new_addr, size);
	reset_receive();
	return result;
}
Пример #9
0
void Win32Socket::reset_except()
{
	fd_set fds;
	FD_ZERO(&fds);
	FD_SET(handle, &fds);
	timeval tv = { 0, 0 };
	int result = select(handle+1, 0, 0, &fds, &tv);
	throw_if_failed(result);
	if (FD_ISSET(handle, &fds) == 0)
		ResetEvent(except_handle);
}
Пример #10
0
SocketName Win32Socket::get_remote_name() const
{
	sockaddr_in addr;
	memset(&addr, 0, sizeof(sockaddr_in));
	int size = sizeof(sockaddr_in);
	int result = getpeername(handle, (sockaddr *) &addr, &size);
	throw_if_failed(result);

	SocketName name;
	name.from_sockaddr(AF_INET, (sockaddr *) &addr, sizeof(sockaddr_in));
	return name;
}
Пример #11
0
void Renderer::draw(const RenderListPtr &render_list)
{
	std::size_t num_vertices = std::size(render_list->vertices);
	if (num_vertices > 0)
	{
		void *data;

		if (num_vertices > max_vertices)
		{
			max_vertices = num_vertices;
			release();
			reacquire();
		}

		throw_if_failed(vertex_buffer->Lock(0, 0, &data, D3DLOCK_DISCARD));
		{
			std::memcpy(data, std::data(render_list->vertices), sizeof(Vertex) * num_vertices);
		}
		vertex_buffer->Unlock();
	}

	std::size_t pos = 0;

	Batch &prev_batch = render_list->batches.front();

	for (const auto &batch : render_list->batches)
	{
		int order = topology_order(batch.topology);
		if (batch.count && order > 0)
		{
			std::uint32_t primitive_count = batch.count;

			if (is_toplogy_list(batch.topology))
				primitive_count /= order;
			else
				primitive_count -= (order - 1);

			device->SetTexture(0, batch.texture);
			device->DrawPrimitive(batch.topology, pos, primitive_count);
			pos += batch.count;
		}
	}
}
Пример #12
0
    //FUZZ: disable check_for_lack_ACE_OS
    size_t recv (void* msg, size_t size)
    {
    //FUZZ: enable check_for_lack_ACE_OS

      AutoLock lock (mutex_);

      while (true)
      {
        throw_if_failed ();

        if (!in_recv_data_.empty ())
        {
          MessagePtr m (in_recv_data_.front ());
          in_recv_data_.pop ();

          std::type_info const* exp = &typeid (*m);

          if (exp == typeid (Recv))
          {
            Recv* data = dynamic_cast<Recv*> (m.get ());

            if (size < data->size ()) 
              throw Group::InsufficienSpace ();

            ACE_OS::memcpy (msg, data->payload (), data->size ());

            return data->size ();
          }
          else
          {
            // cerr << "recv: group-scheduler messaging protocol violation. "
            //     << "unexpected message " << typeid (*m).name () << endl;

            ACE_OS::abort ();
          }
        }

        recv_cond_.wait ();
      }
    }
Пример #13
0
	bool show()
	{
		#ifdef WIN32

		CL_String16 title16 = CL_StringHelp::utf8_to_ucs2(title);
		CL_String16 initial_directory16 = CL_StringHelp::utf8_to_ucs2(initial_directory);

		#ifndef __MINGW32__
		
		if(is_vista_or_later())
		{
			HRESULT result;
			CL_ComPtr<IFileOpenDialog> open_dialog;

			result = CoCreateInstance(__uuidof(FileOpenDialog), NULL, CLSCTX_ALL, __uuidof(open_dialog),  reinterpret_cast<void**>(open_dialog.output_variable()));
			throw_if_failed(result, "CoCreateInstance(FileOpenDialog) failed");

			result = open_dialog->SetTitle(title16.c_str());
			throw_if_failed(result, "IFileOpenDialog.SetTitle failed");

			result = open_dialog->SetOptions(FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
			throw_if_failed(result, "IFileOpenDialog.SetOptions((FOS_PICKFOLDERS) failed");

			if(initial_directory16.length() > 0)
			{
				LPITEMIDLIST item_id_list = NULL;
				SFGAOF flags = 0;
				result = SHParseDisplayName(initial_directory16.c_str(), NULL, &item_id_list, SFGAO_FILESYSTEM, &flags);
				throw_if_failed(result, "SHParseDisplayName failed");

				CL_ComPtr<IShellItem> folder_item;
				result = SHCreateShellItem(NULL, NULL, item_id_list, folder_item.output_variable());
				ILFree(item_id_list);
				throw_if_failed(result, "SHCreateItemFromParsingName failed");

				/* This code requires Windows Vista or newer:
				CL_ComPtr<IShellItem> folder_item;
				result = SHCreateItemFromParsingName(initial_directory16.c_str(), NULL, IID_PPV_ARGS(folder_item.output_variable()));
				throw_if_failed(result, "SHCreateItemFromParsingName failed");
				*/

				if(!folder_item.is_null())
				{
					result = open_dialog->SetFolder(folder_item);
					throw_if_failed(result, "IFileOpenDialog.SetFolder failed");
				}
			}

			if(owner)
				result = open_dialog->Show(owner->get_display_window().get_hwnd());
			else
				result = open_dialog->Show(0);

			if(SUCCEEDED(result))
			{
				CL_ComPtr<IShellItem> chosen_folder;
				result = open_dialog->GetResult(chosen_folder.output_variable());
				throw_if_failed(result, "IFileOpenDialog.GetResult failed");

				WCHAR *buffer = 0;
				result = chosen_folder->GetDisplayName(SIGDN_FILESYSPATH, &buffer);
				throw_if_failed(result, "IShellItem.GetDisplayName failed");

				CL_String16 output_directory16;
				try
				{
					output_directory16 = buffer;
				}
				catch (...)
				{
					CoTaskMemFree(buffer);
					throw;
				}

				CoTaskMemFree(buffer);
				selected_path = CL_StringHelp::ucs2_to_utf8(output_directory16);
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		#endif
		{
			BROWSEINFO bi;
			ZeroMemory(&bi, sizeof(bi));
		
			CL_String16::char_type path_buffer[FILENAME_MAX] = { 0 };

			WCHAR Buffer[MAX_PATH];
			memset(Buffer, 0, sizeof(WCHAR) * MAX_PATH);

			if(owner)
				bi.hwndOwner = owner->get_display_window().get_hwnd();
			else
				bi.hwndOwner = 0;

			bi.pszDisplayName = Buffer;
			bi.lpszTitle = title16.c_str();
			bi.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_SHAREABLE;

			LPCITEMIDLIST pFolder = SHBrowseForFolder(&bi);
			if (pFolder == NULL) 
				return false;

			if (!SHGetPathFromIDList(pFolder, path_buffer)) 
				throw CL_Exception("Bad path for Browse Folder Dialog");

			selected_path = CL_StringHelp::ucs2_to_utf8(path_buffer);

			return true;
		}
#else
		bool success = false;
		return success;
#endif
	}
Пример #14
0
void Win32Socket::set_nodelay(bool enable)
{
	int value = enable ? 1 : 0;
	int result = setsockopt(handle, IPPROTO_TCP, TCP_NODELAY, (const char *) &value, sizeof(int));
	throw_if_failed(result);
}
Пример #15
0
void Win32Socket::listen(int backlog)
{
	int result = ::listen(handle, backlog);
	throw_if_failed(result);
}
Пример #16
0
	bool show()
	{
		#if defined(WIN32)

		std::wstring title16 = StringHelp::utf8_to_ucs2(title);
		std::wstring initial_directory16 = StringHelp::utf8_to_ucs2(initial_directory);

		if(is_vista_or_later())
		{
			HRESULT result;
			ComPtr<IFileOpenDialog> open_dialog;

			result = CoCreateInstance(__uuidof(FileOpenDialog), NULL, CLSCTX_ALL, __uuidof(open_dialog),  reinterpret_cast<void**>(open_dialog.output_variable()));
			throw_if_failed(result, "CoCreateInstance(FileOpenDialog) failed");

			result = open_dialog->SetTitle(title16.c_str());
			throw_if_failed(result, "IFileOpenDialog.SetTitle failed");

			result = open_dialog->SetOptions(FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
			throw_if_failed(result, "IFileOpenDialog.SetOptions((FOS_PICKFOLDERS) failed");

			if(initial_directory16.length() > 0)
			{
				LPITEMIDLIST item_id_list = NULL;
				SFGAOF flags = 0;
				result = SHParseDisplayName(initial_directory16.c_str(), NULL, &item_id_list, SFGAO_FILESYSTEM, &flags);
				throw_if_failed(result, "SHParseDisplayName failed");

				ComPtr<IShellItem> folder_item;
				result = SHCreateShellItem(NULL, NULL, item_id_list, folder_item.output_variable());
				ILFree(item_id_list);
				throw_if_failed(result, "SHCreateItemFromParsingName failed");

				/* This code requires Windows Vista or newer:
				ComPtr<IShellItem> folder_item;
				result = SHCreateItemFromParsingName(initial_directory16.c_str(), NULL, IID_PPV_ARGS(folder_item.output_variable()));
				throw_if_failed(result, "SHCreateItemFromParsingName failed");
				*/

				if(!folder_item.is_null())
				{
					result = open_dialog->SetFolder(folder_item);
					throw_if_failed(result, "IFileOpenDialog.SetFolder failed");
				}
			}

			if(owner)
				result = open_dialog->Show(owner->get_display_window().get_hwnd());
			else
				result = open_dialog->Show(0);

			if(SUCCEEDED(result))
			{
				ComPtr<IShellItem> chosen_folder;
				result = open_dialog->GetResult(chosen_folder.output_variable());
				throw_if_failed(result, "IFileOpenDialog.GetResult failed");

				WCHAR *buffer = 0;
				result = chosen_folder->GetDisplayName(SIGDN_FILESYSPATH, &buffer);
				throw_if_failed(result, "IShellItem.GetDisplayName failed");

				std::wstring output_directory16;
				try
				{
					output_directory16 = buffer;
				}
				catch (...)
				{
					CoTaskMemFree(buffer);
					throw;
				}

				CoTaskMemFree(buffer);
				selected_path = StringHelp::ucs2_to_utf8(output_directory16);
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			BROWSEINFO bi;
			ZeroMemory(&bi, sizeof(bi));
		
			std::wstring::value_type path_buffer[FILENAME_MAX] = { 0 };

			WCHAR Buffer[MAX_PATH];
			memset(Buffer, 0, sizeof(WCHAR) * MAX_PATH);

			if(owner)
				bi.hwndOwner = owner->get_display_window().get_hwnd();
			else
				bi.hwndOwner = 0;

			bi.pszDisplayName = Buffer;
			bi.lpszTitle = title16.c_str();
			bi.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_SHAREABLE;

			LPCITEMIDLIST pFolder = SHBrowseForFolder(&bi);
			if (pFolder == NULL) 
				return false;

			if (!SHGetPathFromIDList(pFolder, path_buffer)) 
				throw Exception("Bad path for Browse Folder Dialog");

			selected_path = StringHelp::ucs2_to_utf8(path_buffer);

			return true;
		}
        
#elif defined(__APPLE__)

        // To do: add cocoa code here
        return false;
        
#elif defined(I_LOVE_AUTOHELL_AND_FIXED_THE_GTK_CHECK)

		if (!gtk_init_check(NULL, NULL))
			throw Exception("gtk_init_check Failed!");

	 	GtkWidget *dialog;
    
		dialog = gtk_file_chooser_dialog_new ("Open File", 
				NULL,
				GTK_FILE_CHOOSER_ACTION_OPEN,
				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				NULL);
     
		if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
		{
			char *filename;
     
			filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
			//printf("%s\n", filename);
			g_free (filename);
		}
     
		gtk_widget_destroy (dialog);
		unsigned int x_time = System::get_time();
		while(true)
		{
			if(owner)
				XSync(owner->get_display_window().get_display(), True);
			gtk_main_iteration_do(FALSE);
			unsigned int x_time_now = System::get_time();
			if ((x_time_now - x_time) > 250)
				break;
		}
	
		bool success = false;
		return success;
		
#else
	return false;
#endif
	}
Пример #17
0
void Win32Socket::select_events()
{
	int result = WSAEventSelect(handle, event_handle, FD_READ|FD_WRITE|FD_OOB|FD_ACCEPT|FD_CONNECT|FD_CLOSE);
	throw_if_failed(result);
}