Improved server example
This commit is contained in:
parent
b2030c506c
commit
971b7f4b76
5 changed files with 37 additions and 10 deletions
10
lib/net/net_linux.q
Normal file
10
lib/net/net_linux.q
Normal file
|
@ -0,0 +1,10 @@
|
|||
import sys
|
||||
|
||||
bind(socket Int, port Int) -> Int {
|
||||
addr := new(sys.sockaddr_in)
|
||||
addr.sin_family = 2
|
||||
addr.sin_port = port
|
||||
err := sys.bind(socket, addr, 20)
|
||||
delete(addr)
|
||||
return err
|
||||
}
|
10
lib/net/net_mac.q
Normal file
10
lib/net/net_mac.q
Normal file
|
@ -0,0 +1,10 @@
|
|||
import sys
|
||||
|
||||
bind(socket Int, port Int) -> Int {
|
||||
addr := new(sys.sockaddr_in_bsd)
|
||||
addr.sin_family = 2
|
||||
addr.sin_port = port
|
||||
err := sys.bind(socket, addr, 20)
|
||||
delete(addr)
|
||||
return err
|
||||
}
|
|
@ -1,3 +1,11 @@
|
|||
struct sockaddr_in_bsd {
|
||||
sin_len Int8
|
||||
sin_family Int8
|
||||
sin_port Int16
|
||||
sin_addr Int64
|
||||
sin_zero Int64
|
||||
}
|
||||
|
||||
socket(family Int, type Int, protocol Int) -> Int {
|
||||
return syscall(0x2000061, family, type, protocol)
|
||||
}
|
||||
|
@ -6,7 +14,7 @@ accept(fd Int, address Pointer, length Int) -> Int {
|
|||
return syscall(0x200001E, fd, address, length)
|
||||
}
|
||||
|
||||
bind(fd Int, address Pointer, length Int) -> Int {
|
||||
bind(fd Int, address *sockaddr_in_bsd, length Int) -> Int {
|
||||
return syscall(0x2000068, fd, address, length)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue