Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(rust/hyper): Add hyper server demo #15

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hackerchai
Copy link
Contributor

@hackerchai hackerchai commented Aug 5, 2024

This PR need LLGo #700 and LLGo #706 to be merged first.

@hackerchai hackerchai marked this pull request as ready for review August 8, 2024 07:38
@hackerchai hackerchai marked this pull request as draft August 8, 2024 07:38
refactor(rust/hyper): Update server demo due to llgo changes

fix(rust/hyper): Fix some errs

Signed-off-by: hackerchai <[email protected]>

fix(rust/hyper/demo): Fix errors in server demo

Signed-off-by: hackerchai <[email protected]>
Signed-off-by: hackerchai <[email protected]>

fix(rust/hyper/demo): Fix hyper response task error

Signed-off-by: hackerchai <[email protected]>
Signed-off-by: hackerchai <[email protected]>

# Conflicts:
#	go.mod
#	go.sum
@hackerchai hackerchai marked this pull request as ready for review August 13, 2024 08:45
@hackerchai
Copy link
Contributor Author

@xushiwei @aofei @visualfc ready for review.


func freeConnData(userdata c.Pointer) {
conn := (*ConnData)(userdata)
if conn != nil && !conn.IsClosing.Swap(true){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
if conn != nil && !conn.IsClosing.Swap(true){
if conn != nil && !conn.IsClosing.Swap(true) {

If you have any questions about this comment, feel free to raise an issue here:

Comment on lines +180 to +185
(*libuv.Handle)(unsafe.Pointer(&conn.PollHandle)).Close(nil)
}

if (*libuv.Handle)(unsafe.Pointer(&conn.Stream)).IsClosing() == 0 {
(*libuv.Handle)(unsafe.Pointer(&conn.Stream)).Close(nil)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
(*libuv.Handle)(unsafe.Pointer(&conn.PollHandle)).Close(nil)
}
if (*libuv.Handle)(unsafe.Pointer(&conn.Stream)).IsClosing() == 0 {
(*libuv.Handle)(unsafe.Pointer(&conn.Stream)).Close(nil)
}
(*libuv.Handle)(unsafe.Pointer(&conn.PollHandle)).Close(nil)
}
if (*libuv.Handle)(unsafe.Pointer(&conn.Stream)).IsClosing() == 0 {
(*libuv.Handle)(unsafe.Pointer(&conn.Stream)).Close(nil)
}

If you have any questions about this comment, feel free to raise an issue here:

Comment on lines +200 to +203
if userdata == nil {
fmt.Fprintf(os.Stderr, "Failed to allocate service_userdata\n")
}
return userdata
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
if userdata == nil {
fmt.Fprintf(os.Stderr, "Failed to allocate service_userdata\n")
}
return userdata
if userdata == nil {
fmt.Fprintf(os.Stderr, "Failed to allocate service_userdata\n")
}
return userdata

If you have any questions about this comment, feel free to raise an issue here:

(*libuv.Handle)(unsafe.Pointer(&conn.Stream)).Close(nil)
return
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
(*libuv.Handle)(unsafe.Pointer(&conn.PollHandle)).Data = unsafe.Pointer(conn)

If you have any questions about this comment, feel free to raise an issue here:

}

(*libuv.Handle)(unsafe.Pointer(&conn.PollHandle)).Data = unsafe.Pointer(conn)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
if !updateConnDataRegistrations(conn, true) {

If you have any questions about this comment, feel free to raise an issue here:

Comment on lines +427 to +447
for task != nil {
taskType := task.Type()
if taskType == hyper.TaskError {
fmt.Println("hyper task failed with error!")

err := (*hyper.Error)(task.Value())
fmt.Printf("error code: %d\n", err.Code())

var errbuf [256]byte
errlen := err.Print(&errbuf[0], unsafe.Sizeof(errbuf))
fmt.Printf("details: %s\n", errbuf[:errlen])

err.Free()
task.Free()
} else if taskType == hyper.TaskEmpty {
fmt.Println("internal hyper task complete")
task.Free()
} else if taskType == hyper.TaskServerconn {
fmt.Println("server connection task complete")
task.Free()
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
for task != nil {
taskType := task.Type()
if taskType == hyper.TaskError {
fmt.Println("hyper task failed with error!")
err := (*hyper.Error)(task.Value())
fmt.Printf("error code: %d\n", err.Code())
var errbuf [256]byte
errlen := err.Print(&errbuf[0], unsafe.Sizeof(errbuf))
fmt.Printf("details: %s\n", errbuf[:errlen])
err.Free()
task.Free()
} else if taskType == hyper.TaskEmpty {
fmt.Println("internal hyper task complete")
task.Free()
} else if taskType == hyper.TaskServerconn {
fmt.Println("server connection task complete")
task.Free()
}
for task != nil {
taskType := task.Type()
if taskType == hyper.TaskError {
fmt.Println("hyper task failed with error!")
err := (*hyper.Error)(task.Value())
fmt.Printf("error code: %d\n", err.Code())
var errbuf [256]byte
errlen := err.Print(&errbuf[0], unsafe.Sizeof(errbuf))
fmt.Printf("details: %s\n", errbuf[:errlen])
err.Free()
task.Free()
} else if taskType == hyper.TaskEmpty {
fmt.Println("internal hyper task complete")
task.Free()
} else if taskType == hyper.TaskServerconn {
fmt.Println("server connection task complete")
task.Free()
}

If you have any questions about this comment, feel free to raise an issue here:

Comment on lines +450 to +455
}

if shouldExit.Load() {
fmt.Println("Shutdown initiated, cleaning up...")
handle.Stop()
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
}
if shouldExit.Load() {
fmt.Println("Shutdown initiated, cleaning up...")
handle.Stop()
}
}
if shouldExit.Load() {
fmt.Println("Shutdown initiated, cleaning up...")
handle.Stop()
}

If you have any questions about this comment, feel free to raise an issue here:

"github.com/goplus/llgo/c/net"
cos "github.com/goplus/llgo/c/os"
"github.com/goplus/llgo/c/syscall"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
"github.com/goplus/llgoexamples/rust/hyper"

If you have any questions about this comment, feel free to raise an issue here:

loop *libuv.Loop
server libuv.Tcp
checkHandle libuv.Check
sigintHandle, sigtermHandle libuv.Signal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
sigintHandle, sigtermHandle libuv.Signal
sigintHandle, sigtermHandle libuv.Signal

If you have any questions about this comment, feel free to raise an issue here:

Comment on lines +34 to +40
Stream libuv.Tcp
PollHandle libuv.Poll
EventMask c.Uint
ReadWaker *hyper.Waker
WriteWaker *hyper.Waker
IsClosing atomic.Bool
ClosedHandles int32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
Stream libuv.Tcp
PollHandle libuv.Poll
EventMask c.Uint
ReadWaker *hyper.Waker
WriteWaker *hyper.Waker
IsClosing atomic.Bool
ClosedHandles int32
Stream libuv.Tcp
PollHandle libuv.Poll
EventMask c.Uint
ReadWaker *hyper.Waker
WriteWaker *hyper.Waker
IsClosing atomic.Bool
ClosedHandles int32

If you have any questions about this comment, feel free to raise an issue here:

serviceData := (*ServiceUserdata)(userdata)

fmt.Printf("Handling request on connection from %s:%s\n",
c.GoString((*c.Char)(&serviceData.Host[0])), c.GoString((*c.Char)(&serviceData.Port[0])))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
c.GoString((*c.Char)(&serviceData.Host[0])), c.GoString((*c.Char)(&serviceData.Port[0])))
c.GoString((*c.Char)(&serviceData.Host[0])), c.GoString((*c.Char)(&serviceData.Port[0])))

If you have any questions about this comment, feel free to raise an issue here:

Comment on lines +364 to +367
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create conn_data\n")
return
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create conn_data\n")
return
}
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create conn_data\n")
return
}

If you have any questions about this comment, feel free to raise an issue here:

Comment on lines +586 to +594
if exec != nil {
exec.Free()
}
if http1Opts != nil {
http1Opts.Free()
}
if http2Opts != nil {
http2Opts.Free()
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
if exec != nil {
exec.Free()
}
if http1Opts != nil {
http1Opts.Free()
}
if http2Opts != nil {
http2Opts.Free()
}
if exec != nil {
exec.Free()
}
if http1Opts != nil {
http1Opts.Free()
}
if http2Opts != nil {
http2Opts.Free()
}

If you have any questions about this comment, feel free to raise an issue here:

"fmt"
"os"
"unsafe"
"sync/atomic"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[gofmt] Is your code not properly formatted? Here are some suggestions below

Suggested change
"sync/atomic"
"unsafe"

If you have any questions about this comment, feel free to raise an issue here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant