Skip to content

Commit

Permalink
Merge pull request #541 from xushiwei/x
Browse files Browse the repository at this point in the history
demo: select, netdbd
  • Loading branch information
xushiwei authored Jul 19, 2024
2 parents bd68075 + 5fa68f8 commit 118bb3f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions _demo/netdb/netdb.go → _demo/netdbdemo/netdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

func main() {
var hints net.AddrInfo
hints.AiFamily = net.AF_UNSPEC
hints.AiSockType = net.SOCK_STREAM
hints.Family = net.AF_UNSPEC
hints.SockType = net.SOCK_STREAM

host := "httpbin.org"
port := "80"
Expand Down
14 changes: 6 additions & 8 deletions _demo/select/select.go → c/sys/_demo/selectdemo/select.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package main

import (
"unsafe"

"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/os"
"github.com/goplus/llgo/c/sys"
"github.com/goplus/llgo/c/syscall"
"unsafe"
)

func main() {
var readFds syscall.FdSet

var readFds sys.FdSet
sys.FD_ZERO(&readFds)

sys.FD_SET(0, &readFds)

var tv sys.TimeVal
tv.TvSec = 5
tv.TvUSec = 0
var tv sys.Timeval
tv.Sec = 5
tv.Usec = 0

c.Printf(c.Str("Waiting for input on stdin...\n"))
ret := sys.Select(1, &readFds, nil, nil, &tv)
Expand Down
13 changes: 7 additions & 6 deletions _demo/select/select2.go → c/sys/_demo/selectdemo2/select2.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"unsafe"

"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/net"
"github.com/goplus/llgo/c/os"
"github.com/goplus/llgo/c/sys"
"github.com/goplus/llgo/c/syscall"
"unsafe"
)

const (
Expand Down Expand Up @@ -41,14 +41,15 @@ func main() {
return
}

var writefds, readfds syscall.FdSet
var timeout sys.TimeVal
var writefds, readfds sys.FdSet
var timeout sys.Timeval

// Monitor socket writes
sys.FD_ZERO(&writefds)
sys.FD_SET(sock, &writefds)
timeout.TvSec = 10
timeout.TvUSec = 0
timeout.Sec = 10
timeout.Usec = 0

// Use select to monitor the readiness of writes
if sys.Select(sock+1, nil, &writefds, nil, &timeout) > 0 {
if sys.FD_ISSET(sock, &writefds) != 0 {
Expand Down

0 comments on commit 118bb3f

Please sign in to comment.