feat(rust/hyper): Add hyper server demo#15
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 <i@hackerchai.com> fix(rust/hyper/demo): Fix errors in server demo Signed-off-by: hackerchai <i@hackerchai.com>
Signed-off-by: hackerchai <i@hackerchai.com> fix(rust/hyper/demo): Fix hyper response task error Signed-off-by: hackerchai <i@hackerchai.com>
Signed-off-by: hackerchai <i@hackerchai.com>
Signed-off-by: hackerchai <i@hackerchai.com> # Conflicts: # go.mod # go.sum
521ca79 to
ef31104
Compare
…rite replacing poll logic Signed-off-by: hackerchai <i@hackerchai.com>
Signed-off-by: hackerchai <i@hackerchai.com>
|
|
||
| func freeConnData(userdata c.Pointer) { | ||
| conn := (*ConnData)(userdata) | ||
| if conn != nil && !conn.IsClosing.Swap(true){ |
There was a problem hiding this comment.
[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) { |
Details
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.
[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) | |
| } |
Details
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.
[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 |
Details
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.
[gofmt] Is your code not properly formatted? Here are some suggestions below
| (*libuv.Handle)(unsafe.Pointer(&conn.PollHandle)).Data = unsafe.Pointer(conn) |
Details
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.
[gofmt] Is your code not properly formatted? Here are some suggestions below
| if !updateConnDataRegistrations(conn, true) { |
Details
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.
[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() | |
| } |
Details
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.
[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() | |
| } |
Details
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.
[gofmt] Is your code not properly formatted? Here are some suggestions below
| "github.com/goplus/llgoexamples/rust/hyper" |
Details
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.
[gofmt] Is your code not properly formatted? Here are some suggestions below
| sigintHandle, sigtermHandle libuv.Signal | |
| sigintHandle, sigtermHandle libuv.Signal |
Details
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.
[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 |
Details
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.
[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]))) |
Details
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.
[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 | |
| } |
Details
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.
[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() | |
| } |
Details
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.
[gofmt] Is your code not properly formatted? Here are some suggestions below
| "sync/atomic" | |
| "unsafe" |
Details
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.