小编dil*_*ish的帖子

关键字var后面的下划线和接口名称是什么意思?

来自http://golang.org/src/pkg/database/sql/driver/types.go :

type ValueConverter interface {
    // ConvertValue converts a value to a driver Value.
    ConvertValue(v interface{}) (Value, error)
}

var Bool boolType

type boolType struct{}

var _ ValueConverter = boolType{} // line 58

func (boolType) String() string { return "Bool" }

func (boolType) ConvertValue(src interface{}) (Value, error) {....}
Run Code Online (Sandbox Code Playgroud)

我知道ValueConverter是一个接口名称.第58行似乎声明boolType实现接口ValueConverter,但这是必要的吗?我删除了第58行,代码运行良好.

syntax interface go underscores

66
推荐指数
2
解决办法
1万
查看次数

如何激活linux中的所有ksoftirqd?(关于linux内核的net stack)

我在 4 核 intel 机器上有一个多队列 NIC 卡,并且我将 NIC 卡的每个队列绑定在 cpu 核心上(设置 /proc/irq/xxx/smp_affinity) 假设 core0 上的queue0,core1 上的queue1 等等。

据说软中断将在发生硬件中断的同一内核上调用。为什么 ksoftirqd 无法在我的机器上并行运行?只有一个内核线程(如 ksoftirqd/2)将使用 100% 的内核,但其他线程为 0%

当我使用

cat /proc/interrupts | grep eth1
Run Code Online (Sandbox Code Playgroud)

我可以看到所有的包甚至都分发到了所有的NIC队列。

更新:

如果你能读懂中文,这里有一个100%软中断问题的解决方案 http://hi.baidu.com/higkoo/item/42ba6c353bc8aed76d15e9c3(请参见#7)如果不能,哪个博客说你可以添加另一张卡,这个问题将会得到解决

linux performance networking kernel irq

5
推荐指数
1
解决办法
3225
查看次数

为什么没有位置工作人员在golang time.Equal?

http://golang.org/src/pkg/time/time.go

62  // Equal reports whether t and u represent the same time instant.
63  // Two times can be equal even if they are in different locations.
64  // For example, 6:00 +0200 CEST and 4:00 UTC are Equal.
65  // This comparison is different from using t == u, which also compares
66  // the locations.
67  func (t Time) Equal(u Time) bool {
68      return t.sec == u.sec && t.nsec == u.nsec
69  }
Run Code Online (Sandbox Code Playgroud)

为什么他们不关心t.loc和u.loc?

更新:如果我有2台服务器(不同的位置),我如何判断他们的时间是否完全相同?

go

3
推荐指数
1
解决办法
497
查看次数

如何在golang中通知TCP客户端文件的结尾?

我想通过golang中的TCP发送文件。这是我的服务器代码:

    c is connected *net.TCPConn

    file, _ := os.Open(fn)
    defer file.Close()
    io.Copy(c, file)
    // c.CloseWrite()
Run Code Online (Sandbox Code Playgroud)

和客户:

    as above, c is connected *net.TCPConn

    file, _ := os.Create("file.txt")
    defer file.Close()
    io.Copy(file, c)
Run Code Online (Sandbox Code Playgroud)

我的问题是:这样,客户端无法收到文件的EOF

因此,io.Copy被阻止。我必须打电话c.CloseWrite通知客户文件已结束。

如果要发送文件,将无法正常工作,如何解决?

networking tcp file go

3
推荐指数
1
解决办法
3525
查看次数

标签 统计

go ×3

networking ×2

file ×1

interface ×1

irq ×1

kernel ×1

linux ×1

performance ×1

syntax ×1

tcp ×1

underscores ×1