| ... | ... | @@ -3251,16 +3251,33 @@ pub fn sched_yield() SchedYieldError!void { |
| 3251 | 3251 | } |
| 3252 | 3252 | } |
| 3253 | 3253 | |
| 3254 | pub const SetSockOptError = error{ |
| 3255 | /// The socket is already connected, and a specified option cannot be set while the socket is connected. |
| 3256 | AlreadyConnected, |
| 3257 | |
| 3258 | /// The option is not supported by the protocol. |
| 3259 | InvalidProtocolOption, |
| 3260 | |
| 3261 | /// The send and receive timeout values are too big to fit into the timeout fields in the socket structure. |
| 3262 | TimeoutTooBig, |
| 3263 | |
| 3264 | /// Insufficient resources are available in the system to complete the call. |
| 3265 | SystemResources, |
| 3266 | } || UnexpectedError; |
| 3267 | |
| 3254 | 3268 | /// Set a socket's options. |
| 3255 | | pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) !void { |
| 3269 | pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void { |
| 3256 | 3270 | switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) { |
| 3257 | 3271 | 0 => {}, |
| 3258 | | EBADF => unreachable, |
| 3272 | EBADF => unreachable, // always a race condition |
| 3273 | ENOTSOCK => unreachable, // always a race condition |
| 3259 | 3274 | EINVAL => unreachable, |
| 3260 | 3275 | EFAULT => unreachable, |
| 3276 | EDOM => return error.TimeoutTooBig, |
| 3261 | 3277 | EISCONN => return error.AlreadyConnected, |
| 3262 | 3278 | ENOPROTOOPT => return error.InvalidProtocolOption, |
| 3263 | | ENOTSOCK => unreachable, |
| 3279 | ENOMEM => return error.SystemResources, |
| 3280 | ENOBUFS => return error.SystemResources, |
| 3264 | 3281 | else => |err| return unexpectedErrno(err), |
| 3265 | 3282 | } |
| 3266 | 3283 | } |