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) } }
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 }
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)) }
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() }
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)) }
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 }
func openWrite(name string) *os.File { file, err := os.OpenFile(name, os.O_WRONLY, perm) bug.Err(err) return file }
func openRead(name string) *os.File { file, err := os.Open(name) bug.Err(err) return file }
func remove(name string) { err := os.Remove(name) bug.Err(err) }
func createFifo(name string) { err := syscall.Mkfifo(name, perm) bug.Err(err) }