Skip to content

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

Open
hackerchai wants to merge 7 commits into
xgo-dev:mainfrom
hackerchai:feature/hyper-server-demo
Open

feat(rust/hyper): Add hyper server demo#15
hackerchai wants to merge 7 commits into
xgo-dev:mainfrom
hackerchai:feature/hyper-server-demo

Conversation

@hackerchai

@hackerchai hackerchai commented Aug 5, 2024

Copy link
Copy Markdown
Contributor

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
@hackerchai hackerchai force-pushed the feature/hyper-server-demo branch from 86856f1 to 521ca79 Compare August 13, 2024 08:40
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
@hackerchai hackerchai force-pushed the feature/hyper-server-demo branch from 521ca79 to ef31104 Compare August 13, 2024 08:44
@hackerchai hackerchai marked this pull request as ready for review August 13, 2024 08:45
@hackerchai

Copy link
Copy Markdown
Contributor Author

@xushiwei @aofei @visualfc ready for review.

…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){

Copy link
Copy Markdown

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) {
Details

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
Copy Markdown

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)
}
Details

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
Copy Markdown

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
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
}

Copy link
Copy Markdown

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)
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)

Copy link
Copy Markdown

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) {
Details

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
Copy Markdown

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()
}
Details

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
Copy Markdown

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()
}
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"

Copy link
Copy Markdown

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"
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

Copy link
Copy Markdown

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
Details

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
Copy Markdown

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
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])))

Copy link
Copy Markdown

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])))
Details

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
Copy Markdown

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
}
Details

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
Copy Markdown

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()
}
Details

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

"fmt"
"os"
"unsafe"
"sync/atomic"

Copy link
Copy Markdown

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"
Details

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