refactor(c-libuv): Added TODO(uid) comment & adjusted the position of Handle, Stream, Req, Write, Connect

This commit is contained in:
赵英杰
2024-08-02 17:54:19 +08:00
committed by spongehah
parent 0bd259403c
commit b3e1b6fdbf
4 changed files with 232 additions and 223 deletions

View File

@@ -11,8 +11,6 @@ import (
var DEFAULT_PORT c.Int = 8080
var DEFAULT_BACKLOG c.Int = 128
var loop *libuv.Loop
type WriteReq struct {
Req libuv.Write
Buf libuv.Buf
@@ -20,7 +18,7 @@ type WriteReq struct {
func main() {
// Initialize the default event loop
loop = libuv.DefaultLoop()
var loop = libuv.DefaultLoop()
// Initialize a TCP server
var server libuv.Tcp
@@ -105,7 +103,7 @@ func OnNewConnection(server *libuv.Stream, status c.Int) {
}
// Initialize the client TCP handle.
if libuv.InitTcp(loop, client) < 0 {
if libuv.InitTcp(libuv.DefaultLoop(), client) < 0 {
c.Fprintf(c.Stderr, c.Str("Failed to initialize client\n"))
c.Free(c.Pointer(client))
return