Example #1
0
File: block.go Project: taysom/va
func (block *Block) Release() {
	if block.dirty {
		n, err := block.cache.f.WriteAt(block.Buf[:], block.id<<blockShift)
		bug.Err(err)
		bug.Assert(n == blockSize)
	}
}
Example #2
0
File: block.go Project: taysom/va
func Start(path string) *Cache {
	var cache Cache
	f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, perm)
	bug.Err(err)
	cache.f = f
	cache.nextId = 1
	return &cache
}
Example #3
0
File: ping.go Project: taysom/va
func fifoPing() {
	var ball [1]byte
	createFifo(pingFifo)
	defer remove(pingFifo)

	ping := openWrite(pingFifo)
	pong := openRead(pongFifo)
	ball[0] = 'b'
	start := time.Now()
	for i := 0; i < pingpong.Loops; i++ {
		_, err := ping.Write(ball[:])
		bug.Err(err)
		//fmt.Println("Ping!")
		_, err = pong.Read(ball[:])
		bug.Err(err)
	}
	finish := time.Now()
	fmt.Println("Total time: ",
		float64(finish.UnixNano()-start.UnixNano())/float64(pingpong.Loops))
}
Example #4
0
File: pong.go Project: taysom/va
func tcpPong() {
	var ball [1]byte
	tcpAddr, err := net.ResolveTCPAddr("tcp4", pingpong.Service)
	bug.Err(err)

	pong, err := net.ListenTCP("tcp", tcpAddr)
	bug.Err(err)

	conn, err := pong.Accept()
	bug.Err(err)
	ball[0] = 'b'
	for i := 0; i < pingpong.Loops; i++ {

		_, err = conn.Read(ball[:])
		bug.Err(err)
		fmt.Println("Pong!")
		_, err = conn.Write(ball[:])
		bug.Err(err)
	}
	conn.Close()
}
Example #5
0
File: ping.go Project: taysom/va
func tcpPing() {
	var ball [1]byte
	tcpAddr, err := net.ResolveTCPAddr("tcp4", "taysom"+pingpong.Service)
	bug.Err(err)

	ping, err := net.DialTCP("tcp", nil, tcpAddr)
	bug.Err(err)

	ball[0] = 'b'
	start := time.Now()
	for i := 0; i < pingpong.Loops; i++ {
		_, err := ping.Write(ball[:])
		bug.Err(err)
		fmt.Println("Ping!")
		_, err = ping.Read(ball[:])
		bug.Err(err)
	}
	finish := time.Now()
	fmt.Println("Total time: ",
		float64(finish.UnixNano()-start.UnixNano())/float64(pingpong.Loops))
}
Example #6
0
File: block.go Project: taysom/va
func (cache *Cache) Get(blknum int64) *Block {
	var block Block
	n, err := cache.f.ReadAt(block.Buf[:], blknum<<blockShift)
	if err == io.EOF {
		n = blockSize
		err = nil
	}
	bug.Err(err)
	bug.Assert(n == blockSize)
	block.id = blknum
	block.cache = cache
	return &block
}
Example #7
0
File: ping.go Project: taysom/va
func openWrite(name string) *os.File {
	file, err := os.OpenFile(name, os.O_WRONLY, perm)
	bug.Err(err)
	return file
}
Example #8
0
File: ping.go Project: taysom/va
func openRead(name string) *os.File {
	file, err := os.Open(name)
	bug.Err(err)
	return file
}
Example #9
0
File: ping.go Project: taysom/va
func remove(name string) {
	err := os.Remove(name)
	bug.Err(err)
}
Example #10
0
File: ping.go Project: taysom/va
func createFifo(name string) {
	err := syscall.Mkfifo(name, perm)
	bug.Err(err)
}