pax_global_header00006660000000000000000000000064132212072460014511gustar00rootroot0000000000000052 comment=c2c6a7f821c2609441686453a5a3e88d908e4c18 receptor-0.0~git20171228.c2c6a7f/000077500000000000000000000000001322120724600160565ustar00rootroot00000000000000receptor-0.0~git20171228.c2c6a7f/.travis.yml000066400000000000000000000010721322120724600201670ustar00rootroot00000000000000language: go sudo: false go: - 1.9 - master # Skip the install step. Don't `go get` dependencies. install: true matrix: # It's ok if our code fails on unstable development versions of Go. allow_failures: - go: master # Don't wait for tip tests to finish. Mark the test run green if the # tests pass on the stable versions of Go. fast_finish: true notifications: email: false before_script: - GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/) script: - test -z $(gofmt -s -l $GO_FILES) - go tool vet . - go test -v -race ./... receptor-0.0~git20171228.c2c6a7f/LICENSE000066400000000000000000000027071322120724600170710ustar00rootroot00000000000000Copyright (c) 2009 The Go Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. receptor-0.0~git20171228.c2c6a7f/README.md000066400000000000000000000020141322120724600173320ustar00rootroot00000000000000socketpair [![TravisCI](https://travis-ci.org/prep/socketpair.svg?branch=master)](https://travis-ci.org/prep/socketpair.svg?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/prep/socketpair)](https://goreportcard.com/report/github.com/prep/socketpair) [![GoDoc](https://godoc.org/github.com/prep/socketpair?status.svg)](https://godoc.org/github.com/prep/socketpair) ========== This is a simple package for Go that provides an interface to socketpair(2). Usage ----- ```go import "github.com/prep/socketpair" ``` ```go func testSocketPair() error { sock1, sock2, err := socketpair.New("unix") if err != nil { return err } defer sock1.Close() defer sock2.Close() if _, err := sock1.Write([]byte("Hello World")); err != nil { return err } data := make([]byte, 11) if _, err := sock2.Read(data); err != nil { return err } return nil } ``` License ------- This software is distributed under the BSD-style license found in the LICENSE file. receptor-0.0~git20171228.c2c6a7f/socketpair.go000066400000000000000000000020711322120724600205510ustar00rootroot00000000000000// Copyright (c) 2014 Maurice Nonnekes // All rights reserved. // Package socketpair implements a simple interface to create a socket pair. package socketpair import ( "errors" "net" "os" "syscall" ) // New creates a socketpair of the specified network type. // // Known networks are "unix" and "unixgram". func New(network string) (net.Conn, net.Conn, error) { var spDomain, spType int switch network { case "unix": spDomain, spType = syscall.AF_LOCAL, syscall.SOCK_STREAM case "unixgram": spDomain, spType = syscall.AF_LOCAL, syscall.SOCK_DGRAM default: return nil, nil, errors.New("unknown network " + network) } fds, err := syscall.Socketpair(spDomain, spType, 0) if err != nil { return nil, nil, err } fd1 := os.NewFile(uintptr(fds[0]), "fd1") defer fd1.Close() fd2 := os.NewFile(uintptr(fds[1]), "fd2") defer fd2.Close() sock1, err := net.FileConn(fd1) if err != nil { return nil, nil, err } sock2, err := net.FileConn(fd2) if err != nil { sock1.Close() return nil, nil, err } return sock1, sock2, nil } receptor-0.0~git20171228.c2c6a7f/socketpair_test.go000066400000000000000000000026571322120724600216220ustar00rootroot00000000000000// Copyright (c) 2014 Maurice Nonnekes // All rights reserved. package socketpair import ( "net" "testing" ) var ( testByteString = []byte("Hello World") testNetworks = []string{"unix", "unixgram"} ) func slicesAreEqual(a, b []byte) bool { if len(a) != len(b) { return false } for i, v := range a { if v != b[i] { return false } } return true } func TestSocketpair(t *testing.T) { for _, network := range testNetworks { sock1, sock2, err := New(network) if err != nil { t.Fatalf("Error creating socket: %s: %s", network, err) } defer sock1.Close() defer sock2.Close() if _, ok := sock1.(*net.UnixConn); !ok { t.Fatalf("Expected to be able to typecast to a new.UnixConn pointer") } if _, ok := sock2.(*net.UnixConn); !ok { t.Fatalf("Expected to be able to typecast to a new.UnixConn pointer") } if _, err := sock1.Write(testByteString); err != nil { t.Fatalf("Error writing to socket: %s: %s", network, err) } byteString := make([]byte, len(testByteString)) if _, err := sock2.Read(byteString); err != nil { t.Fatalf("Error reading from socket: %s: %s", network, err) } if !slicesAreEqual(byteString, testByteString) { t.Fatalf("Unexpected data read from unix socket: %s", byteString) } } } func TestIllegalNetwork(t *testing.T) { if _, _, err := New("foobar"); err == nil { t.Fatalf("Expected error when requesting a bogus network type") } }