mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Clean up some FreeBSD core:net code
This commit is contained in:
@@ -27,8 +27,9 @@ Dial_Error :: enum c.int {
|
|||||||
Already_Connected = cast(c.int)freebsd.Errno.EISCONN,
|
Already_Connected = cast(c.int)freebsd.Errno.EISCONN,
|
||||||
Timeout = cast(c.int)freebsd.Errno.ETIMEDOUT,
|
Timeout = cast(c.int)freebsd.Errno.ETIMEDOUT,
|
||||||
Refused_By_Remote_Host = cast(c.int)freebsd.Errno.ECONNREFUSED,
|
Refused_By_Remote_Host = cast(c.int)freebsd.Errno.ECONNREFUSED,
|
||||||
// `Refused` alias for core:net tests.
|
// `Refused` alias for `core:net` tests.
|
||||||
Refused = cast(c.int)freebsd.Errno.ECONNREFUSED,
|
// The above default name `Refused_By_Remote_Host` is more explicit.
|
||||||
|
Refused = Refused_By_Remote_Host,
|
||||||
Reset_By_Remote_Host = cast(c.int)freebsd.Errno.ECONNRESET,
|
Reset_By_Remote_Host = cast(c.int)freebsd.Errno.ECONNRESET,
|
||||||
Network_Unreachable = cast(c.int)freebsd.Errno.ENETUNREACH,
|
Network_Unreachable = cast(c.int)freebsd.Errno.ENETUNREACH,
|
||||||
Host_Unreachable = cast(c.int)freebsd.Errno.EHOSTUNREACH,
|
Host_Unreachable = cast(c.int)freebsd.Errno.EHOSTUNREACH,
|
||||||
@@ -138,13 +139,15 @@ TCP_Send_Error :: enum c.int {
|
|||||||
specified, and the requested operation would block. */
|
specified, and the requested operation would block. */
|
||||||
Would_Block = cast(c.int)freebsd.Errno.EAGAIN,
|
Would_Block = cast(c.int)freebsd.Errno.EAGAIN,
|
||||||
|
|
||||||
// NOTE: This error arises for two distinct reasons.
|
/* NOTE: This error arises for two distinct reasons:
|
||||||
/* The system was unable to allocate an internal buffer.
|
|
||||||
The operation may succeed when buffers become available. */
|
|
||||||
|
|
||||||
/* The output queue for a network interface was full.
|
1. The system was unable to allocate an internal buffer.
|
||||||
This generally indicates that the interface has stopped
|
The operation may succeed when buffers become available.
|
||||||
sending, but may be caused by transient congestion. */
|
|
||||||
|
2. The output queue for a network interface was full.
|
||||||
|
This generally indicates that the interface has stopped
|
||||||
|
sending, but may be caused by transient congestion.
|
||||||
|
*/
|
||||||
No_Buffer_Space_Available = cast(c.int)freebsd.Errno.ENOBUFS,
|
No_Buffer_Space_Available = cast(c.int)freebsd.Errno.ENOBUFS,
|
||||||
|
|
||||||
Host_Unreachable = cast(c.int)freebsd.Errno.EHOSTUNREACH,
|
Host_Unreachable = cast(c.int)freebsd.Errno.EHOSTUNREACH,
|
||||||
@@ -174,16 +177,16 @@ Shutdown_Error :: enum c.int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Socket_Option_Error :: enum c.int {
|
Socket_Option_Error :: enum c.int {
|
||||||
None = 0,
|
None = 0,
|
||||||
Value_Out_Of_Range = -1,
|
Value_Out_Of_Range = -1,
|
||||||
Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
|
Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
|
||||||
Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
|
Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
|
||||||
Unknown_Option_For_Level = cast(c.int)freebsd.Errno.ENOPROTOOPT,
|
Unknown_Option_For_Level = cast(c.int)freebsd.Errno.ENOPROTOOPT,
|
||||||
Argument_In_Invalid_Address_Space = cast(c.int)freebsd.Errno.EFAULT,
|
Argument_In_Invalid_Address_Space = cast(c.int)freebsd.Errno.EFAULT,
|
||||||
// This error can arise for many different reasons.
|
// This error can arise for many different reasons.
|
||||||
Invalid_Value = cast(c.int)freebsd.Errno.EINVAL,
|
Invalid_Value = cast(c.int)freebsd.Errno.EINVAL,
|
||||||
System_Memory_Allocation_Failed = cast(c.int)freebsd.Errno.ENOMEM,
|
System_Memory_Allocation_Failed = cast(c.int)freebsd.Errno.ENOMEM,
|
||||||
Insufficient_System_Resources = cast(c.int)freebsd.Errno.ENOBUFS,
|
Insufficient_System_Resources = cast(c.int)freebsd.Errno.ENOBUFS,
|
||||||
}
|
}
|
||||||
|
|
||||||
Set_Blocking_Error :: enum c.int {
|
Set_Blocking_Error :: enum c.int {
|
||||||
|
|||||||
@@ -245,17 +245,17 @@ _set_option :: proc(socket: Any_Socket, option: Socket_Option, value: any, loc :
|
|||||||
.Reuse_Port,
|
.Reuse_Port,
|
||||||
.No_SIGPIPE_From_EPIPE,
|
.No_SIGPIPE_From_EPIPE,
|
||||||
.Reuse_Port_Load_Balancing:
|
.Reuse_Port_Load_Balancing:
|
||||||
switch real in value {
|
switch real in value {
|
||||||
case bool: bool_value = cast(b32)real
|
case bool: bool_value = cast(b32)real
|
||||||
case b8: bool_value = cast(b32)real
|
case b8: bool_value = cast(b32)real
|
||||||
case b16: bool_value = cast(b32)real
|
case b16: bool_value = cast(b32)real
|
||||||
case b32: bool_value = real
|
case b32: bool_value = real
|
||||||
case b64: bool_value = cast(b32)real
|
case b64: bool_value = cast(b32)real
|
||||||
case:
|
case:
|
||||||
panic("set_option() value must be a boolean here", loc)
|
panic("set_option() value must be a boolean here", loc)
|
||||||
}
|
}
|
||||||
ptr = &bool_value
|
ptr = &bool_value
|
||||||
len = size_of(bool_value)
|
len = size_of(bool_value)
|
||||||
case
|
case
|
||||||
.Linger,
|
.Linger,
|
||||||
.Send_Timeout,
|
.Send_Timeout,
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ close :: proc "contextless" (fd: Fd) -> Errno {
|
|||||||
//
|
//
|
||||||
// The getpid() function appeared in Version 7 AT&T UNIX.
|
// The getpid() function appeared in Version 7 AT&T UNIX.
|
||||||
getpid :: proc "contextless" () -> pid_t {
|
getpid :: proc "contextless" () -> pid_t {
|
||||||
// always succeeds
|
// This always succeeds.
|
||||||
result, _ := intrinsics.syscall_bsd(SYS_getpid)
|
result, _ := intrinsics.syscall_bsd(SYS_getpid)
|
||||||
return cast(pid_t)result
|
return cast(pid_t)result
|
||||||
}
|
}
|
||||||
@@ -468,7 +468,7 @@ accept4_T :: proc "contextless" (s: Fd, sockaddr: ^$T, flags: Socket_Flags = {})
|
|||||||
where
|
where
|
||||||
intrinsics.type_is_subtype_of(T, Socket_Address_Header)
|
intrinsics.type_is_subtype_of(T, Socket_Address_Header)
|
||||||
{
|
{
|
||||||
// sockaddr must contain a valid pointer, or this will segfault because
|
// `sockaddr` must contain a valid pointer, or this will segfault because
|
||||||
// we're telling the syscall that there's memory available to write to.
|
// we're telling the syscall that there's memory available to write to.
|
||||||
addrlen: u32 = size_of(T)
|
addrlen: u32 = size_of(T)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user