From 5546556517b163cdf17942dc58b53741d41e5d29 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 4 Oct 2020 17:25:33 -0700 Subject: [PATCH] Make IPC option symbols available everywhere. This reduces some friction when using these options in code that may be built for different platforms. --- transport/ipc/ipc_options.go | 59 ++++++++++++++++++++++++++++++++++++ transport/ipc/ipc_unix.go | 23 -------------- transport/ipc/ipc_windows.go | 22 -------------- 3 files changed, 59 insertions(+), 45 deletions(-) create mode 100644 transport/ipc/ipc_options.go diff --git a/transport/ipc/ipc_options.go b/transport/ipc/ipc_options.go new file mode 100644 index 00000000..abba156c --- /dev/null +++ b/transport/ipc/ipc_options.go @@ -0,0 +1,59 @@ +// +build !windows,!plan9,!js + +// Copyright 2019 The Mangos Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use file except in compliance with the License. +// You may obtain a copy of the license at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ipc + +const ( + // OptionIpcSocketPermissions is used to set the permissions on the + // UNIX domain socket via chmod. The argument is a uint32, and + // represents the mode passed to chmod(). This is + // done on the server side. Be aware that relying on + // socket permissions for enforcement is not portable. + OptionIpcSocketPermissions = "UNIX-IPC-CHMOD" + + // OptionIpcSocketOwner is used to set the socket owner by + // using chown on the server socket. This will only work if + // the process has permission. The argument is an int. + // If this fails to set at socket creation time, + // no error is reported. + OptionIpcSocketOwner = "UNIX-IPC-OWNER" + + // OptionIpcSocketGroup is used to set the socket group by + // using chown on the server socket. This will only work if + // the process has permission. The argument is an int. + // If this fails to set at socket creation time, + // no error is reported. + OptionIpcSocketGroup = "UNIX-IPC-GROUP" + + // OptionSecurityDescriptor represents a Windows security + // descriptor in SDDL format (string). This can only be set on + // a Listener, and must be set before the Listen routine + // is called. + OptionSecurityDescriptor = "WIN-IPC-SECURITY-DESCRIPTOR" + + // OptionInputBufferSize represents the Windows Named Pipe + // input buffer size in bytes (type int32). Default is 4096. + // This is only for Listeners, and must be set before the + // Listener is started. + OptionInputBufferSize = "WIN-IPC-INPUT-BUFFER-SIZE" + + // OptionOutputBufferSize represents the Windows Named Pipe + // output buffer size in bytes (type int32). Default is 4096. + // This is only for Listeners, and must be set before the + // Listener is started. + OptionOutputBufferSize = "WIN-IPC-OUTPUT-BUFFER-SIZE" +) + diff --git a/transport/ipc/ipc_unix.go b/transport/ipc/ipc_unix.go index 638e89b4..fc4a9f4e 100644 --- a/transport/ipc/ipc_unix.go +++ b/transport/ipc/ipc_unix.go @@ -34,29 +34,6 @@ const ( Transport = ipcTran(0) ) -const ( - // OptionIpcSocketPermissions is used to set the permissions on the - // UNIX domain socket via chmod. The argument is a uint32, and - // represents the mode passed to chmod(). This is - // done on the server side. Be aware that relying on - // socket permissions for enforcement is not portable. - OptionIpcSocketPermissions = "UNIX-IPC-CHMOD" - - // OptionIpcSocketOwner is used to set the socket owner by - // using chown on the server socket. This will only work if - // the process has permission. The argument is an int. - // If this fails to set at socket creation time, - // no error is reported. - OptionIpcSocketOwner = "UNIX-IPC-OWNER" - - // OptionIpcSocketGroup is used to set the socket group by - // using chown on the server socket. This will only work if - // the process has permission. The argument is an int. - // If this fails to set at socket creation time, - // no error is reported. - OptionIpcSocketGroup = "UNIX-IPC-GROUP" -) - func init() { transport.RegisterTransport(Transport) } diff --git a/transport/ipc/ipc_windows.go b/transport/ipc/ipc_windows.go index bb72cae2..a58e06b9 100644 --- a/transport/ipc/ipc_windows.go +++ b/transport/ipc/ipc_windows.go @@ -34,28 +34,6 @@ func init() { transport.RegisterTransport(Transport) } -// The options here are pretty specific to Windows Named Pipes. - -const ( - // OptionSecurityDescriptor represents a Windows security - // descriptor in SDDL format (string). This can only be set on - // a Listener, and must be set before the Listen routine - // is called. - OptionSecurityDescriptor = "WIN-IPC-SECURITY-DESCRIPTOR" - - // OptionInputBufferSize represents the Windows Named Pipe - // input buffer size in bytes (type int32). Default is 4096. - // This is only for Listeners, and must be set before the - // Listener is started. - OptionInputBufferSize = "WIN-IPC-INPUT-BUFFER-SIZE" - - // OptionOutputBufferSize represents the Windows Named Pipe - // output buffer size in bytes (type int32). Default is 4096. - // This is only for Listeners, and must be set before the - // Listener is started. - OptionOutputBufferSize = "WIN-IPC-OUTPUT-BUFFER-SIZE" -) - type dialer struct { path string proto transport.ProtocolInfo