mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
New faults and syntax (#2034)
- Remove `[?]` syntax. - Change `int!` to `int?` syntax. - New `fault` declarations. - Enum associated values can reference the calling enum.
This commit is contained in:
committed by
GitHub
parent
fefce25081
commit
25bccf4883
@@ -34,20 +34,20 @@ fn anyfault convert_error(Errno error)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case errno::EACCES: return IoError.NO_PERMISSION;
|
||||
case errno::EADDRINUSE: return NetError.ADDRESS_IN_USE;
|
||||
case errno::EALREADY: return NetError.CONNECTION_ALREADY_IN_PROGRESS;
|
||||
case errno::EBADF: return NetError.BAD_SOCKET_DESCRIPTOR;
|
||||
case errno::ECONNREFUSED: return NetError.CONNECTION_REFUSED;
|
||||
case errno::ECONNRESET: return NetError.CONNECTION_RESET;
|
||||
case errno::EISCONN: return NetError.ALREADY_CONNECTED;
|
||||
case errno::ENETUNREACH: return NetError.NETWORK_UNREACHABLE;
|
||||
case errno::ENOTSOCK: return NetError.NOT_A_SOCKET;
|
||||
case errno::EINTR: return IoError.INTERRUPTED;
|
||||
case errno::EWOULDBLOCK: return IoError.WOULD_BLOCK;
|
||||
case errno::EOPNOTSUPP: return NetError.OPERATION_NOT_SUPPORTED_ON_SOCKET;
|
||||
case errno::ETIMEDOUT: return NetError.CONNECTION_TIMED_OUT;
|
||||
default: return IoError.GENERAL_ERROR;
|
||||
case errno::EACCES: return io::NO_PERMISSION;
|
||||
case errno::EADDRINUSE: return net::ADDRESS_IN_USE;
|
||||
case errno::EALREADY: return net::CONNECTION_ALREADY_IN_PROGRESS;
|
||||
case errno::EBADF: return net::BAD_SOCKET_DESCRIPTOR;
|
||||
case errno::ECONNREFUSED: return net::CONNECTION_REFUSED;
|
||||
case errno::ECONNRESET: return net::CONNECTION_RESET;
|
||||
case errno::EISCONN: return net::ALREADY_CONNECTED;
|
||||
case errno::ENETUNREACH: return net::NETWORK_UNREACHABLE;
|
||||
case errno::ENOTSOCK: return net::NOT_A_SOCKET;
|
||||
case errno::EINTR: return io::INTERRUPTED;
|
||||
case errno::EWOULDBLOCK: return io::WOULD_BLOCK;
|
||||
case errno::EOPNOTSUPP: return net::OPERATION_NOT_SUPPORTED_ON_SOCKET;
|
||||
case errno::ETIMEDOUT: return net::CONNECTION_TIMED_OUT;
|
||||
default: return io::GENERAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,16 +61,16 @@ macro bool NativeSocket.is_valid(self)
|
||||
return (iptr)self >= 0;
|
||||
}
|
||||
|
||||
macro void! NativeSocket.close(self)
|
||||
macro void? NativeSocket.close(self)
|
||||
{
|
||||
if (libc::close(self))
|
||||
{
|
||||
if (libc::errno() == errno::EBADF) return NetError.INVALID_SOCKET?;
|
||||
return NetError.GENERAL_ERROR?;
|
||||
if (libc::errno() == errno::EBADF) return net::INVALID_SOCKET?;
|
||||
return net::GENERAL_ERROR?;
|
||||
}
|
||||
}
|
||||
|
||||
macro void! NativeSocket.set_non_blocking(self, bool non_blocking)
|
||||
macro void? NativeSocket.set_non_blocking(self, bool non_blocking)
|
||||
{
|
||||
int flags = fcntl(self, F_GETFL, 0);
|
||||
if (non_blocking)
|
||||
@@ -85,8 +85,8 @@ macro void! NativeSocket.set_non_blocking(self, bool non_blocking)
|
||||
}
|
||||
if (fcntl(self, F_SETFL, flags) == -1)
|
||||
{
|
||||
if (libc::errno() == errno::EBADF) return NetError.INVALID_SOCKET?;
|
||||
return NetError.GENERAL_ERROR?;
|
||||
if (libc::errno() == errno::EBADF) return net::INVALID_SOCKET?;
|
||||
return net::GENERAL_ERROR?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ macro bool NativeSocket.is_valid(self)
|
||||
return self != (NativeSocket)(uptr)-1;
|
||||
}
|
||||
|
||||
fn void! NativeSocket.set_non_blocking(self, bool non_blocking)
|
||||
fn void? NativeSocket.set_non_blocking(self, bool non_blocking)
|
||||
{
|
||||
if (ioctlsocket(self, win32::FIONBIO, &&(CULong)non_blocking))
|
||||
{
|
||||
@@ -35,7 +35,7 @@ fn void! NativeSocket.set_non_blocking(self, bool non_blocking)
|
||||
}
|
||||
}
|
||||
|
||||
macro void! NativeSocket.close(self)
|
||||
macro void? NativeSocket.close(self)
|
||||
{
|
||||
WSAError error = closesocket(self);
|
||||
if (error) return convert_error(error)?;
|
||||
@@ -65,24 +65,24 @@ fn anyfault convert_error(WSAError error)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case wsa::NOTINITIALISED: return NetError.SOCKETS_NOT_INITIALIZED;
|
||||
case wsa::ENETDOWN: return NetError.NETWORK_UNREACHABLE;
|
||||
case wsa::INVALID_HANDLE: return NetError.BAD_SOCKET_DESCRIPTOR;
|
||||
case wsa::EACCESS: return IoError.NO_PERMISSION;
|
||||
case wsa::EINPROGRESS: return NetError.STILL_PROCESSING_CALLBACK;
|
||||
case wsa::EADDRINUSE: return NetError.ADDRESS_IN_USE;
|
||||
case wsa::EALREADY: return NetError.CONNECTION_ALREADY_IN_PROGRESS;
|
||||
case wsa::EBADF: return NetError.BAD_SOCKET_DESCRIPTOR;
|
||||
case wsa::EINTR: return IoError.INTERRUPTED;
|
||||
case wsa::EWOULDBLOCK: return IoError.WOULD_BLOCK;
|
||||
case wsa::ECONNREFUSED: return NetError.CONNECTION_REFUSED;
|
||||
case wsa::EISCONN: return NetError.ALREADY_CONNECTED;
|
||||
case wsa::ENETUNREACH: return NetError.NETWORK_UNREACHABLE;
|
||||
case wsa::ENOTSOCK: return NetError.NOT_A_SOCKET;
|
||||
case wsa::EOPNOTSUPP: return NetError.OPERATION_NOT_SUPPORTED_ON_SOCKET;
|
||||
case wsa::ETIMEDOUT: return NetError.CONNECTION_TIMED_OUT;
|
||||
case wsa::ECONNRESET: return NetError.CONNECTION_RESET;
|
||||
default: return IoError.GENERAL_ERROR;
|
||||
case wsa::NOTINITIALISED: return net::SOCKETS_NOT_INITIALIZED;
|
||||
case wsa::ENETDOWN: return net::NETWORK_UNREACHABLE;
|
||||
case wsa::INVALID_HANDLE: return net::BAD_SOCKET_DESCRIPTOR;
|
||||
case wsa::EACCESS: return io::NO_PERMISSION;
|
||||
case wsa::EINPROGRESS: return net::STILL_PROCESSING_CALLBACK;
|
||||
case wsa::EADDRINUSE: return net::ADDRESS_IN_USE;
|
||||
case wsa::EALREADY: return net::CONNECTION_ALREADY_IN_PROGRESS;
|
||||
case wsa::EBADF: return net::BAD_SOCKET_DESCRIPTOR;
|
||||
case wsa::EINTR: return io::INTERRUPTED;
|
||||
case wsa::EWOULDBLOCK: return io::WOULD_BLOCK;
|
||||
case wsa::ECONNREFUSED: return net::CONNECTION_REFUSED;
|
||||
case wsa::EISCONN: return net::ALREADY_CONNECTED;
|
||||
case wsa::ENETUNREACH: return net::NETWORK_UNREACHABLE;
|
||||
case wsa::ENOTSOCK: return net::NOT_A_SOCKET;
|
||||
case wsa::EOPNOTSUPP: return net::OPERATION_NOT_SUPPORTED_ON_SOCKET;
|
||||
case wsa::ETIMEDOUT: return net::CONNECTION_TIMED_OUT;
|
||||
case wsa::ECONNRESET: return net::CONNECTION_RESET;
|
||||
default: return io::GENERAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user