當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Ufs.Msize方法代碼示例

本文整理匯總了Golang中github.com/lionkov/ninep/srv/ufs.Ufs.Msize方法的典型用法代碼示例。如果您正苦於以下問題:Golang Ufs.Msize方法的具體用法?Golang Ufs.Msize怎麽用?Golang Ufs.Msize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/lionkov/ninep/srv/ufs.Ufs的用法示例。


在下文中一共展示了Ufs.Msize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: BenchmarkVersion

func BenchmarkVersion(b *testing.B) {
	ufs := new(ufs.Ufs)
	ufs.Dotu = false
	ufs.Id = "ufs"
	ufs.Debuglevel = *debug
	ufs.Msize = 8192
	ufs.Start(ufs)

	l, err := net.Listen("unix", "")
	if err != nil {
		b.Fatalf("Can not start listener: %v", err)
	}
	srvAddr := l.Addr().String()
	b.Logf("Server is at %v", srvAddr)
	go func() {
		if err = ufs.StartListener(l); err != nil {
			b.Fatalf("Can not start listener: %v", err)
		}
		b.Fatalf("Listener returned")
	}()
	var conn net.Conn
	for i := 0; i < b.N; i++ {
		if conn, err = net.Dial("unix", srvAddr); err != nil {
			// Sometimes, things just happen.
			//b.Logf("%v", err)
		} else {
			conn.Close()
		}
	}

}
開發者ID:hugelgupf,項目名稱:ninep,代碼行數:31,代碼來源:clnt_test.go

示例2: BenchmarkRootWalkBadFid

func BenchmarkRootWalkBadFid(b *testing.B) {
	ufs := new(ufs.Ufs)
	ufs.Dotu = false
	ufs.Id = "ufs"
	ufs.Debuglevel = *debug
	ufs.Msize = 8192
	ufs.Start(ufs)

	l, err := net.Listen("unix", "")
	if err != nil {
		b.Fatalf("Can not start listener: %v", err)
	}
	srvAddr := l.Addr().String()
	go func() {
		if err = ufs.StartListener(l); err != nil {
			b.Fatalf("Can not start listener: %v", err)
		}
		b.Fatalf("Listener returned")
	}()

	user := ninep.OsUsers.Uid2User(os.Geteuid())
	clnt, err := Mount("unix", srvAddr, "/", 8192, user)
	if err != nil {
		b.Fatalf("Connect failed: %v\n", err)
	}
	rootfid := clnt.Root
	clnt.Debuglevel = 0 // *debug

	rootfid.Fid++
	for i := 0; i < b.N; i++ {
		if _, err = clnt.Walk(rootfid, rootfid, []string{"bin"}); err == nil {
			b.Fatalf("Did not get an expected error on walking a bad fid!")
		}
	}
}
開發者ID:hugelgupf,項目名稱:ninep,代碼行數:35,代碼來源:clnt_test.go

示例3: TestRename

func TestRename(t *testing.T) {
	var err error
	flag.Parse()
	ufs := new(ufs.Ufs)
	ufs.Dotu = false
	ufs.Id = "ufs"
	ufs.Debuglevel = *debug
	ufs.Msize = 8192
	ufs.Start(ufs)

	tmpDir, err := ioutil.TempDir("", "go9")
	if err != nil {
		t.Fatal("Can't create temp directory")
	}
	defer os.RemoveAll(tmpDir)
	ufs.Root = tmpDir
	t.Logf("ufs starting in %v", tmpDir)
	// determined by build tags
	//extraFuncs()
	l, err := net.Listen("unix", "")
	if err != nil {
		t.Fatalf("Can not start listener: %v", err)
	}
	srvAddr := l.Addr().String()
	t.Logf("Server is at %v", srvAddr)
	go func() {
		if err = ufs.StartListener(l); err != nil {
			t.Fatalf("Can not start listener: %v", err)
		}
	}()

	user := ninep.OsUsers.Uid2User(os.Geteuid())
	clnt, err := Mount("unix", srvAddr, "/", 8192, user)
	if err != nil {
		t.Fatalf("Connect failed: %v\n", err)
	}
	rootfid := clnt.Root
	clnt.Debuglevel = 0 // *debug
	t.Logf("attached to %v, rootfid %v\n", tmpDir, rootfid)
	// OK, create a file behind nineps back and then rename it.
	b := make([]byte, 0)
	from := path.Join(tmpDir, "a")
	to := path.Join(tmpDir, "b")
	if err = ioutil.WriteFile(from, b, 0666); err != nil {
		t.Fatalf("%v", err)
	}

	f := clnt.FidAlloc()
	if _, err = clnt.Walk(rootfid, f, []string{"a"}); err != nil {
		t.Fatalf("%v", err)
	}
	t.Logf("Walked to a")
	if _, err := clnt.Stat(f); err != nil {
		t.Fatalf("%v", err)
	}
	if err := clnt.FSync(f); err != nil {
		t.Fatalf("%v", err)
	}
	if err = clnt.Rename(f, "b"); err != nil {
		t.Errorf("%v", err)
	}
	// the old one should be gone, and the new one should be there.
	if _, err = ioutil.ReadFile(from); err == nil {
		t.Errorf("ReadFile(%v): got nil, want err", from)
	}

	if _, err = ioutil.ReadFile(to); err != nil {
		t.Errorf("ReadFile(%v): got %v, want nil", from, err)
	}

	// now try with an absolute path, which is supported on ufs servers.
	// It's not guaranteed to work on all servers, but it is hugely useful
	// on those that can do it -- which is almost all of them, save Plan 9
	// of course.
	from = to
	if err = clnt.Rename(f, "c"); err != nil {
		t.Errorf("%v", err)
	}

	// the old one should be gone, and the new one should be there.
	if _, err = ioutil.ReadFile(from); err == nil {
		t.Errorf("ReadFile(%v): got nil, want err", from)
	}

	to = path.Join(tmpDir, "c")
	if _, err = ioutil.ReadFile(to); err != nil {
		t.Errorf("ReadFile(%v): got %v, want nil", to, err)
	}

	// Make sure they can't walk out of the root.

	from = to
	if err = clnt.Rename(f, "../../../../d"); err != nil {
		t.Errorf("%v", err)
	}

	// the old one should be gone, and the new one should be there.
	if _, err = ioutil.ReadFile(from); err == nil {
		t.Errorf("ReadFile(%v): got nil, want err", from)
	}
//.........這裏部分代碼省略.........
開發者ID:hugelgupf,項目名稱:ninep,代碼行數:101,代碼來源:clnt_test.go


注:本文中的github.com/lionkov/ninep/srv/ufs.Ufs.Msize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。