Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Detach a connection from watcher. #11

Open
liukun opened this issue Jan 27, 2021 · 5 comments · May be fixed by #12
Open

Detach a connection from watcher. #11

liukun opened this issue Jan 27, 2021 · 5 comments · May be fixed by #12

Comments

@liukun
Copy link

liukun commented Jan 27, 2021

In a project, I need to detach a connection from the watcher and send it to another process, so I modified the flow of opDelete to support a new action opDetach: liukun@0a9a8f6

Do you think it can be added as a feature of gaio? If so, I'll commit a PR later with more proper designs than the above commit.

@xtaci
Copy link
Owner

xtaci commented Jan 27, 2021

but the file descriptor in the original net.Conn has been closed when watching , the working fd in watcher is dup() -ed from net.Conn.

@liukun
Copy link
Author

liukun commented Jan 27, 2021

Yes, it is. You can recover net.Conn by:

	f := os.NewFile(uintptr(fd), "dup-fd")
	conn, err := net.FileConn(f)
	_ = f.Close()
	return conn, err

@xtaci
Copy link
Owner

xtaci commented Jan 28, 2021

that makes sense, could you submit a PR to this issue for me to review the details?

@liukun
Copy link
Author

liukun commented Jan 28, 2021

Cool! I'll submit one when I have time.

不过有个设计上的问题。我目前是在回调里用size这个属性把fd传回来的。这样能接受吗?还是在OpResult里增加一个专用的FileDescriptor int或者通用的IntValue int呢?

@xtaci
Copy link
Owner

xtaci commented Jan 28, 2021

A watcher.Detach(conn) func is preferred.

@liukun liukun linked a pull request Jan 31, 2021 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants