aboutsummaryrefslogtreecommitdiff
path: root/lp.go
blob: aee2d23a45b2f666d93e6cbebee706f181c77ba8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package robo

import (
	"bufio"
	"os"
	"syscall"
)

type LP struct {
	*os.File
}

func NewLP(path string) (LP, error) {
	f, err := os.OpenFile(path, os.O_RDWR, 0666)
	return LP{f}, err
}

func (d LP) Close() {
	d.File.Close()
}

func (d LP) SetNonblock() {
	fd := d.File.Fd()
	syscall.SetNonblock(int(fd), true)
}

func (d LP) Handle() *bufio.ReadWriter {
	r := bufio.NewReader(d.File)
	w := bufio.NewWriter(d.File)
	return bufio.NewReadWriter(r, w)
}