ipc/glue/Transport_win.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/glue/Transport_win.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=8 et :
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "base/message_loop.h"
    1.12 +#include "chrome/common/child_process_info.h"
    1.13 +
    1.14 +#include "mozilla/ipc/Transport.h"
    1.15 +
    1.16 +using namespace base;
    1.17 +using namespace std;
    1.18 +
    1.19 +namespace mozilla {
    1.20 +namespace ipc {
    1.21 +
    1.22 +bool
    1.23 +CreateTransport(ProcessHandle aProcOne, ProcessHandle /*unused*/,
    1.24 +                TransportDescriptor* aOne, TransportDescriptor* aTwo)
    1.25 +{
    1.26 +  // This id is used to name the IPC pipe.  The pointer passed to this
    1.27 +  // function isn't significant.
    1.28 +  wstring id = ChildProcessInfo::GenerateRandomChannelID(aOne);
    1.29 +  // Use MODE_SERVER to force creation of the pipe
    1.30 +  Transport t(id, Transport::MODE_SERVER, nullptr);
    1.31 +  HANDLE serverPipe = t.GetServerPipeHandle();
    1.32 +  if (!serverPipe) {
    1.33 +    return false;
    1.34 +  }
    1.35 +
    1.36 +  // NB: we create the server pipe immediately, instead of just
    1.37 +  // grabbing an ID, on purpose.  In the current setup, the client
    1.38 +  // needs to connect to an existing server pipe, so to prevent race
    1.39 +  // conditions, we create the server side here and then dup it to the
    1.40 +  // eventual server process.
    1.41 +  HANDLE serverDup;
    1.42 +  DWORD access = 0;
    1.43 +  DWORD options = DUPLICATE_SAME_ACCESS;
    1.44 +  if (!DuplicateHandle(GetCurrentProcess(), serverPipe, aProcOne,
    1.45 +                       &serverDup,
    1.46 +                       access,
    1.47 +                       FALSE/*not inheritable*/,
    1.48 +                       options)) {
    1.49 +    return false;
    1.50 +  }
    1.51 +
    1.52 +  aOne->mPipeName = aTwo->mPipeName = id;
    1.53 +  aOne->mServerPipe = serverDup;
    1.54 +  aTwo->mServerPipe = INVALID_HANDLE_VALUE;
    1.55 +  return true;
    1.56 +}
    1.57 +
    1.58 +Transport*
    1.59 +OpenDescriptor(const TransportDescriptor& aTd, Transport::Mode aMode)
    1.60 +{
    1.61 +  return new Transport(aTd.mPipeName, aTd.mServerPipe, aMode, nullptr);
    1.62 +}
    1.63 +
    1.64 +Transport*
    1.65 +OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode)
    1.66 +{
    1.67 +  NS_NOTREACHED("Not implemented!");
    1.68 +  return nullptr;
    1.69 +}
    1.70 +
    1.71 +void
    1.72 +CloseDescriptor(const TransportDescriptor& aTd)
    1.73 +{
    1.74 +  CloseHandle(aTd.mServerPipe);
    1.75 +}
    1.76 +
    1.77 +} // namespace ipc
    1.78 +} // namespace mozilla

mercurial