本文整理汇总了Golang中net.UnixListener.AcceptUnix方法的典型用法代码示例。如果您正苦于以下问题:Golang UnixListener.AcceptUnix方法的具体用法?Golang UnixListener.AcceptUnix怎么用?Golang UnixListener.AcceptUnix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.UnixListener
的用法示例。
在下文中一共展示了UnixListener.AcceptUnix方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: accept
// listen for gui client to connect to our socket
func accept(listener *net.UnixListener, ch chan []byte) {
for {
// we are going to eat the serial data until
// we get a socket connection so we don't block the channel
select {
case <-ch:
log.Println("eating serial data")
default:
}
// set timeout to fall through so we can check the channel for
// serial data
listener.SetDeadline(time.Now().Add(100 * time.Millisecond))
conn, err := listener.AcceptUnix()
if nil != err {
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
continue
}
log.Println(err)
} else {
// we have connection, call handle, we only handle one connection
// so no goroutine here
handleSocket(conn, ch)
}
}
}
示例2: Serve
// Serve listens on sock for new connections and services them.
func (server LinuxHostAdminServer) Serve(sock *net.UnixListener) error {
defer RecoverTPMResources()
// Set the socket to allow peer credentials to be passed
sockFile, err := sock.File()
if err != nil {
return err
}
err = syscall.SetsockoptInt(int(sockFile.Fd()), syscall.SOL_SOCKET, syscall.SO_PASSCRED, 1 /* true */)
sockFile.Close()
if err != nil {
return err
}
connections := make(chan *net.UnixConn, 1)
errors := make(chan error, 1)
go func() {
defer RecoverTPMResources()
for {
conn, err := sock.AcceptUnix()
if err != nil {
errors <- err
break
}
connections <- conn
}
}()
for {
var conn *net.UnixConn
select {
case conn = <-connections:
break
case err = <-errors:
return err
case <-server.Done:
return nil
}
s := rpc.NewServer()
oob := util.NewOOBUnixConn(conn)
err = s.RegisterName("LinuxHost", linuxHostAdminServerStub{oob, server.lh, server.Done})
if err != nil {
return err
}
go func() {
defer RecoverTPMResources()
s.ServeCodec(protorpc.NewServerCodec(oob))
}()
}
}
示例3: lstn
func (e *Euclid) lstn(l *net.UnixListener, loop *loop) {
for {
conn, err := l.AcceptUnix()
if err != nil {
panic(err)
}
var buf [1024]byte
n, err := conn.Read(buf[:])
if err != nil {
panic(err)
}
r := bytes.Trim(buf[:n], " ")
resp := e.processMsg(r, loop.comm)
conn.Write(resp)
conn.Close()
}
}
示例4: run
func (srv *Server) run(listener *net.UnixListener) {
defer os.Remove(SOCKET)
for {
conn, err := listener.AcceptUnix()
if err != nil {
select {
case srv.errors <- err:
case <-srv.closed:
}
break
}
go srv.handleConn(conn)
}
close(srv.finished)
}
示例5: handleUnixConnection
func handleUnixConnection(listener *net.UnixListener, unix UnixHandler) {
for {
data := make([]byte, 512)
conn, err := listener.AcceptUnix()
if err != nil {
fmt.Println(err)
continue
}
read_length, err := conn.Read(data[0:])
if err != nil { // EOF, or worse
fmt.Println(err)
continue
}
if read_length > 0 {
go panicWrapping(func() {
unix.UnixReceived(data[0:read_length], conn)
})
}
}
}
示例6: Serve
// Serve listens on sock for new connections and services them.
func (server LinuxHostAdminServer) Serve(sock *net.UnixListener) error {
// Set the socket to allow peer credentials to be passed
err := NewAuthenticatedFileSocket(sock)
if err != nil {
return err
}
connections := make(chan *net.UnixConn, 1)
errors := make(chan error, 1)
go func() {
for {
conn, err := sock.AcceptUnix()
if err != nil {
errors <- err
break
}
connections <- conn
}
}()
for {
var conn *net.UnixConn
select {
case conn = <-connections:
break
case err = <-errors:
return err
case <-server.Done:
return nil
}
s := rpc.NewServer()
oob := util.NewOOBUnixConn(conn)
err = s.RegisterName("LinuxHost", linuxHostAdminServerStub{oob, server.lh, server.Done})
if err != nil {
return err
}
go s.ServeCodec(protorpc.NewServerCodec(oob))
}
}
示例7: Run
// Run the server's accept loop, waiting for connections from l.
// Correct shutdown procedure is:
// set slots to a number such that no new processes will run
// wait for all running processes to finish
// set shittingDown to true
// close the listening socket
func Run(v *viper.Viper, l *net.UnixListener) {
i := newInstance(v)
i.listener = l
for {
c, err := l.AcceptUnix()
i.m.Lock()
sdc := i.shutdownComplete
i.m.Unlock()
if sdc {
glog.Infoln("Shutdown complete. closing listener.")
if c != nil {
c.Close()
}
l.Close()
return
} else if err != nil {
glog.Errorln("Accept() failed on unix socket:", err)
return
}
go i.connectionHandler(c)
}
}