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

Unified Diff: third_party/mojo/src/mojo/public/go/system/message_pipe.go

Issue 1019173002: Update mojo sdk to rev 7214b7ec7d27563b2666afad86cf1c5895c56c18 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keep permission service alive if embedder drops requests Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/public/go/system/message_pipe.go
diff --git a/third_party/mojo/src/mojo/public/go/system/message_pipe.go b/third_party/mojo/src/mojo/public/go/system/message_pipe.go
index 79f0ae962439a358cd3c1a69004bb1d9f8b49cf2..21b81ef94c939a5c8a31c93209e14f84717d6746 100644
--- a/third_party/mojo/src/mojo/public/go/system/message_pipe.go
+++ b/third_party/mojo/src/mojo/public/go/system/message_pipe.go
@@ -4,11 +4,6 @@
package system
-//#include "c_allocators.h"
-//#include "mojo/public/c/system/core.h"
-import "C"
-import "unsafe"
-
// MessagePipeHandle is a handle for a bidirectional communication channel for
// framed data (i.e., messages). Messages can contain plain data and/or Mojo
// handles.
@@ -28,50 +23,37 @@ type MessagePipeHandle interface {
}
type messagePipe struct {
+ // baseHandle should always be the first component of this struct,
+ // see |finalizeHandle()| for more details.
baseHandle
}
func (h *messagePipe) ReadMessage(flags MojoReadMessageFlags) (MojoResult, []byte, []UntypedHandle) {
h.core.mu.Lock()
- defer h.core.mu.Unlock()
-
- cParams := C.MallocReadMessageParams()
- defer C.FreeReadMessageParams(cParams)
- *cParams.num_bytes = 0
- *cParams.num_handles = 0
- if result := C.MojoReadMessage(h.mojoHandle.cValue(), nil, cParams.num_bytes, nil, cParams.num_handles, flags.cValue()); result != C.MOJO_RESULT_RESOURCE_EXHAUSTED {
- return MojoResult(result), nil, nil
+ r, buf, rawHandles := sysImpl.ReadMessage(uint32(h.mojoHandle), uint32(flags))
+ h.core.mu.Unlock()
+ if r != 0 {
+ return MojoResult(r), nil, nil
}
- cArrays := C.MallocMessageArrays(*cParams.num_bytes, *cParams.num_handles)
- defer C.FreeMessageArrays(cArrays)
- result := C.MojoReadMessage(h.mojoHandle.cValue(), cArrays.bytes, cParams.num_bytes, cArrays.handles, cParams.num_handles, C.MojoReadMessageFlags(flags))
- bytesLen := int(*cParams.num_bytes)
- cBytes := *(*[]byte)(newUnsafeSlice(unsafe.Pointer(cArrays.bytes), bytesLen))
- bytes := make([]byte, bytesLen)
- copy(bytes, cBytes)
-
- handlesLen := int(*cParams.num_handles)
- cHandles := *(*[]MojoHandle)(newUnsafeSlice(unsafe.Pointer(cArrays.handles), handlesLen))
- handles := []UntypedHandle{}
- for i := 0; i < handlesLen; i++ {
- handles = append(handles, h.core.AcquireNativeHandle(cHandles[i]))
+ handles := make([]UntypedHandle, len(rawHandles))
+ for i := 0; i < len(handles); i++ {
+ handles[i] = h.core.AcquireNativeHandle(MojoHandle(rawHandles[i]))
}
- return MojoResult(result), bytes, handles
+ return MojoResult(r), buf, handles
}
func (h *messagePipe) WriteMessage(bytes []byte, handles []UntypedHandle, flags MojoWriteMessageFlags) MojoResult {
- h.core.mu.Lock()
- defer h.core.mu.Unlock()
-
- cArrays := C.MallocMessageArrays(C.uint32_t(len(bytes)), C.uint32_t(len(handles)))
- defer C.FreeMessageArrays(cArrays)
- cBytes := *(*[]byte)(newUnsafeSlice(unsafe.Pointer(cArrays.bytes), len(bytes)))
- copy(cBytes, bytes)
- cHandles := *(*[]MojoHandle)(newUnsafeSlice(unsafe.Pointer(cArrays.handles), len(handles)))
- for i := 0; i < len(handles); i++ {
- cHandles[i] = handles[i].ReleaseNativeHandle()
+ var rawHandles []uint32
+ if len(handles) != 0 {
+ rawHandles = make([]uint32, len(handles))
+ for i := 0; i < len(handles); i++ {
+ rawHandles[i] = uint32(handles[i].NativeHandle())
+ }
}
- return MojoResult(C.MojoWriteMessage(h.mojoHandle.cValue(), cArrays.bytes, C.uint32_t(len(bytes)), cArrays.handles, C.uint32_t(len(handles)), flags.cValue()))
+ h.core.mu.Lock()
+ r := sysImpl.WriteMessage(uint32(h.mojoHandle), bytes, rawHandles, uint32(flags))
+ h.core.mu.Unlock()
+ return MojoResult(r)
}
« no previous file with comments | « third_party/mojo/src/mojo/public/go/system/handle.go ('k') | third_party/mojo/src/mojo/public/go/system/mojo_types.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698