Exemplo n.º 1
1
HRESULT NamedPipeChannel::Create(const base::StringPiece16& name, DWORD mode,
                                 DWORD max_instances, DWORD default_timeout) {
  // drop unsupported flags
  mode &= ~(PIPE_NOWAIT | PIPE_REJECT_REMOTE_CLIENTS);

  base::AutoLock guard(lock_);

  if (work_ == nullptr || handle_ != INVALID_HANDLE_VALUE || io_ != nullptr)
    return E_HANDLE;

  auto pipe_name = kPipeNamePrefix + name.as_string();

  handle_ = CreateNamedPipe(pipe_name.c_str(),
                            PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, mode,
                            max_instances, 0, 0, default_timeout, nullptr);
  if (handle_ == INVALID_HANDLE_VALUE)
    return HRESULT_FROM_WIN32(GetLastError());

  io_ = CreateThreadpoolIo(handle_, OnCompleted, this, nullptr);
  if (io_ == nullptr)
    return HRESULT_FROM_WIN32(GetLastError());

  end_point_ = EndPoint::kServer;

  return S_OK;
}
Exemplo n.º 2
0
HRESULT NamedPipeChannel::Open(const base::StringPiece16& name, DWORD timeout) {
  base::AutoLock guard(lock_);

  if (work_ == nullptr || handle_ != INVALID_HANDLE_VALUE || io_ != nullptr)
    return E_HANDLE;

  auto pipe_name = kPipeNamePrefix + name.as_string();

  if (!WaitNamedPipe(pipe_name.c_str(), timeout))
    return HRESULT_FROM_WIN32(GetLastError());

  handle_ = CreateFile(pipe_name.c_str(), GENERIC_READ | GENERIC_WRITE,
                       FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
                       nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
  if (handle_ == INVALID_HANDLE_VALUE)
    return HRESULT_FROM_WIN32(GetLastError());

  io_ = CreateThreadpoolIo(handle_, OnCompleted, this, nullptr);
  if (io_ == nullptr)
    return HRESULT_FROM_WIN32(GetLastError());

  end_point_ = EndPoint::kClient;

  return S_OK;
}
Exemplo n.º 3
0
	bool TrimString(const string16& input,
		const base::StringPiece16& trim_chars,
		string16* output) {
		return TrimStringT(input, trim_chars.as_string(), TRIM_ALL, output) !=
			TRIM_NONE;
	}
Exemplo n.º 4
0
	bool RemoveChars(const string16& input,
		const base::StringPiece16& remove_chars,
		string16* output) {
		return ReplaceChars(input, remove_chars.as_string(), string16(), output);
	}
Exemplo n.º 5
0
	bool ReplaceChars(const string16& input,
		const base::StringPiece16& replace_chars,
		const string16& replace_with,
		string16* output) {
		return ReplaceCharsT(input, replace_chars.as_string(), replace_with, output);
	}