Giter Club home page Giter Club logo

easygo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easygo's Issues

reading websocket data returns random bytes

Script:

package main

import (
    "fmt"
    "io"
    "log"
    "net"

    "github.com/gobwas/ws"
)

func HandleConn(conn net.Conn) {
    for {
        header, err := ws.ReadHeader(conn)
        if err != nil {
            log.Fatal(err)
        }

        buf := make([]byte, header.Length)
        _, err = io.ReadFull(conn, buf)
        if err != nil {
            log.Fatal(err)
        }
        fmt.Println(buf)
        fmt.Println(string(buf))
    }
}

func main() {
    ln, err := net.Listen("tcp", "localhost:8080")
    if err != nil {
        log.Fatal(err)
    }
    for {
        conn, err := ln.Accept()
        if err != nil {
            log.Fatal(err)
        }
        _, err = ws.Upgrade(conn)
        if err != nil {
            log.Fatal(err)
        }
        go HandleConn(conn)
    }
}

I do in browser console:

let socket = new WebSocket("ws://127.0.0.1:8080")
socket.send("Hello world")`

I see random bytes in the my terminal. Each call to socket.send("Hello world") return different bytes. But the length of the byte array is always equal to the length of the string. How can I fix this?

Level Trigger epoll mode

Documentation said that the library supports epoll LT mode:
Screen Shot 2023-09-01 at 17 07 44
At the same time I see no options for such behaviour in the documentation:
Screen Shot 2023-09-01 at 17 09 03

Can you explain please, how epoll Level Trigger mode can be enabled. If there are no options, are you planning to support this feature?

Please add "Examples" documentation :)

I'm new to Go and having to build this software in a hurry, so the copy/paste helps a lot! As I will need to do the same for my code, I've found the instructions for adding such examples to the godocs.

Also, THANK YOU for the trick to snag the file descriptor in your code! I was really upset when I didn't see a way to get it from the damn Go net library and thought I was going to just have to (further) hack the Go sources for my project. The Go language provides for some interesting idioms -- I'm still learning.

Is nonBlocking required if using level triggers?

I'm experimenting using netpoller with tls and websocket (github.com/gobwas/ws/wsutil), and I am concerned that with larger messages, the nonblocking socket read will return less than is needed to complete the websocket frame? From what I found via google search, nonblocking is only necessary when using level triggering, yet netpoll sets nonblocking on all connections.

do you see any problem with making setNonBlocking as optional and do you envision any issue with github.com/gobwas/ws/wsutil framing on top of netpoll

Poller does not implement Close method

The OS independent type Poller does not implement the Close method that can be found in type Epoll and Kqueue (although) it isn't implemented for the last.

I am writing a Websocket tracker using gobwas/ws and this package, and I want to implement a graceful shutdown to my server. As of now, I am calling poller.Stop on all Desc then closing connections, but it represents alot of syscalls, being able to call Close once would be easier and cleaner to stop the background loop.

Also, could you please consider implementing Close for the Kqueue implementation ?

Thanks

@gobwas

EventErr

c, err := l.Accept()
desc := netpoll.Must(netpoll.HandleRead(c))
poller.Start(desc, func(ev netpoll.Event) {
  if ev&netpoll.EventHup != 0 || ev&netpoll.EventErr != 0 {
    // close etc
  }
  go doSomething(c)
}

Why the code above doesn't "catch" connection error (eg. timeout)?
Also - when I close connection c inside doSomething(c) - the poller doesn't seem to catch that either - which leads me to a question - how to stop poller on error inside doSomething()?

Start would reset fd on HandleRead to blocking lead to set deadliner doesn't work

you set non blocking here for handle read:

easygo/netpoll/handle.go

Lines 91 to 93 in 0c8322a

if err = setNonblock(desc.fd(), true); err != nil {
return nil, os.NewSyscallError("setnonblock", err)
}

but on poller.Start(), the call to fd() would set underlying file to blocking mode again.

return p.Add(desc.fd(), events, n, func(kev Kevent) {


// Fd returns the integer Unix file descriptor referencing the open file.
// The file descriptor is valid only until f.Close is called or f is garbage collected.
// On Unix systems this will cause the SetDeadline methods to stop working.
func (f *File) Fd() uintptr {
	if f == nil {
		return ^(uintptr(0))
	}

	// If we put the file descriptor into nonblocking mode,
	// then set it to blocking mode before we return it,
	// because historically we have always returned a descriptor
	// opened in blocking mode. The File will continue to work,
	// but any blocking operation will tie up a thread.
	if f.nonblock {
		f.pfd.SetBlocking()
	}

	return uintptr(f.pfd.Sysfd)
}

This caused set deadliner doesn't work on conn owned by poller

support tls ?

if use tls.Listen(), netpoll.must Will fail,The reason for the failure is "could not get file descriptor", so support tls?

Should use CLOEXEC for epoll_create and eventfd

Epoll has EPOLL_CLOEXEC and eventfd EFD_CLOEXEC to close socket after calling to exec syscall. While it is strange to be highload network server and call os.StartProcess or exec.Command at the same time, still better to provide this flags for consistency with Go runtime.

Why not use goroutines when dispatch callbacks?

I see in the implementation of epoll.wait() and kqueue.wait() you use a iterative way to execute all the callbacks, why not use goroutines to concurrently execute them for more effitiency? I'm just a little confused about it. If you don't think this is neccessary, please tell me why, I will be very thankful.

question of closebytes

var closeBytes = []byte{1, 0, 0, 0, 0, 0, 0, 0} // what is this for?

// Close stops wait loop and closes all underlying resources.
func (ep *Epoll) Close() (err error) {
	ep.mu.Lock()
	{
		if ep.closed {
			ep.mu.Unlock()
			return ErrClosed
		}
		ep.closed = true

		if _, err = unix.Write(ep.eventFd, closeBytes); err != nil {
			ep.mu.Unlock()
			return
		}
	}
...
}

I'm currently trying to understand this repository. I don't understand the usage of the closeBytes.Is it used to close the eventFD?Is there any documetation about it?

How do you handle duplicate files?

When you use conn.File(). It returns a duplicate file instead, as mentioned here. Docs say you need to close those files yourself, how do you handle that? And does it have any impact of open fd limit of os or any other side effects?

compiler error

error : mailru\easygo\netpoll\handle.go:92: cannot use desc.fd() (type int) as type syscall.Handle in argument tosyscall.SetNonblock

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.