Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: mojo/public/go/system/message_pipe.go

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/go/system/handle.go ('k') | mojo/public/go/system/mojo_types.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package system
6
7 // MessagePipeHandle is a handle for a bidirectional communication channel for
8 // framed data (i.e., messages). Messages can contain plain data and/or Mojo
9 // handles.
10 type MessagePipeHandle interface {
11 Handle
12
13 // ReadMessage reads a message from the message pipe endpoint with the
14 // specified flags. Returns the message data and attached handles that w ere
15 // received in the "next" message.
16 ReadMessage(flags MojoReadMessageFlags) (MojoResult, []byte, []UntypedHa ndle)
17
18 // WriteMessage writes message data and optional attached handles to
19 // the message pipe endpoint given by handle. On success the attached
20 // handles will no longer be valid (i.e.: the receiver will receive
21 // equivalent but logically different handles).
22 WriteMessage(bytes []byte, handles []UntypedHandle, flags MojoWriteMessa geFlags) MojoResult
23 }
24
25 type messagePipe struct {
26 // baseHandle should always be the first component of this struct,
27 // see |finalizeHandle()| for more details.
28 baseHandle
29 }
30
31 func (h *messagePipe) ReadMessage(flags MojoReadMessageFlags) (MojoResult, []byt e, []UntypedHandle) {
32 h.core.mu.Lock()
33 r, buf, rawHandles := sysImpl.ReadMessage(uint32(h.mojoHandle), uint32(f lags))
34 h.core.mu.Unlock()
35 if r != 0 {
36 return MojoResult(r), nil, nil
37 }
38
39 handles := make([]UntypedHandle, len(rawHandles))
40 for i := 0; i < len(handles); i++ {
41 handles[i] = h.core.AcquireNativeHandle(MojoHandle(rawHandles[i] ))
42 }
43 return MojoResult(r), buf, handles
44 }
45
46 func (h *messagePipe) WriteMessage(bytes []byte, handles []UntypedHandle, flags MojoWriteMessageFlags) MojoResult {
47
48 var rawHandles []uint32
49 if len(handles) != 0 {
50 rawHandles = make([]uint32, len(handles))
51 for i := 0; i < len(handles); i++ {
52 rawHandles[i] = uint32(handles[i].ReleaseNativeHandle())
53 }
54 }
55 h.core.mu.Lock()
56 r := sysImpl.WriteMessage(uint32(h.mojoHandle), bytes, rawHandles, uint3 2(flags))
57 h.core.mu.Unlock()
58 return MojoResult(r)
59 }
OLDNEW
« no previous file with comments | « mojo/public/go/system/handle.go ('k') | mojo/public/go/system/mojo_types.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698