vlib: replace macros that resolve to __builtin_bswapnn calls for tcc (#19305)

The tcc compiler does not have __builtin_bswap64, __builtin_bswap32,
and __builtin_bswap16 functions.  The various hton and ntoh macros
resolve down to these functions.  When compiling with tcc, we should
be using the analogous functions from net.conv.
This commit is contained in:
Kim Shrier 2023-09-07 22:42:28 -06:00 committed by GitHub
parent bea12e2623
commit 2d4ccf6829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 10 deletions

View file

@ -1,6 +1,7 @@
module picoev
import net
import net.conv
import picohttpparser
#include <errno.h>
@ -123,10 +124,23 @@ fn listen(config Config) int {
}
// addr settings
sin_port := $if tinyc {
conv.hton16(u16(config.port))
} $else {
C.htons(config.port)
}
sin_addr := $if tinyc {
conv.hton32(u32(C.INADDR_ANY))
} $else {
C.htonl(C.INADDR_ANY)
}
mut addr := C.sockaddr_in{
sin_family: u8(C.AF_INET)
sin_port: C.htons(config.port)
sin_addr: C.htonl(C.INADDR_ANY)
sin_port: sin_port
sin_addr: sin_addr
}
size := sizeof(C.sockaddr_in)
bind_res := C.bind(fd, voidptr(unsafe { &net.Addr(&addr) }), size)