-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Conversation
86856f1
to
521ca79
Compare
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]>
Signed-off-by: hackerchai <[email protected]> # Conflicts: # go.mod # go.sum
521ca79
to
ef31104
Compare
…rite replacing poll logic Signed-off-by: hackerchai <[email protected]>
Signed-off-by: hackerchai <[email protected]>
|
||
func freeConnData(userdata c.Pointer) { | ||
conn := (*ConnData)(userdata) | ||
if conn != nil && !conn.IsClosing.Swap(true){ |
There was a problem hiding this comment.
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
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:
(*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) | ||
} |
There was a problem hiding this comment.
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
(*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:
if userdata == nil { | ||
fmt.Fprintf(os.Stderr, "Failed to allocate service_userdata\n") | ||
} | ||
return userdata |
There was a problem hiding this comment.
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
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 | ||
} | ||
|
There was a problem hiding this comment.
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
(*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) | ||
|
There was a problem hiding this comment.
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
if !updateConnDataRegistrations(conn, true) { |
If you have any questions about this comment, feel free to raise an issue here:
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() | ||
} |
There was a problem hiding this comment.
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
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:
} | ||
|
||
if shouldExit.Load() { | ||
fmt.Println("Shutdown initiated, cleaning up...") | ||
handle.Stop() | ||
} |
There was a problem hiding this comment.
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
} | |
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" | ||
|
There was a problem hiding this comment.
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
"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 |
There was a problem hiding this comment.
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
sigintHandle, sigtermHandle libuv.Signal | |
sigintHandle, sigtermHandle libuv.Signal |
If you have any questions about this comment, feel free to raise an issue here:
Stream libuv.Tcp | ||
PollHandle libuv.Poll | ||
EventMask c.Uint | ||
ReadWaker *hyper.Waker | ||
WriteWaker *hyper.Waker | ||
IsClosing atomic.Bool | ||
ClosedHandles int32 |
There was a problem hiding this comment.
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
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]))) |
There was a problem hiding this comment.
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
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:
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Failed to create conn_data\n") | ||
return | ||
} |
There was a problem hiding this comment.
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
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:
if exec != nil { | ||
exec.Free() | ||
} | ||
if http1Opts != nil { | ||
http1Opts.Free() | ||
} | ||
if http2Opts != nil { | ||
http2Opts.Free() | ||
} |
There was a problem hiding this comment.
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
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" |
There was a problem hiding this comment.
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
"sync/atomic" | |
"unsafe" |
If you have any questions about this comment, feel free to raise an issue here:
This PR need LLGo #700 and LLGo #706 to be merged first.