Giter Club home page Giter Club logo

Comments (5)

Allenxuxu avatar Allenxuxu commented on August 25, 2024

非常感谢,这里确实有问题。 已经提了修复的 PR ,可以看下 #61 @M6ZeroG

from gev.

M6ZeroG avatar M6ZeroG commented on August 25, 2024

非常感谢,这里确实有问题。 已经提了修复的 PR ,可以看下 #61 @M6ZeroG

不客气,还以为我对EAGAIN的理解有问题呢,查了资料又看了好久:joy:

from gev.

Allenxuxu avatar Allenxuxu commented on August 25, 2024

这里当err == unix.EAGAIN时直接return的话,不管n是多少,未Write()成功的那部分数据相当于直接丢弃了,为什么不把这部分未成功写入的数据存到c.outBuffer里再return呢?请教。

n, err := unix.Write(c.fd, data)
if err != nil {
if err == unix.EAGAIN {
return
}
c.handleClose(c.fd)
return

我理解 linux 里返回 EAGAIN , n 会被置为 -1, golang 里n会返回啥,我没找到确切的资料。
按你这里所说,返回 EAGAIN ,会存在 n 大于 0 的情况?有相关资料吗?

from gev.

M6ZeroG avatar M6ZeroG commented on August 25, 2024

这里当err == unix.EAGAIN时直接return的话,不管n是多少,未Write()成功的那部分数据相当于直接丢弃了,为什么不把这部分未成功写入的数据存到c.outBuffer里再return呢?请教。

n, err := unix.Write(c.fd, data)
if err != nil {
if err == unix.EAGAIN {
return
}
c.handleClose(c.fd)
return

我理解 linux 里返回 EAGAIN , n 会被置为 -1, golang 里n会返回啥,我没找到确切的资料。
按你这里所说,返回 EAGAIN ,会存在 n 大于 0 的情况?有相关资料吗?

根据golang封装的Write()源码上看,这个n应该就是 linux系统调用返回值,暂时还没有实测过
https://github.com/golang/sys/blob/master/unix/zsyscall_linux.go#L1565-L1578

from gev.

Allenxuxu avatar Allenxuxu commented on August 25, 2024

这里当err == unix.EAGAIN时直接return的话,不管n是多少,未Write()成功的那部分数据相当于直接丢弃了,为什么不把这部分未成功写入的数据存到c.outBuffer里再return呢?请教。

n, err := unix.Write(c.fd, data)
if err != nil {
if err == unix.EAGAIN {
return
}
c.handleClose(c.fd)
return

我理解 linux 里返回 EAGAIN , n 会被置为 -1, golang 里n会返回啥,我没找到确切的资料。
按你这里所说,返回 EAGAIN ,会存在 n 大于 0 的情况?有相关资料吗?

根据golang封装的Write()源码上看,这个n应该就是 linux系统调用返回值,暂时还没有实测过
https://github.com/golang/sys/blob/master/unix/zsyscall_linux.go#L1565-L1578

这里我也看过,结合 linux man,似乎会返回 -1 ,但是返回 -1 的话又不符合 go 的“哲学”了,已经返回 err 了,n 应该是一个零值

from gev.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.