for ^o: other do push(arr, *o);
}
+filter :: macro (arr: ^[..] $T, body: Code) {
+ move := 0;
+
+ while i := 0; i < arr.count - move {
+ defer i += 1;
+
+ if !(#unquote body) do move += 1;
+ if move != 0 do arr.data[i] = arr.data[i + move];
+ }
+
+ arr.count -= move;
+}
fold_idx_elem :: (arr: [] $T, cmp: (T, T) -> bool) -> (i32, T) {
idx := 0;
use stream : io.Stream;
handle: Handle;
+ type: SocketType;
close :: socket_close
setting :: socket_setting
SocketSetting :: enum {
NonBlocking :: 0x01;
+ Broadcast :: 0x02;
}
// This structure is twenty bytes in size to accommodate IPV6 addresses.
socket_create :: (domain: SocketDomain, type: SocketType) -> (Socket, SocketError) {
s: Socket;
+ s.type = type;
err := __net_create_socket(^s.handle, domain, type);
if err == .None {
socket_sendto :: (s: ^Socket, data: [] u8, addr: ^Socket_Address) -> i32 {
sent := __net_sendto(s.handle, data, addr);
- if sent < 0 { s.vtable = null; }
+ // if sent < 0 s.{ s.vtable = null; }
return sent;
}
return sa, received;
}
+host_to_network :: #match {}
+#match host_to_network (x: u16) => __net_host_to_net_s(x);
+#match host_to_network (x: u32) => __net_host_to_net_l(x);
+
+network_to_host :: #match {}
+#match network_to_host (x: u16) => __net_net_to_host_s(x);
+#match network_to_host (x: u32) => __net_net_to_host_l(x);
+
#local __net_socket_vtable := io.Stream_Vtable.{
read = (use s: ^Socket, buffer: [] u8) -> (io.Error, u32) {
if handle == 0 do return .BadFile, 0;
#package __net_recv :: (handle: Socket.Handle, data: [] u8, async_would_block: ^bool) -> i32 ---
#package __net_recvfrom :: (handle: Socket.Handle, data: [] u8, out_recv_addr: ^Socket_Address, async_would_block: ^bool) -> i32 ---
#package __net_poll_recv :: (handle: [] Socket.Handle, timeout: i32, out_recv_indicies: ^i32) -> i32 ---
+
+ #package __net_host_to_net_s :: (s: u16) -> u16 ---
+ #package __net_host_to_net_l :: (s: u32) -> u32 ---
+ #package __net_net_to_host_s :: (s: u16) -> u16 ---
+ #package __net_net_to_host_l :: (s: u32) -> u32 ---
}
#operator >= macro (a, b: Socket.Handle) => cast(u32) a >= cast(u32) b;
b32 pending_type_is_valid : 1;
b32 is_union : 1;
+ b32 is_packed : 1;
};
struct AstStructMember {
AstTyped_base;
fcntl(s, F_SETFL, flags);
break;
}
+
+ case 2: { // :EnumDependent Broadcast
+ int s = params->data[0].of.i32;
+ setsockopt(s, SOL_SOCKET, SO_BROADCAST, (void *) ¶ms->data[2].of.i32, sizeof(int));
+ break;
+ }
}
#endif
return NULL;
}
-ONYX_DEF(__net_address_get_address, (WASM_I64, WASM_I32, WASM_I32), (WASM_I32)) {
- #ifdef _BH_LINUX
- int maximum_length = params->data[2].of.i32;
- int address_len = 0;
-
- struct sockaddr_in *addr = (struct sockaddr_in *) params->data[0].of.i64;
- if (addr == NULL) goto done;
-
- char *address = inet_ntoa(addr->sin_addr);
- if (address) address_len = strnlen(address, maximum_length);
-
- memcpy(ONYX_PTR(params->data[1].of.i32), address, address_len);
-
-done:
- results->data[0] = WASM_I32_VAL(address_len);
- #endif
+ONYX_DEF(__net_host_to_net_s, (WASM_I32), (WASM_I32)) {
+ results->data[0] = WASM_I32_VAL(htons(params->data[0].of.i32));
return NULL;
}
-ONYX_DEF(__net_address_get_port, (WASM_I64), (WASM_I32)) {
- #ifdef _BH_LINUX
- struct sockaddr_in *addr = (struct sockaddr_in *) params->data[0].of.i64;
- if (addr == NULL) results->data[0] = WASM_I32_VAL(-1);
- else results->data[0] = WASM_I32_VAL(addr->sin_port);
- #endif
+ONYX_DEF(__net_host_to_net_l, (WASM_I32), (WASM_I32)) {
+ results->data[0] = WASM_I32_VAL(htonl(params->data[0].of.i32));
return NULL;
}
+ONYX_DEF(__net_net_to_host_s, (WASM_I32), (WASM_I32)) {
+ results->data[0] = WASM_I32_VAL(ntohs(params->data[0].of.i32));
+ return NULL;
+}
+ONYX_DEF(__net_net_to_host_l, (WASM_I32), (WASM_I32)) {
+ results->data[0] = WASM_I32_VAL(ntohl(params->data[0].of.i32));
+ return NULL;
+}
//
ONYX_FUNC(__net_recv)
ONYX_FUNC(__net_recvfrom)
ONYX_FUNC(__net_poll_recv)
+ ONYX_FUNC(__net_host_to_net_s)
+ ONYX_FUNC(__net_host_to_net_l)
+ ONYX_FUNC(__net_net_to_host_s)
+ ONYX_FUNC(__net_net_to_host_l)
ONYX_FUNC(__cptr_make)
ONYX_FUNC(__cptr_read)
if (parse_possible_directive(parser, "union")) s_node->is_union = 1;
+ else if (parse_possible_directive(parser, "pack")) s_node->is_packed = 1;
+
else if (parse_possible_directive(parser, "align")) {
AstNumLit* numlit = parse_int_literal(parser);
if (numlit == NULL) return NULL;
}
if (mem_alignment > alignment) alignment = mem_alignment;
- bh_align(offset, mem_alignment);
+
+ if (!s_node->is_packed) {
+ bh_align(offset, mem_alignment);
+ }
token_toggle_end((*member)->token);
if (shgeti(s_type->Struct.members, (*member)->token->text) != -1) {
}
alignment = bh_max(s_node->min_alignment, alignment);
- bh_align(size, alignment);
+ if (!s_node->is_packed) {
+ bh_align(size, alignment);
+ }
+
size = bh_max(s_node->min_size, size);
s_type->Struct.alignment = alignment;
Hello, I am Billy!
-Go away!! func[17]
+Go away!! func[16]