aboutsummaryrefslogtreecommitdiff
path: root/dev.go
blob: b10ba2a60e2c37324452dc5d4c596c608e9aacc1 (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() error {
	return 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)
}