You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it will be more useful to provide these non-blocking methods by RawConn rather than TCPConn.
These new metheds and the new definition would be like(see the OnRead/OnWrite/EnablePollWrite:
// A RawConn is a raw network connection.typeRawConninterface {
// Control invokes f on the underlying connection's file// descriptor or handle.// The file descriptor fd is guaranteed to remain valid while// f executes but not after f returns.Control(ffunc(fduintptr)) error// Read invokes f on the underlying connection's file// descriptor or handle; f is expected to try to read from the// file descriptor.// If f returns true, Read returns. Otherwise Read blocks// waiting for the connection to be ready for reading and// tries again repeatedly.// The file descriptor is guaranteed to remain valid while f// executes but not after f returns.Read(ffunc(fduintptr) (donebool)) error// Write is like Read but for writing.Write(ffunc(fduintptr) (donebool)) error// This is a new method.// OnRead registers a callback to handle the reading event.// If this callback is registered, users don't need to use// one goroutine for each conn and read it in a for-loop.OnRead(func(fduintptr))
// This is a new method.// OnWrite registers a callback to handle the writing event.OnWrite(func(fduintptr))
// This is a new method.// EnablePollWrite enables write event on the poller.// Users should cache the data unsent and call EnablePollWrite(true)// to enable the write event when Write fails, then the OnWrite // callback will be called when the fd is writable;// Users should call EnablePollWrite(false) to cancel the write// event after cached data has been sent.EnablePollWrite(enablebool)
}
After providing these new methods, users will be able to choose how to handle Fd's IO:
Using blocking Read/Write as before
Get RawConn by conn.SyscallConn(), and use RawConn.OnRead/OnWrite/EnablePollWrite to handle IO in a non-blocking way
The old issue #15735 was only for TCPConn, and still no solution to solve the problem of saving goroutines and blocking methods, so I open this new issue.
The text was updated successfully, but these errors were encountered:
We can't add new methods to an existing interface. That would break the compatibility guarantee.
I don't understand what OnRead does. What does "handle the reading event" mean? Note that at least with our current approaches, we can't in general know whether there is any data available to read without attempting to read something.
I don't understand what OnRead does. What does "handle the reading event" mean? Note that at least with our current approaches, we can't in general know whether there is any data available to read without attempting to read something.
OnRead registers a callback, users no longer use for { read } in a goroutine. but when the fd is readable, runtime calls the callback and users can read data in the callback.
It's like Reactor, io events passed to the users' handler.
I would want to see an implementation before accepting a proposal like this.
I haven't tried to implement these Reactor things in runtime yet, but found that maybe can do it for different Socket Conns when I read go source code.
I'll try it in my spare time.
Related:
#15735
I think it will be more useful to provide these non-blocking methods by RawConn rather than TCPConn.
These new metheds and the new definition would be like(see the OnRead/OnWrite/EnablePollWrite:
After providing these new methods, users will be able to choose how to handle Fd's IO:
The old issue #15735 was only for TCPConn, and still no solution to solve the problem of saving goroutines and blocking methods, so I open this new issue.
The text was updated successfully, but these errors were encountered: